ls command in Linux / Unix




Linux ls command.

ls  command Lists the files in the current directory, in alphanumeric order, except files starting with the “.” character.

ls command syntax

ls command options

ls command main options:

option description
ls -a (all) Lists all the files (including .* files)
ls -l (long) Long listing (type, date, size, owner, permissions)
ls -t (time) Lists the most recent files first
ls -S (size) Lists the biggest files first
ls -r (reverse) Reverses the sort order
ls -ltr (options can be combined) Long listing, most recent files at the end
ls -d -d tells ls not to display the contents of directories
ls -i list file’s inode index number
ls -la (long + all) Long listing + Lists all the files
ls -ls (long + size) Long listing with size
ls -R list recursively directory tree

ls command examples

ls (List):

Lists filse present in directory

 


ls -a (all) :

Lists all the files (including .* files)

 


ls -l (long) :

Long listing (type, date, size, owner, permissions)

 


The shell first replaces *txt by all the file and directory names ending by txt (including .txt), except those starting with ., and then executes the ls command line.

 


Lists all the files and directories starting with . -d tells ls not to display the contents of directories.