Top 10 LS command examples in Unix /Linux
![]() |
Ls is one of the frequently used commands in Linux as well as UNIX and it is important to know about this command Ls command list the names of files or directories in a directory.
ls command sort the files alphabetically and output to the standard console. when ls command is executed, Linux server does inode sorting and outputs the files on alphabetically
in Linux files metadata are stored in a data structure which includes file owner, file access rights and file type. Each inode is a unique index number in organized file system data structure
ls is one of the basic commands of Unix/Linux operating system.
ls command works on bash shell as well as CentOS of Unix.
ls command syntax usage
$ls (options) (file name or directory)
ls command syntax is shown above and ls command examples are shown below
How to display content of directory using ls command
bash-3.2$ ls cloud.txt directory1
ls command without options displays the files and directories in a current directory
bash-3.2$ ls cloud.txt directory1
How to list the inode information using ls command line
$ls -l filename 12345 filename
here 12345 is index number
l without options list the files and in the directory
How to list the files and directories in a given path
$ls -l
ls command with option -l list out the long file format information about files and directories
How to list the files based on sorting order modification time.
$ls -t
ls command with option -t displays the recently modified file first and so on
How to list directories using commands
$ls -d
ls command with option -d outputs a list of directories in a given path, but not subdirectories
How to print the files without doing the sorting?
$ls -f or ls -U
ls command do the sort the files alphabetical and outputs it, Suppose In a given directory, if there 500 files, To view all these files, if ls command is supplied without any arguments, server does sorting of this file's inode and takes more time in hours, so in this case we need to use ls command with option -f to list the filenames without doing sorting
How to display content of files/directory recursively
to list the files in directories and subdirectory or recursive directories
$ ls -R
T
How to show hidden files in command line
$ ls -a or ls -A
ls command with option -a outputs the normal files as well as hidden files. to differentiate normal file with hidden files, hidden files always start with '.'
EmoticonEmoticon