ls command list all the file and directory name present in the current directory.
Syntax:
1 | $ ls [press enter] |
Example:
Print the name of all the directory and file available in the current directory.
1 2 3 4 5 | $ ls [press enter] README Chap01 Chap02 text |
Above command display four file and directory name.
Check availability of file or directory: We can check whether a particular file or directory is present in the current directory or not. To know we just specify a file name with ls command.
1 2 | $ ls EmployeeRecord [press enter] EmployeeRecord |
If Employee Record file is not available, the system will clearly say:
1 2 | $ ls EmployeeRecord [press enter] EmployeeRecord: No such file or directory. |
Details of file and directory (-l option): We can check the details of the file with (-l) option
1 2 3 4 5 | $ ls -l [press enter] -rwxr-x-r-- 1 hope aditya 16 Jun 1 23:11 1.txt -rw-rw-r-- 2 hope aditya 13 Jul 1 23:11 2.txt drwxrwxr-x 1 hope aditya 4096 Jul 6 19:25 hello drwxrwxr-x 2 hope aditya 4096 Jul 6 19:25 sample |
First character “-“ or “d”: The first character represents the type of file. The symbol “-“represents a regular file and “d” denotes a directory.
Next Nine Character: Next 9 character (for example rwxr-xr– )represent the file or directory permission permissions.
The first group of 3 characters(for example rwxr-xr–) represent permissions for owner means the owner has a permission to read, write and execute.
The second group of 3 characters(for example rwxr-xr–) represent permissions for members of the file group means the group has a permission only to read and execute.
The third group of 3 characters (for example rwxr-xr–) represent permissions for others means others have a permission only to read a file.
Second column: Represent the of the number of links to that file.
Third column: Represent the owner of the file.
Fourth Column: Represent the group of the file.
Fifth Column: Represent the size of the file. Here file size for the file 2.txt is 13 bytes.
Sixth Column: Represent the last modified date and time of the file or directory.
Seventh column: Tells the name of the file or directory in current directory.
Options of ls command
[table id=7 /]