ls command is a basic, useful, and obvious utility that Linux users have been putting to work for decades. Originally debuted in an AT&T build of UNIX, the
ls command we know today is a part of the GNU Coreutils packages of our favorite distributions; unless you are using macOS (then its BSD). The utility on offer here is rather simple. The
ls command allows us to list files in a directory. It doesn't do anything special or crazy, but it does do something very necessary. I want to take a look at what options we have available when using
ls and how to make those options work for you.
ls with no options
This lists all of the non-hidden files and directories in your working directory. Simple! Although, in my opinion, not the most useful.
-l option signifies the long list format. This shows a lot more information presented to the user than the standard command. You will see the file permissions, the number of links, owner name, owner group, file size, time of last modification, and the file or directory name. This option is used in conjunction with many other options on a regular basis.
-lh flag is the same long list format command as above, however, the file size is displayed in a human-readable format. Notice the difference between the file size outputs in the previous two screens.
This option, like the standard
ls command, lists all non-hidden files and directories. However, this command lists them in reverse order.
-a option displays all files, hidden or otherwise. Some files begin with
.. and those files are hidden from the user by default.
This combination of options will show the latest modification to a file or directory in reverse order.
This will show the
/ character at the end of all directories.
Displays the files in order of size from largest to smallest.
This option will list directory trees in a long format.
This option will display the
inode number beside each file or directory. An
inode is the index node that identifies a specific file. Some files have multiple hard links, however if the hard links of multiple files share an
inode, they are equivalent.
This command will show you the version of the ls command that you are using.
This will allow you to access the
man page for the
ls command and see all of the information that this article doesn't cover.
ls command is used by people everyday at a subconscious level. We all know the basics, but there are some great options that are under-utilized. I challenge you to make a point to use some of these lesser-known options in your daily work. You may be surprised at the utility that is available to you.
BONUS: To really become efficient, set up an
alias for your favorite flavor of
ls. For more information on creating aliases in Linux, see my previous article here.
Want to try out Red Hat Enterprise Linux? Download it now for free.