Showing posts with label ls. Show all posts
Showing posts with label ls. Show all posts

Monday, June 20, 2011

Listing Files

The ls (list) command, used by itself, lists the content of the working directory.

[ray@domain ~]$ ls
Desktop helloworld.txt


You can also retrieve a list of the files in another directory by adding the directory name, ex


[ray@domain ~]$ ls /home/ray
movies pictures documents music public desktop


Using ls by itself will show you the names of tiles in the directory, if you want  all  details you can add the -l flag to the command, ex.


[ray@domain ~]$ ls -l
total 16 files
drwxr-xr-x 2 ray staff 4096 5 Sep 15:21 Desktop
-rw-rw-r-- 1 ray staff 13 8 Sep 07:30 Hello World.txt


The data found above:

  • The first column represents the file permissions in the format discussed in section 1.2 File Persmissions. The first character tells us if the file is a directory or other (d equals a directory). The next nine characters show the permissions to (in order) Owner, Group, and Others.
  • The next column only useful for directories, as it tells you the number of files within it.
  • The next two columns identifies the owner and group
  • Next column is the size of the files in bytes
  • Next is the date and time of last modified, Hello World.txt above is modified September 8 at 07:30
  • Finally, the name of file
Hidden files in Linux start with a period. If you want to hide the Hello World.txt file you would change the name to .Hello World.txt (mind the dot in front of the filename!). Programs store user-specific configuration files by hidden using the period in front of the file. To see hidden files you use the flag -a, which can be used in conjunction with -l flag, ex.

[ray@domain ~]$ ls -la
total 16 files
drwx------ 13 ray  staff 714 19 Jun 20:24  .
drwxr-xr-x  5 root admin 306 17 June 14:44 ..
-re-------  1 ray  staff  14 08 June 15:55 .trash
drwxr-xr-x 2 ray staff 4096 5 Sep 15:21 Desktop
-rw-rw-r-- 1 ray staff 13 8 Sep 07:30 Hello World.txt

At the top of the listing are two directories, "." and "..", These are shortcuts to the current directory and the parent directory, respectively we will have a look at theses later on.