Linux ls command
ls command is used to list directories and files. Without any options the basic
ls command lists the visible directories and files in the current directory. The user must have the access to list that directory.
Basic Example of
In this example, we entered
ls in terminal. And got the files and directories list in /home/infolinux directory.
ls command options
Linux hidden files start with . (dot) symbol and hidden file are not visible in the regular directory. The (ls -a) command will show the whole list of the current directory including the hidden files.
It will show the list in a long list format on your destination directory. Simply, it shows the time, permissions, owner, type, id, size etc with the name of the file/directory.
ls -lh command will show you the file sizes in human readable format. Size of the file is very difficult to read when displayed in terms of byte. The (ls -lh) command will give you the data in terms of Mb, Gb, Tb, all size etc.
If you want to display your files in descending order (highest at the top) according to their size, then you can use (ls -lhS) command.
ls -l – -block-size=[SIZE]
This command used to display the files in a specific size format. Here, in [SIZE] you can assign size according to your requirement.
ls -d */
It is use to display only subdirectories.
ls -g or ls -lG
With this command you can exclude column of group information and owner.
It is used to print group id and owner id instead of their names.
It is used to print list as colored or discolored.
It is used to print the index number if file is in the first column.
This command is used to identify the directory easily by marking the directories with a slash (/) line sign.
It is used to print the list in reverse order.
Recursive; It will display the content of the sub-directories also.
It will group the files with same extensions together in the list.
It will sort the list by displaying recently modified filed at top.
It gives the contents of home directory.
It give the contents of parent directory.
It checks the version of ls command.
Linux ls command some practical with example below :
Columns above indicate specific things:
1. Column 1 indicates information regarding file permission.
2. Column 2 indicates the number of links to the file.
3. Column 3 & 4 indicates the owner and group information.
4. Column 5 indicates size of the file in bytes.
5. Column 6 show date and time.
6. Column 7 show the file or directory name.
Linux ls -l –block-size=[SIZE]
ls -l –block-size=M
You can replace [SIZE] with the following measures:
K = Kilo byte
M = Mega byte
G = Giga byte
T = Tera byte
P = Peta byte
E = Exa byte
Z = Zetta byte
Y = Yotta byte
Path Completion in Linux
Linux path completion is a very helpful feature in terminal. You can navigate and complete your commands fast. Type a few characters and press ‘Tab’ key – a closest match of file / directory will be replaced with the characters.
If you want to type ‘cd Desktop’ you can type ‘cd De’ and press ‘Tab’. Your command will be automatically complete.