The Linux ls command is used to display the contents of the specified working directory (list the files and subdirectories contained in the current working directory), view the permissions of files (including directories, folders, file permissions), view directory information, and so on. It is a very powerful and useful command.

Syntax of the ls command

ls [-alrtAFR] [name...]
Copy the code

2. Parameters of the ls command

The following describes several parameters of the ls command.

-a Displays all files and directories (ls automatically considers file names or directory names starting with "." as hidden files and will not be listed) -l Except file names, -r will display the files in reverse order (originally in alphabetical order) -t will list the files in order of creation time -A and -A, but not "." (current directory) and ".." (Parent directory) -f Appends the names of listed files with a symbol; For example, "*" is added to executable files, and "/" is added to directories. -r If there are files in the directory, the following files are also sequencedCopy the code

C. ls d. ls

1, list all directories under root (\) :

ls /

2, list all files whose names start with B in the current working directory. The newer files are listed later:

ls -lrt b*

3, list all directories and files in shell folder:

ls -lR test/

4. List the absolute path of all files (including hidden files) in the current directory without recursion

find $PWD -maxdepth 1 | xargs ls -ld

If do 1 layer of recursion: find $PWD – maxdepth 2 | xargs ls – ld

5. List all files and directories under the current working directory; Directories followed by “/” and executables followed by “*”

ls -AF

6. List all files (including hidden files) and file information in the current directory

ls -al