The ls commands list the content and optional information of the directories and files. When you execute the Ls command without options, they list the files alphabetically. In addition, it may be considered one of the most commonly used commands. Find out how to use them below.
ls command options
-a: lists all files, plus includes hidden files starting with “.”
-color: list of colors (when) [=always/never/auto]
-d: list directories – with ‘* /’
-r: list in reverse order
-R: list the directory tree recursively
–s: file size list
-S: sorted by file size
-F: add a character from * / => @ | to the entrails
-i: list the inode index number of the file
-l: large format list – show permissions
-la: list of long formats, including hidden files
-h: It shows the same information as ls -l, with the size units in KB, MB, etc.
-F, -classify: Indicator of addition (one of * / => @ | ) to the entries.
-file-type: Similar to -classify , except that no ‘ * ‘ is added
-group-directories-first: Groups the directories before the files. Increase with a -sort option, but any use of -sort = none (- U ) disables grouping.
-full-time: As -l.
-g: As -l, but does not list the owner of the file/directory
-t: by default, the files are displayed in alphabetical order. To list the files by time brand order (default modification date)
How to use the ls command
ls is a quite simple command but it helps to manage server interfaces because as said before it shows the content of a folder.
The basic syntax of this command is:
ls [options] [directory]
For example, the most common and easy way to use this command is:
ls /home/user/ Documents Downloads eclipse-workspace ...
Using that command you will display all the content of the specified directory. In this case
/home/user/ If you do not add any directory then it will show the contents of the current directory.
However, some options modify the behavior of the ls command.
So, we will show you the most useful and common options so that you can take advantage of this command.
Using the ls command
Using Linux it is common to have hidden folders and files. Especially in the configuration of programs. By default, the ls command doesn’t show them, but there is an option to do so.
To display hidden files, simply use the –a
ls -a [directory]
ls -a /home/user/Documents/ .. document.odt file.sql eclipse project
This will display all the files and folders in that directory.
To show the contents of the subdirectories. They use the option.
ls -R Documents/files: file1.txt file2.txt Documents/music: music.mp3 audio.ogg ...
To show all the information.
ls -l total 171668 -rw-r--r-- 1 user user 18265 Aug 7 15:54 document.odt drwxrwxr-x 8 user user 4096 Mar 13 2020 picture.jpg drwxr-xr-x 6 user user 4096 Sep 1 2019 project -rw-r--r-- 1 user user84097512 Sep 2 03:01 file2.txt
They will display the user, group, permission, size, date, and time of modification information. With the use of the option.
To visualize the information with the size units in KB, MB, etc. Use the option.
ls -lh total 168M -rw-r--r-- 1 user user 18k Aug 7 15:54 document.odt drwxrwxr-x 8 user user 4M Mar 13 2020 picture.jpg drwxr-xr-x 6 user user 4M Sep 1 2019 project -rw-r--r-- 1 user user 155M Sep 2 03:01 file2.txt
They show the same information as ls -l but in a very easy format.
The ls command is very useful, to view the files and directories, within the directory that the user is in.
Similarly, for users who are starting to use the commands, it is very useful to know the ls commands.
On the other hand, the ls command allows us to see the files that are hidden. They are also displayed alphabetically.
So, share this post and join our Telegram Channel.