List of content you will read in this article:
- 1. Prerequisites
- 2. What is ls Command in Linux?
- 3. How to use the Linux ls Command?
- 4. How to Read Output of ls Command in Linux OS?
- 5. Summary
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.
- 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. 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.
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 Output of ls Command in Linux OS?
The ls command is used to list files in the Linux terminal. The output of the ls command can be confusing, but with a little practice, it is easy to read.
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.
List all files in the directory.
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.
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.
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.
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.
ls -l --block-size=M
If you select your size as M, then the size of all files will be displayed in Megabytes.
ls -l --block-size=[SIZE]
ls -d */ Command
This command is used in those cases where you only want to show the sub-directories and not any other files.
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.
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.
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.
ls ~ Command
The ls ~ command displays all the contents of the home directory.
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.
ls –version Command
Using this command, the user can look into the version of the ls command.
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.
ls –help Command
ls -n Command
ls –r Command
The ls -r command shows all the existing files and directories but in reverse order.
ls -R Command
The ls -R command only displays the long listing directory trees.
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.
ls -l Command
In Linux, if the user wants to create an alias of their Is terminal command, then they can use this command.
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'.