ls command in Linux

The ls command in Linux

Today’s topic: ls command in Linux. Linux command is a useful service provided by the Linux operating system. These commands are used to execute all basic and advanced tasks. Commands are implemented in the Linux terminal. A terminal is a commanding and powerful command-line interface used to interact with the system. Linux’s terminal emulator is similar to Windows operating system’s command prompt. The commands we use in Linux are case-sensitive.

The Linux OS comes pre-installed with many Linux commands that enable the user to manage the file system, install software packages, and organize the system and its applications. Commands are issued in the terminal by specifying the title of an executable file. Linux commands can be binary programs or scripts.

As mentioned earlier, two types of tasks can be performed through terminals, basic tasks, and advanced tasks. Basic tasks include creating a file, deleting a file, moving a file, etc. while advanced tasks include several administrative tasks (such as installing a package, managing users), network-related tasks, security tasks, etc.

To run commands you first need to know how to open a terminal. To open a terminal, press “CTRL + ALT + T” and press the “Enter” key to execute any command. In this article, we will mainly discuss the “ls command”, what they are, their usage, and examples.

Different types of Linux commands

Linux commands can be of different types. Following are the different types of Linux commands:

Prerequisites

  1. Linux directory command
  2. Linux file command
  3. Linux file content command
  4. Linux user commands
  5. Linux filter command
  6. Linux networking commands
  7. Linux utility commands
  8. A machine with files and directories
  9. Linux operating system
  10. Access to the Linux terminal
  11. Basic concepts of the command-line interface

ls Commands

The ls command is one of the most frequently used commands in the Linux Terminal. There are several ls commands that serve different needs. The ls command is a type of Linux directory command. We will now discuss all the basic ls commands with examples and parameters.

The ls command shows all available contents of a directory.

Syntax: ls

Linux ls -a Commands

In Linux, a user usually cannot see hidden files. Hidden files start with a . (dot) and is not detectable in regular directories. This is where ls -a command comes in handy. This command lists the entire contents of existing directories as well as hidden files.

Syntax: ls -a

Linux ls -l Command

The ls command, as mentioned, only shows files. But what if the user wants to see the contents of the file? To get that detailed information, users need to use ls – l command. The file appears in a long list format.

The long list format displays content by column.

Let’s say the content has seven different attributes, then the attributes will appear in seven different columns.

For example,

  1. 1st column specifies file permission details.
  2. The 2nd column indicates the total number of associations with the list.
  3. The 3rd and 4th columns specify owner and group information.
  4. 5th column specifies the total file size (in bytes).
  5. 6th column displays last updated date and time.
  6. The 7th column displays the file/directory name.

Syntax: ls -l

Linux ls -l –block-size=[SIZE] Commands

This command is used if the user wants to display the file size in their preferred format. There are eight different size formats. They are:

  1. K = Kilobyte
  2. M = Megabyte
  3. G = Gigabyte
  4. T = Terabyte
  5. P = Petabyte
  6. E = Exabyte
  7. Z = Zettabyte
  8. Y = Yottabyte

Users can replace SIZE with their preferred option.

For example, ls -l –block-size=M

If you select your size as M, all file sizes will be displayed in megabytes.

Syntax: ls -l –block-size=[SIZE]

Linux ls -d */ Commands

This command is used in cases where you want to show only sub-directories and no other files.

Syntax: ls -d */

Linux ls –g Command

If in any situation you want to display all file information other than the owner information column, use this command.

Syntax: ls -g

Linux ls –lG Commands

If in any situation you want to display all file information except the group column, use this command.

Group columns will be excluded from the output.

Syntax: ls -lG

Linux ls –color=[VALUE] Commands

In Linux, this command is used if the user wants to colorize and fade the list. To get a colored list, you need to replace [VALUE] with ‘auto’, and if you want a faded list, replace [VALUE] with ‘never’.

Syntax: ls –color=[VALUE]

Linux ls ~ Command

The ls ~ command displays all the contents of the home directory.

Syntax: ls ~

Linux ls ../ command

Using this command you can list the details of the root directory.

Let’s say there are two directories. The current directory is the “download” directory and its previous directory i.e. Its parent directory is “home” directory.

Syntax: ls ../

Linux ls –version Command

By using this command user can check the version of the ls command.
Syntax: ls -version

Linux ls –F commands

If you put the -F command with the ls command, it will add a new character ‘ / ‘ to the end of each directory.
Syntax: ls -F

Linux ls -help command

Syntax: ls -help.

Linux ls -n commands

Syntax: Is -n

Linux ls –r command

The ls -r command shows all existing files and directories but in reverse order.
Syntax: ls -r

Linux ls -R commands

The ls -R command displays only the long-listed directory tree.
Syntax: Is -R

Linux ls -i command

When you use the ls -i command it will display all existing files or directories with an inode number before them.
Syntax: Is -i

Linux ls -l commands

On Linux, if the user wants to create an alias for their Is command, they can use this command.
Syntax: Is -l

Conclusion

The Linux operating system has a plethora of ls command to unlist files and directories. But, these were some basic ls commands of the Linux operating system. These commands help the users to execute their tasks comfortably and effortlessly. They are proven very effective.
Users need to practice them a lot as these commands may take some time to get used to. You can buy Linux VPS from Oudel Inc. You can read Linux Kill Command here.

Scroll to Top