Top 10 ls command examples with tutorials in Linux/Unix

Top 10 LS command examples in Unix /Linux


Ls is one of the frequently used command 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 standard console. when ls command is executed, Linux server do inode sorting and outputs the files on alphabetically
in Linux files metadata are stored in data structure which includes file owner, file access rights and file type. Each inode is an unique index number in organized file system data structure
ls is  one of the basic command of unix/linux operating system.
ls command works on bash shell as well as Cent OS 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 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 recent modified file first and so on

How to list directories using commands
$ls -d 
ls command with option -d outputs list of directories in a given path, but not sub directories

How to print the files without doing 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 files 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 sub directory or recursive directories
$ ls -R  
T
How to show hidden files in command line
$ ls -a  or ls -A
ls command with option -a ouputs the normal files as well as hidden files. to differentiate normal file with hidden files, hidden files are always start with '.'

No comments:

Post a Comment

Note: only a member of this blog may post a comment.