- Use the "-l" option to view the file type, permissions, number of files and subdirectories, owner, group, size and the date the files were last modified. This is called the long listing. The syntax is "ls -l". The following is an example of the output:
drwxr-xr-x 2 owner group 4096 2011-08-12 22:50 dir_name
The first letter of the first column indicates whether it is a directory or file. The "d" stands for directory. If it was a regular file, the "d" would be replaced with the "-" character. The rest of the letters in the first column represent the file permissions. The "2" in the second column indicates the number of files or subdirectories contained in the directory. The third column contains the name of the owner. The fourth column contains the name of the primary group for the directory. The fifth column shows the size of the file in bytes. The sixth column shows the date and time the file was last modified. The last column is the name of the file or directory. - The Linux operating system hides files and directories by placing a "." in front of the file name. The "-a" option shows the hidden files. The hidden files are listed in alphabetically order by the first name of the file, omitting the leading "." character. You can combine the "-a" option with the "-l" option to view the long listing of all of the files and subdirectories.
- The long listing shows the size of the file or directory in bytes. The "-h" option shows the size in human readable form. The size is followed by a "K" for kilobytes, "M" for megabytes or "G" for gigabytes. The "-h" option must be combined with the "-l" option. If it is used with the "ls" command alone, no size is shown.
- The "ls" command only shows the names of any subdirectories contained within the directory, but it does not print the contents of the subdirectory by default. The "-R" option recursively shows the contents of the subdirectories. The option can be used alone or with the other options. The output can be quite extensive. Type the command "ls -R | less" to pipe the output through the "less" command. The output will stop regularly. Pressing the spacebar will advance the output.
- You can change the way the command sorts the output. The "-S" option sorts the output by file size, with the largest files at the top of the list. The "-t" option sorts the output by the modification date, with the most recently modified files at the top of the list.
The "-r" option sorts the output in reverse order. Used alone, it sorts the output in reverse alphabetical order. Used with the "-S" option, it sorts the output with the smallest files at the top of the list. Used with the "-t" option, the output is sorted with the most recently modified files at the end of the list.
next post