|
||||||
Linux Secrets: How to Customize the ls OutputUse ls Options Change the Information that it Displays
The Linux command ls is used to list directory contents, but what it displays can be customized just by using a couple of options.
One of the most underrated Linux commands is ls; it is, of course, used for listing the contents of a directory. However ls has a number of options and each of these options can change the output that ls produces - making it a very versatile tool. The Standard ls UsageThe most usual usage of ls is just to list the files in a directory: $ ls
process_article writing_status writing_status~
This output can be changed from horizontal to vertical by using the -1 (that's the number one, not lowercase L) option: $ ls -1
process_article
writing_status
writing_status~
Using ls to Show Hidden FilesAny file with the prefix (a full-stop or period) is normally hidden from the display; the -a option is used to reveal the hidden files: $ ls -1a
.netrc
process_article
writing_status
writing_status~
The Long Listing Format of lsMore than just a simple list of files can be displayed; the long listing format shows:
The long listing format is initiated by using the -l (that's lowercase L, not the number one) option: $ ls -l
-rwxrw-rw- 1 bainm bainm 312 2008-10-10 21:20 process_article
-rwxrwxrwx 1 bainm users 4690 2008-07-14 14:58 writing_status
-rwxrwxrwx 1 bainm users 4318 2008-07-13 23:01 writing_status~
And the long listing format can be used with the -a option to show the details of all of the hidden files as well: $ ls -la
total 32
drwxr-xr-x 2 bainm users 4096 2008-12-04 13:53 .
drwxr-xr-x 33 bainm bainm 4096 2008-11-30 14:57 ..
-rw------- 1 bainm bainm 248 2008-12-04 13:53 .netrc
-rwxrw-rw- 1 bainm bainm 312 2008-10-10 21:20 process_article
-rwxrwxrwx 1 bainm users 4690 2008-07-14 14:58 writing_status
-rwxrwxrwx 1 bainm users 4318 2008-07-13 23:01 writing_status~
Another useful form of the long format is the file classification (-F) - this appends a symbol onto the file name according to the file:
For example: $ ls -laF
total 32
drwxr-xr-x 2 bainm users 4096 2008-12-04 13:53 ./
drwxr-xr-x 33 bainm bainm 4096 2008-11-30 14:57 ../
-rw------- 1 bainm bainm 248 2008-12-04 13:53 .netrc
-rwxrw-rw- 1 bainm bainm 312 2008-10-10 21:20 process_article*
-rwxrwxrwx 1 bainm users 4690 2008-07-14 14:58 writing_status*
-rwxrwxrwx 1 bainm users 4318 2008-07-13 23:01 writing_status~*
Learning more about lsAll of the other options can be read about by using the Linux man command: $ man ls
SummaryAt it's simplest level ls is very useful for listing the contents of a directory, but has a number of options, for example:
The options can be used on their own or in conjunction completely change the way that the ls output looks.
The copyright of the article Linux Secrets: How to Customize the ls Output in Linux Programming is owned by Mark Alexander Bain. Permission to republish Linux Secrets: How to Customize the ls Output in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||