How to use the Linux ls command to display your directories

The Linux ls command enables you to display content in a directory or folder. You’ve also got various options to make this command more precise.

What is the Linux ls command?

Linux ls is one of the most commonly used Linux commands. You can use this command to show all the content in a folder or directory in the command bar. The content will normally be displayed in alphabetical order as standard. lt is one of the standard tools found in most Linux distributions such as Ubuntu and can be run using different options to focus in more on what you’re looking for. Ls (not i s) stands for “list”.

How does the ls command work?

If you enter the ls command in the command bar and run it, it will pull all available information of an entire folder or directory and display it to you following the alphabetical order of the file names. This means that you don’t need to use the Linux cd command to switch to another directory to look at it. For this reason the ls command is a great tool which makes your work easier. If you don’t enter a specific folder, the system will give you information about the one you’re currently working in.

What does the ls syntax look like?

The Linux ls command’s syntax is very easy to use and looks as follows:

$ ls [Options] [Directory]
shell

ls is the actual command and you can use the options to make it more precise. You need to enter the name of the directory correctly in order to get the information you’re looking for.

What options does the ls command have?

If you run the ls command without using any options you will see all the information on your files available in alphabetical order. You can use your options to refine your search if you need to.

  • -A or –almost-all: Use this option to list hidden information.
  • -a or –all: You can use this option to show directories such as . and .. alongside the hidden information.
  • -C: This option returns the file names alongside each other. This is a standard setting.
  • -c: Use this option to sort the information by the date of the last change. The last change will be top of the list.
  • -d or –directory: Only shows the name of the directories and not their content.
  • -h or –human readable: You can use this option to make the results easier to read and it changes the size. It’s often used in combination with -l.
  • -i: Use this option to show the Inode number in front of the file name.
  • -l: This options shows you the data in long form.
  • -m: Use this option to see the names in a row.
  • -R or –recursive: Shows recursive information also taking into account subdirectories.

Examples of a ls command

So you can get a better idea of how the -ls command is used, here are a few practical examples:

$ ls -la EXAMPLE
shell

This gives you all information on the directory EXAMPLE in long form. Use the option -a to list hidden information as well.

$ ls -la EXAMPLE
shell

Use the command to open all information about your current directory and subdirectory.

We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.