The most commonly used command in Linux - ls usage

 

ls is a command that everyone will use when they come into contact with the Linux system. Today, I will bring you back to the basic usage of ls

ls basic usage

effect

The role of the ls command is to list the contents of the directory

usage

ls [options] [filename...]

View multiple files or folders

ls  /dev/ /boot

 

view file details

ls -l If no parameters are added, the default refers to viewing the contents of the current directory

ls -l

 

-rw-r–r–

file type and permissions

1

number of hard links

root root

Belonging user and user group

0

size

July 7 23:17

Last Modified

myfile.txt

file name

View hidden files or hidden folders

Everyone knows that under Windows, hidden files and hidden folders are set through the system, but under Linux, hiding files is relatively simple, as long as the file or folder is named, start with a dot, as shown in the example below The ".abc" in the default ls is not displayed

ls -a

 

After ls -a, you can see three more files

.

current directory (in every folder)

..

parent directory (in each folder)

.abc

Hidden files set by yourself

Because there are two folders. and .. in all files, if you want to ignore them when you want to view them, you can use the ls -A command to ignore these two folders

ls -A

 

Sort the files

Default sort display

By default, when ls views files, they are sorted by file name

 

Display commands in reverse order

ls -r

 

From the comparison of the results of the above two executions, it can be seen that the difference between the file sorting of ls -r and the execution result of ls has changed according to the display order of the file names

Show in chronological order

Sort by most recently updated files first

ls -t

 

Show in reverse chronological order

Sort in reverse order by most recently updated file

ls -rt

 

sort by file size

Sort by big files first

ls -S

 

Reverse sort by file size

small files first

ls -Sr

 

Recursively list the contents of subdirectories

Sometimes you need to view the contents of all files, at this time the following command comes in handy, it will display the contents of all folders

ls -R

 

friendly display file size

It is usually used together with -l, so that the displayed file size is more readable, and the difference between the two can be seen in the figure below

ls -lh

 

The above are some common usages of ls in daily life, which can meet the basic needs in daily use. If you want to know more, you can execute man ls, which contains more parameters.

If the article is helpful to you, you may wish to follow the WeChat public account TouTalk, support, thank you.

Guess you like

Origin blog.csdn.net/dtwangquan/article/details/107240417