Linuxips
  • Home
  • Linux
  • Debian
  • Ubuntu
  • Fedora
  • Arch Linux
No Result
View All Result
Linuxips
  • Home
  • Linux
  • Debian
  • Ubuntu
  • Fedora
  • Arch Linux
No Result
View All Result
Linuxips
No Result
View All Result
Home Commands

ls Command in Linux

admin by admin
August 11, 2022
in Commands, Linux
Reading Time: 4 mins read
0
ls Command in Linux
0
SHARES
51
VIEWS
Share on FacebookShare on Twitter

In this article,  we are going to learn about ls Command in Linux. ls is probably the most used command and for good reason. With it, we can see directory contents and determine a variety of important file and directory attributes. As we have seen, we can simply enter ls to see a list of files and subdirectories contained in the current working directory.

Contents hide
1 ls Command in Linux
2 Options and Arguments
3 A Longer Look at Long Format
3.1 ls Long Listing Fields
4 Conclusion

ls Command in Linux

$ ls

Besides the current working directory, we can specify the directory to list, like so:

$ ls /usr

or even specify multiple directories. In this example we will list both the user’s home directory (symbolized by the ~ character) and the /usr
directory:

$ ls ~ /usr

We can also change the format of the output to reveal more detail:

$ ls -l

By adding -l to the command, we changed the output to the long format.

Options and Arguments

This brings us to a very important point about how most commands work. Commands are often followed by one or more options that modify their behavior and, further, by one or more arguments, the items upon which the command acts. So most commands look something like this:

command -options arguments

Most commands use options consisting of a single character preceded by a dash, such as -l. But many commands, including those from the GNU Project, also support long options, consisting of a word preceded by two dashes. Also, many commands allow multiple short options to be strung together. In this example, the ls command is given two options, the l option to produce long format output, and the t option to sort the result by the file’s modification time:

$ ls -lt

We’ll add the long option –reverse to reverse the order of the sort:

$ ls -lt --reverse

The ls command has a large number of possible options. The most common are listed below:

OptionLong OptionDescription
-a–allList all files, even those with names that begin with a period, which are normally not listed(i.e., hidden).
-d–directoryOrdinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents.
-F–classifyThis option will append an indicator character to the end of each listed name (for example, a forward slash if the name is a directory).
-h–human-readableIn long format listings, display file sizes in human-readable format rather than in bytes
-lDisplay results in long format.
-r–reverseDisplay the results in reverse order. Normally, ls displays its results in ascending alphabetical order.
-SSort results by file size.
-tSort by modification time.

A Longer Look at Long Format

As we saw before, the -l option causes ls to display its results in long format. This format contains a great deal of useful information. Here is the Examples directory from an Ubuntu system:

Let’s look at the different fields from one of the files and examine their meanings:

ls Long Listing Fields

[linuxips@ubuntu ~/Downloads]$ ls -l

drwxrwxr-x 2 linuxips linuxips 4096 Aug 12 12:30 Backup
drwxrwxr-x 2 linuxips linuxips 4096 Aug 12 12:30 Data
-rw-rw-r-- 1 linuxips linuxips 0 Aug 12 12:30 Info
-rw-rw-r-- 1 linuxips linuxips 276990976 Apr 15 02:07 wps-office.deb

 

FieldMeaning
-rw-r—r–
Access rights to the file. The first character indicates the type of file. Among the different types, a leading dash means a regular file, while a d indicates a directory. The next three characters are the access rights for the file’s owner, the next three are for members of the file’s group, and the final three are for everyone else.
1File’s number of hard links.
2Directory’s number of hard links.
linuxipsThe user name of the file’s owner
linuxipsThe name of the group that owns the file
4096Size of the file in bytes.
Aug 12 12:30Date and time of the file’s last modification.
BackupName of the file

Conclusion

So this is the ls Command in Linux. This article was intended to share the five most practical examples of using the “ls” command in Linux. However, if you want to know more about this command’s usage, you can execute the “ls –help” command in Linux for accessing the help manual of this command. You can use it as you want. Enjoy!!!

Related Linux Tutorials:

  • How to Install Cisco Packet Tracer on Ubuntu.
  • How to install Tweak Tool on Ubuntu 21.04.
  • ZSH to BASH | How to Install ZSH on Ubuntu.
  • How to Install Ubuntu.
  • mkdir Command in Linux
  • pwd command in Linux
  • Whoami Command in Linux
Tags: Basic Linux CommandsLinuxLinux commandls Command
Previous Post

Basic Linux Commands for Beginners

Next Post

How to Upgrade to Ubuntu 22.04 LTS

admin

admin

Linuxips is a Linux blog that publishes articles and tutorials about server operations, installations, new techniques and Linux security.

Related Posts

Install ZSH on Arch Linux
Arch Linux

How to Install ZSH on Arch Linux

January 6, 2024
How To Use AppImage in Linux
Linux

How To Use AppImage in Linux [Complete Guide]

April 2, 2023
How To Install uGet Download Manager On Ubuntu
Linux

How To Install uGet Download Manager On Ubuntu

March 8, 2023
Linux Files and Directories
Linux

Linux Files and Directories

March 3, 2023
How to Create Files With Passwords in Linux
Linux

How to Create Files With Passwords in Linux

February 27, 2023
pwd Command in Linux
Commands

pwd command in Linux

November 6, 2022
Next Post
How to Upgrade to Ubuntu 22.04 LTS

How to Upgrade to Ubuntu 22.04 LTS

Leave a Reply Cancel reply

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

No Result
View All Result

You might also like

Install ZSH on Arch Linux

How to Install ZSH on Arch Linux

January 6, 2024
How to Install ZSH on Kali Linux 2024.1

How to Install ZSH on Kali Linux

January 5, 2024
How To Use AppImage in Linux

How To Use AppImage in Linux [Complete Guide]

April 2, 2023
How To Install uGet Download Manager On Ubuntu

How To Install uGet Download Manager On Ubuntu

March 8, 2023
How to Install ZSH on Ubuntu 22.10

How to Install ZSH on Ubuntu 22.10

March 7, 2023
Linux Files and Directories

Linux Files and Directories

March 3, 2023

© 2024 Linuxips.com - Linux Tips, Tricks and Tutorials.

  • Home
  • Web Stories
  • Privacy Policy
  • Contact Us
  • Disclaimer
No Result
View All Result
  • Home
  • Linux
  • Debian
  • Ubuntu
  • Fedora
  • Arch Linux

© 2024 Linuxips.com - Linux Tips, Tricks and Tutorials.