Basic Usage of ‘ls’ Command in Kali Linux With Examples

One of the most used Kali Linux commands ‘ls‘ is used by almost every person in the Kali Operating system. It is usually to view the content of the current directory or targeted directory where you wanted to list the files in a specific folder.

This command not only works on Kali Linux it basically works on all Linux distros and macOS as well.

1. ls Command – Basic Usage

The most basic use of any command is when it is used without any option or parameter. So, when the ls command is executed with no option or parameter, then it will enlist files and sub-directories of the current directory.



2. A Long List

ls command when used with option -l (L in small caps), will display the contents of the current directory in a long list format.


ls -l

In the output:

  • 1st column will give detailed information regarding file permission,
  • 2nd column will tell you about the number of links to the file,
  • 3rd and 4th column is associated with the owner and group of the file,
  • 5th column will be displaying the size of the file in bytes,
  • 6th column will display the recent time and date at which the file was modified,
  • and the last and 7th column is the actual file/directory name.

3. Displaying Size in Human Readable Format

Sometimes it is very confusing to read the size of the files in terms of bytes, especially when the file size is very large. So, instead of printing the file size in terms of bytes, we can display it in human-readable forms, like MB, GB, TB, and so on. This can be achieved when the ls command is executed with the option -h as follows:


ls -lh

4. Sort According to File Size

You can sort the ls command output such that the largest file (according to size) will be displayed first and the smallest one at the last and this can be done with the use of option -S.


ls -lhS

5. Determine the Block Size

If you wish to display the size of all the files in a specific human-readable format, you can do it by using the following syntax:


ls -l –block-size=[SIZE]

The [SIZE] in the above syntax can be replaced by the following letters in order to scale the size as per your requirement:

  • K = Kilobyte
  • M = Megabyte
  • G = Gigabyte
  • T = Terabyte
  • P = Petabyte
  • E = Exabyte
  • Z = Zettabyte
  • Y = Yottabyte

In the above example, I have scaled the file size to KB and to do so, I have replaced the [SIZE] thing in the syntax with the letter ‘K’.

6. List the Hidden Files too

In Linux, the files can be hidden by starting a file name with a “.” (dot) symbol. You can list these hidden files by the use of option -a with the ls command.


ls -a

7. Show Me Only Sub-Directories

If you wish to exclude all the files and display only sub-directories, then you can use option -d as follows:


ls */

8. Don’t Display Owner and Group Info

You can exclude the columns providing Owner and Group information by using options -g and -G respectively.


ls -g

9. Display User ID and Group ID

When the ls command is run with option -n, it will print the UID and GID of the owner and group instead of their names.


ls -n

10. Color Changes

This will simply colourize and de-colourize the list when the [VALUE] in the syntax given below is replaced by proper values. You can decolourize it by replacing [VALUE] with never and colourize it by replacing it with auto.


ls --color=never

11. Give Me INODE Numbers

When the ls command is complemented by option -i, it will print the Inode (Index) Numbers of the files in the first column.


ls -li

12. Marking the Directories with a Slash (/) Sign

This is to make identification of the directories easier.


ls -p

13. Sort in Reverse Order

This is for sorting the results in reverse order.


ls -r

14. Show the Contents of Sub-Directories

ls command when used with option -R, will display the contents of the sub-directories too.


ls -R

15. Sort by Extensions

With option -X, you can group the files with the same extensions together.


ls -lX

16. Sort by Modification Time

You can sort the output according to the time of modification. The recently modified file will be displayed first.


ls -lt

17. Listing the Contents of the Home Directory


ls  ~

18. Listing the Contents of the Parent Directory


ls ../

19. Check out the Version Details


ls --version

That’s all about the ‘ls’ command in Kali Linux for now!

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button