The ls command goes all the way back to the original AT&T UNIX operating system. The name, ls, was originally an acronym for list segments. In the early days of UNIX the word segments was used in the same way we use files today (hence ls and not lf.) Now there are two versions of the ls command available: The FSF (Free Software Foundation) release that comes with the coreutils package, and a BSD variant. The version of ls you will find on Linux is the FSF version. Should you be using a BSD-based distribution, you will be using the BSD variant of ls.
The ls command is simple to use. From the command line you can enter the command ls and hit enter to list the contents of the current working directory. In other words, if you are in the /home/jack directory and you issue the ls command, you will see the contents of the /home/jack directory. Of course you are not limited to only the current working directory. Say, for example, you are in the /home/jack/ directory but you want to see the contents of the /opt directory. To do this you would enter ls /opt and hit enter to display the contents of the /opt directory.
Without any arguments, the ls command only lists names of the visible files in a directory. Say, however, you want to see all files including hidden files (files that begin with a “."). To include hidden files in the listing you add the -a flag to the ls command. Now the command looks like: ls -a.
Say, however, you want to see more details of your directory files. You can add the l flag to change the basic listing to a long listing. The long listing includes: file types, permissions, hard links, owner, group, file size, and file name.
More Advanced Use
With Linux you can pipe one command through another command. This might be easier explained with the use of ls. When you enter the ls command the contents of the directory will fly by until they reach the end. If there are quite a few files within a directory you will not see every item. To be able to page through the contents you can pipe the ls command to the less command which will list the contents one page at a time. The piping of ls to the less command will look like this: ls | less. The “|” indicates the piping. Now you will see one page of contents and hit the space bar to see the next page.
The ls command is one of those tools that will become invaluable in your use of the Linux command line. Although there is much more to be had with its usage, this article will give you all you need to be able to use ls.
This post is part of the series: Linux Command Line
If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.
- Linux Command Line: Introduction
- Linux Command Line: ls
- Linux Command Line: cd
- Linux Command Line: mkdir
- Linux Command Line: df
- Linux Command Line: ln
- Linux Command Line: top
- Linux Command Line: mount/umount
- Linux Command Line: Cron/Crontab
- Linux Command Line: chmod
- Linux Command Line: wget
- Linux Command Line: cat
- Linux Command Line: grep
- Linux Command Line: dd
- Linux Command Line: sudo
- Linux Command Line: startx
- Linux Command Line: adduser
- Linux Command Line: at
- Linux Command Line: aterm
- Linux Command Line: nano
- Linux Command Line: hostname