Linux : ls command

ls Command:


ls is the most basic command of Linux. It list information about the FILEs (the current directory by default). 


Linux ls command


ls command examples:

1- Listing files:
$ ls

2- List directory with relative path
$ ls /home/user


3- List root directory:
$ ls /

4- List parent directory:
$ ls ..

5- List user's home directory (e.g: /home/user):
$ ls ~

6- List with long format:
$ ls -l

7- Show hidden files:
$ ls -a

8- List with long format and show hidden files:
$ ls -al

9- Sort by date/time:
$ ls -lt

10- Sort by file size:
$ ls -lS

11- Recursive directory tree list:
$ ls -R

12- Display file size in human readable format:
$ ls -lh

13- Display directory information
$ ls -ld /etc

14- Display hidden files without . and ..
$ ls -A

15- Display inode no
# ls -I /user/home/Documents


Meaning of different fields that show ls -l command



$ ls -l
total 16
drwxr-xr-x 2 user user  80 2011-08-17 16:52 Desktop
drwxr-xr-x 2 user user  40 2011-08-17 16:52 Documents
drwxr-xr-x 2 user user  40 2011-08-17 16:52 Downloads
drwxr-xr-x 2 user user  40 2011-08-17 16:52 Music
drwxr-xr-x 2 user user 120 2011-08-17 18:14 Pictures
drwxr-xr-x 2 user user  40 2011-08-17 16:52 Public



First line total 16 shows total size of the directory, means it is occupying 16 blocks of memory. for human readable format (KB, MB) use -h option.


After That first column is  drwxr-xr-x


1st Character is File Type: First character specifies the type of the file.

diff file type notations are

    - : for normal file

     d : for directory

    s : for socket file

      l  : for  link file



  • Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for user, group and world (others), for example, -rw-r—– indicates read-write permission for user, read permission for group, and no permission for others.
  • Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 2 indicates only one link to this file.
  • Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by username ‘user’.
  • Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs to ”user" group.
  • Field 5 – Size: Fifth field specifies the size of file. In this example, ’80′ indicates the file size in blocks. -h option gives size in human readable format (KB, MB)
  • Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file.
  • Field 7 – File name: The last field is the name of the file or Directory.

 
   Linux Commands                                                                         absolute vs relative Path

No comments: