DEV Community

Cover image for Linux Commands: ls
Umesh Yadav
Umesh Yadav

Posted on • Updated on • Originally published at umesh.dev

Linux Commands: ls

ls is the Linux command to list the content of a directory. You can list all the files and folders inside a directory. Let's try it in your terminal.

Screenshot 2020-10-06 at 2.14.52 PM.png

You can pass arguments to ls to change the output. Let's take a look at ls -al.

Screenshot 2020-10-06 at 2.15.44 PM.png

It has more detailed information as compared to ls. It uses two flags l and a. a is used to show all the files even if the files are hidden(Hidden files are the one which starts with a dot at the beginning). l is used to show details about each file and folder. Let me explain to you what exactly are those. We will take one of the lines from output.

drwxr-xr-x  12 umesh  staff   384 Dec 11  2018 .git
Enter fullscreen mode Exit fullscreen mode
  • drwxr-xr-x: This defines the permission of the file.
  • 12: It tells the number of links to that file.
  • umesh: This signifies the username of the owner of the file
  • staff: This signifies the group of the file.
  • 384: file size in bytes.
  • Dec 11 2018: file created/updated datetime.
  • .git: filename.

There are a bunch of flags available that can be used to modify the output of the ls command. I am listing a few of them down below try them out in your terminal and let me know your experience and which one is your favorite in the comments.

  • l - List files and directories in the long format
  • a - Include directory entries whose names begin with a dot (.).
  • d - Directories are listed as plain files (not searched recursively).
  • i - For each file, print the file's file serial number (inode number).
  • G – Enable colorized output.
  • h – List the size of the files and directories in Human Readable format.
  • S - Sort files by size

If you liked this blog please feel free to share with others, if you are sharing it on twitter please tag @imumesh18 . If you are interested in more of these please subscribe to my newsletter.

Top comments (2)

Collapse
 
mmi profile image
Georg Nikodym

Trivia:

In the permission string, rwxr-xr-x, each character corresponds to a binary bit. A letter meaning 1 and a - meaning 0.

111 101 101 -> 7 5 5

which you might recognize as a common numerical (octal) permission that one might supply to the chmod command. This is how chmod 644 file yields permissions of rw-r--r--

Collapse
 
umesh profile image
Umesh Yadav

Nicely explained 👍