Linux ls commandThe ls is the list command in Linux. It will show the full list or content of your directory. Just type ls and press the enter key. The whole content will be shown. ls is a command used to list computer directories and files in Unix-like and Unix operating systems. It is developed by the Single Unix Specification and POSIX. The numerical computing environments GNU Octave and MATLAB contain an ls function with the same functionality. In several other environments like Microsoft Windows, OS2, and DOS, the same functionality is given by the dir command. The different implementations include different options, as with almost every utility. We can check the documentation given by the command for suitable options and usage. Brief History of lsAn ls utility occurred in the AT&T UNIX first version, the title acquired from the same command in Multics also titled 'ls', an acronym for the "list" term. ls is a component of the X/Open Portability Guide from issue 2 of 1987. It was acquired into the POSIX.1 first version and the Single Unix Specification. BehaviorUnix-like and Unix operating systems manage the thought of a working directory. ls lists several files inside the working directory when used without arguments. In that directory, the files are listed if a directory is mentioned. The arguments might include directories and files. Names beginning with the "." symbol are hidden. The "." directory is known as the working directory, and the ".." symbol is known as its parent directory. By default, they are shown. All files are displayed using -a. File names explicitly specified are listed always. ls only displays names without options. Multiple options might be combined. The basic options are:
It is possible to display different items with different types of colors. It is an area in which implementations differ:
Example: Below, you can see, after entering ls command, we got the whole content list of /home/sssit directory. Linux ls command options
Linux ls -a commandIt will give you the whole list of a directory including the hidden files also. In Linux, hidden files start with a dot (.) and can't be seen in the regular directory. Example: In the above example, you can see the whole list of files, including the hidden files. Linux ls -l commandThe ls command will only display the files. But if you want your files to be displayed in a long list format, then you can use ls -l command. Example: Here, as you can see the list in long list format. Columns above indicate specific things:
Linux ls -l --block-size=[SIZE]If you want to display the file size of your list in a particular format or size, then you can use this command. Just put the size in place of [SIZE] as per your requirement. Syntax: Example: Let's see the output below. Here, all file size has listed in Megabyte. You can replace [SIZE] with the following measures:
Linux ls -d */If you only want to display the sub-directories excluding all other files, you can use this command. Example: The above result only shows sub-directories excluding all the other files. Linux ls -gIf you don't want to display the owner information in your list, then you can exclude this column with the help of this command. Example: Here owner column is excluded. Linux ls -lGIf you don't want to display the group information in your list then you can exclude this column with the help of this command. Here group column is excluded. Linux ls --color=[VALUE]This command is used to colorize and decolorize the list. If you replace the [VALUE] by 'auto', it will display the colored list. But, if you will replace the [VALUE] by 'never', it will decolorize the list. Syntax: Example: You can easily notice the difference between auto and never command in the above image. Linux ls ~Linux ls ~ command shows the contents of the home directory. Let us see the example of ls ~ command. Example: Linux ls ../This command contains the list of the parent directory. In the given example, our current directory is Downloads, and by using ls ../ command, we have listed out the content of its parent directory "home directory". Example: Open the last modified file with ls -tIt can sort the file by edited time, displaying the last modified file first. To open the last modified file in the current working directory, we can use the ls command and head commands: Show file size in HRF (human readable format)To show file size in a human readable format, i.e., GB, G, KB, MB, etc., we can use the below command: Where h is short for human readable format. Show directory informationWhen we use "ls -l", we will get the information of the directories content. But if we wish to see the information of the directory, we can use the -d option. Older files related to the last edited timeWe can use the ls -lt command for sorting the file names shown in the sequence of the last edited time. We will find it handy to utilize it with the -l option. The command is mentioned below: Older files related to the last edited time (reverse order)We can use the ls -ltr command for sorting the file names shown in the sequence of the last edited time in the reverse sequence. It will show the last modified file in the end line. It becomes more accessible when the listing process goes lengthy. The command is mentioned below:
Next TopicLinux mkdir Command
|