ls command – display the file and attribute information in the specified working directory

ls is the abbreviation of the English word list, which means to list the file names and their attributes in the specified directory.

Without parameters, the ls command lists the files and subdirectories in the current working directory.

With options, its syntax is as follows:

 ls [选项] [文件] 

Commonly used options are shown in the table below:

options effect
-a Display all files and directories ( including hidden files starting with "." )
-l List file and directory details using long format
-r Display files in reverse alphabetical order. The default is forward
-t Sort by last modification time
-A Same as -a , but do not list "." ( current directory ) and ".." ( parent directory )
-S Sort by file size
-R List all subdirectories recursively
-d View information about directories, but not subdirectories
-i Output the inode node information of the file
-m List files horizontally, separated by commas
-X sort by file extension
-h Display file size in human readable form
-Z Display the SELinux security context of a file
--color There is a coloring effect in the output information, with this option by default

Example demonstration:

1. The list displays all files in the current directory (but does not include hidden files)

[root@myEuler ~]# ls
anaconda-ks.cfg  data  file1

2. The list displays the reported files (including hidden files) in the current directory

[root@myEuler ~]# ls -a 
.   anaconda-ks.cfg  .bash_logout   .bashrc  data   .lesshst  .viminfo
..  .bash_history    .bash_profile  .cshrc   file1  .tcshrc

Adding a decimal point before the file name is a hidden file

A single dot (.) indicates the current directory

Two decimal points (..) indicate the upper directory, that is, the parent directory.

3. The list displays the detailed attribute information of the specified file

[root@myEuler ~]# ls -l anaconda-ks.cfg 
-rw-------. 1 root root 1055 Feb 19 23:31 anaconda-ks.cfg

4. Display detailed information of the specified directory

[root@myEuler ~]# ls -l /etc/
total 1716
-rw-r--r--.  1 root root        44 Feb 22 23:54 adjtime
-rw-r--r--.  1 root root      1529 Jul 16  2021 aliases
drwxr-xr-x.  2 root root      4096 Feb 19 23:28 alternatives
-rw-r--r--.  1 root root       541 Dec 27 21:02 anacrontab
……此处省略部分输出信息……

5. Display detailed information of all files in the current directory, including their inode numbers

[root@myEuler ~]# ls -li
total 8
786439 -rw-------. 1 root root 1055 Feb 19 23:31 anaconda-ks.cfg
786440 drwxr-xr-x. 2 root root 4096 Feb 26 23:51 data
786444 -rw-r--r--. 1 root root    0 Feb 26 23:51 file1

6. Display all files in the specified directory, requiring sorting by file size

[root@myEuler ~]# ls -hlS /etc
total 1.7M
-rw-r--r--.  1 root root    686K Jul 16  2021 services
-rw-r--r--.  1 root root     69K Apr 27  2021 mime.types
-rw-r--r--.  1 root root     48K Feb 19 23:36 ld.so.cache
-rw-r--r--.  1 root dnsmasq  28K Dec 27 20:49 dnsmasq.conf
-rw-r--r--.  1 root root    8.6K Feb 19 23:36 login.defs

……此处省略部分输出信息……

7. View the SELinux security context of the specified file/directory

[root@myEuler ~]# ls -Zld /etc
drwxr-xr-x. 88 root root system_u:object_r:etc_t:s0 4096  3月  6 17:09 /etc

Guess you like

Origin blog.csdn.net/u013007181/article/details/129370978