List of content you will read in this article:
Linux Command is an effective service that is provided by the Linux OS. These commands are used to execute all the basic and advanced tasks. The implementation of the commands is done on the Linux terminal. The terminal is a powerful command-line interface used to cooperate with the system. The terminal emulator in Linux is identical to the command prompt in the Windows operating system. The commands that we use in Linux are case-sensitive.
Numerous commands pre-installed in Linux enable the user to direct the file system, install software packages, and organize the system and its applications. These are issued on the terminal by stating the title of an executable file; It can be either a binary program or a script.
Prerequisites
-
A Linux virtual machine with files and directories Linux operating system
-
Access to Linux terminal
-
The basic idea of the command-line interface
What is ls Command in Linux?
The Linux ls command is a utility used for viewing the contents of a directory, ls short form of List. It can be used to view files in both a long listing format, which includes additional information such as file size and modification time, or a short listing format, which only displays the filename. The ls command also supports many options for filtering and sorting the output.
Don't miss out on this opportunity to simplify your Linux file size management. Say goodbye to frustration and hello to efficiency! Ready to leap? Click here to learn How to Find File Size in Linux and revolutionize your Linux experience.
How to use the Linux ls Command?
The ls command is one of the most basic and essential commands in Linux. It's used to list files in the current directory, and it has a ton of options that can be used to customize the output. In this article, we'll show you how to use the ls command to list files in Linux. We'll also cover some of the most common options that can be used with ls. If you're new to Linux or if you're just getting started with the command line, this is a great place to start. Let's get started!
How to Read ls Output Columns?
The ls command is used to list files in the Linux terminal, displaying them in columns. The output of the ls command consists of various ls columns, which can be initially confusing, but with a little practice, it is easy to read and understand the information presented in these ls output columns.
Here is an example of the output of the ls command:
-rw-r--r-- 1 root root 0 Apr 12 13:14 file1.txt
-rw-r--r-- 1 root root 0 Apr 12 13:15 file2.txt
drwxr-xr-x 2 root root 4096 Apr 12 13:16 dir1/
- The first column shows the permissions for the file.
- The second column shows the number of links to the file.
- The third column shows the owner of the file.
- The fourth column shows the group that owns the file.
- The fifth column shows the size of the file in bytes.
- The sixth column showed when the file was last modified.
- The seventh column shows the name of the file or directory.
ls Command and ls Command Options
ls Command
List all files in the directory.
Syntax:
ls
ls -a Command
A user can’t see hidden files, As hidden files start with a . (dot) and are not detectable in the regular directory. This is where the ls-a command comes in handy. This command enlists the complete content of the existing directory and the hidden files.
Syntax:
ls -a
ls -l Command
If the user wants to see the contents of the files? To get that detailed information, the users must use the ls – l command. The file will be displayed in a long list format.
The long list format displays the contents column-wise.
Let’s say the contents have seven different attributes; then, the attributes will be displayed in seven columns.
For example,
The 1st column specifies particulars with regard to file permission.
The 2nd column specifies the total number of associations with the list.
The 3rd and 4th columns specify information related to the owner and group.
The 5th column specifies the total size of the file (in Bytes).
The 6th column displays the last updated date and time.
The 7th column displays the file/directory name.
Syntax:
ls -l
ls -l --block-size=[SIZE] Command
This command is used if the user desires to display the file size in their preferred format. There are eight different size formats. They are:
K = Kilobyte
M = Megabyte
G = Gigabyte
T = Terabyte
P = Petabyte
E = Exabyte
Z = Zettabyte
Y = Yottabyte
Users can replace SIZE with their preferred choice.
For example,
ls -l --block-size=M
If you select your size as M, then the size of all files will be displayed in Megabytes.
Syntax:
ls -l --block-size=[SIZE]
ls -lrt Command
To list files and directories in long format, sorted by modification time in reverse order, with the most recently modified files appearing at the end of the list.
Syntax:
ls -lrt
ls -d */ Command
This command is used in those cases where you only want to show the sub-directories and not any other files.
Syntax:
ls -d */
ls –g Command
If, in any situation, you want to display all the other file information without the owner information column, then use this command.
Syntax:
ls -g
ls –lG Command
If, in any situation, you want to display all the other file information without the group column, then use this command in Linux OS.
The group column will be excluded from the output.
Syntax:
ls -lG
ls --color=[VALUE] Command
This command is used if the user wants to colorize and decolorize the list. To get a colored list, you’ve to replace [VALUE] with auto, and if you want to get a decolorized list, replace [VALUE] with never.
Syntax:
ls --color=[VALUE]
ls ~ Command
The ls ~ command displays all the contents of the home directory.
Syntax:
ls ~
ls ../ Command
Using this command, you can enlist the details of the parent directory.
Let’s say there are two directories. The current directory is the “Downloads” directory and the directory that is previous to it i.e. its parent directory is the “Home” directory.
Syntax:
ls ../
ls –version Command
Using this command, the user can look into the version of the ls command.
Syntax:
ls -version
ls –F Command
If you put the -F command with the ls command then it will add a new character ‘ / ‘ at the end of every directory.
Syntax:
ls -F
ls –help Command
Syntax:
ls -help
ls -n Command
The ls -n command displays files and directories with their respective inode numbers.
Syntax:
Is -n
ls –r Command
The ls -r command shows all the existing files and directories but in reverse order.
Syntax:
ls -r
ls -R Command
The ls -R command only displays the long listing directory trees.
Syntax:
Is -R
ls -i Command
When you use the ls -i command, it will display all the existing files or directories with an inode number before it.
Syntax:
Is -i
ls -l Command
In Linux, if the user wants to create an alias of their Is terminal command, then they can use this command.
Syntax:
Is -l
Other ls Commands in Linux
ls command in Linux sort by size
To sort the output of the "ls" command by size in Linux, you can use the "-S" option. This will display the files and directories in the current directory, sorted by size in descending order. The largest files will appear at the top of the list.
Syntax:
ls -S
ls command in Linux sort by date
To sort the output of the "ls" command by date in Linux, you can use the "-t" option. This will display the files and directories in the current directory, sorted by modification time in descending order. The most recently modified files will appear at the top of the list.
Syntax:
ls -t
Summary
There is a plethora of ls command in Linux that can be used to list the files and directories in a Linux operating system. But these were some of the basic ls commands in the Linux operating system. These commands help users to implement their tasks comfortably and effortlessly. They are also proven to be very effective.
Users need to practice them a lot as it may take some time to adapt to these commands.
People Are Also Reading:
I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.