More with the ls command

Hadir Jenni
2 min readNov 14, 2020
Linux

Once you become a linux user you’ll need some basic commands like the ls command..

LS

Ls command :

Ls is a shell command that list all contents (either files or directories) of the current directory.

So if you want to see the content of your current directory using terminal just type ls and push enter and this is an exemple of the result :

Ls command

The syntax of Ls :

$ ls [options] [file|dir]

Options of Ls command :

Ls have some usefull options for example :

  • ls -a : list all files including hidden file starting with ‘.’
  • ls — color : colored list [=always/never/auto]
  • ls -d : list directories — with ‘ */’
  • ls -F : add one char of */=>@| to enteries
  • ls -i : list file’s inode index number
  • ls -l : list with long format — show permissions
  • ls -la : list long format including hidden files
  • ls -lh : list long format with readable file size
  • ls -ls : list with long format with file size
  • ls -r : list in reverse order
  • ls -R : list recursively directory tree
  • ls -s : list file size
  • ls -S : sort by file size
  • ls -t : sort by time & date
  • ls -X : sort by extension name

But what ‘s exactly happens when you type ls -l?

ls -l command:

ls -l means list content of the current directory in a long format so the option -l means LONG FORMAT, let’s see an example of the output of this command :

ls -l command

Once you push enter the content of the directory shows line per line each line contain :

  • Name of a file or a folder
  • Date of creation of the item
  • The size in bytes
  • Name of the createur (name of the current user)
  • The permissions of the file

That’s the magic of the command ls and it’s options.

Happy learning , hope you find this article useful.

--

--