Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the main purpose of ls command in Linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what the ls command in Linux is mainly used to do. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

The Linux common command ls command is used to display the list of targets, and it is a highly used command in Linux. The output of the ls command can be highlighted in color to partition different types of files.

Ls displays a list of directory contents

Supplement the syntax ls [option] [file name.] [- 1abcdfgiklmnopqrstuxABCDFGLNQRSUX] [- w cols] [- T cols] [- I pattern] [--full-time] [--format= {long,verbose,commas,across,vertical,single-col-umn}] [--sort= {none,time,size,extension}] [--time= {atime,access,use,ctime,status}] [--color [= {none,auto] Always}]] [--help] [--version] [- -] option-C # multi-column output Sort vertically. -F # each directory name with a "/" suffix, each FIFO name with a "|" suffix, and each runnable name with a "*" suffix. -R # recursively lists the subdirectories encountered. -a # lists all files, including "." The implied file at the beginning. -c # uses "state change time" instead of "file modification time" to sort (when using the "- t" option) or list (when using the "- l" option). -d # lists directory names like other files, not their contents. -I # output the file series number (that is, I node number: i-node number) before exporting the file. -l lists (in single column format) file mode # (file mode), number of links to the file, owner name, group name, file size (in bytes), time information, and file name. # by default, the time information shows the last modified time; the other two types of time information can be displayed with the options "- c" and "- u". For device files, # the area where the file size was previously displayed usually shows the primary and secondary signals (majorand minor device numbers). -Q # outputs the non-print characters in the file name as a question mark. (this is the default for output to the terminal. )-r # in reverse order. -t # sort by time information. -u # uses the most recent access time instead of the last modified time to sort (when using the "- t" option) or list (when using the "- l" option). -1 # single column output. -1,-- format=single-column # outputs a file on one line (single column output). If the standard output is not to the terminal, this option is the default. -a,-- all # lists all files in the directory, including "." The beginning of the file. -b,-- escape # lists the non-printable characters in the file name in the form of a backslash plus a character number (as in C). -c,-- time=ctime,-- time=status # sort by file state change time (ctime in node I) and output # contents in the directory. If the output is in a long format (option "- l"), the file modification time is replaced by the status change of the file. [translation note: the so-called file state change (marked by ctime in section I) includes both changes to the file and changes in file attributes (such as owner, group, number of links, etc.)-d,-directory # lists directory names like other files, rather than their contents. -f # does not sort the contents of the directory; it is listed in the order in which they are stored on disk. Activate the "- a" option at the same time, and disable "- l", # "--color" or "- s" if they exist before "- f". -g # ignored for UNIX compatibility. -I,-- inode # prints the I node number (also known as the file serial number and index number: file serial number and index num- # ber) to the left of each file. The I node number is unique in each particular file system. -k,-- kilobytes # if the file size is listed, it is in kilobytes of KB. -l,-- format=long,-- format=verbose # in addition to each file name, add the display of file type, permissions, number of hard links, owner name, group name, size (byte #), and time information (if it is not specified is another time, that is, the modification time). For documents that are more than 6 months old or files that exceed the next 1 # hours, the time in the time information will be replaced by the age. # before each directory is listed, there is a line "Total blocks" that shows the disk space occupied by all files under the directory. The default block size is 1024 # bytes; if the environment variable for POSIXLY_CORRECT is set, the default block size is 512 words # sections unless the "- k" option is used. There is no doubt that each hard link is counted in the total number of blocks (and therefore may be repeated), which is undoubtedly a drawback. The permissions listed in # are similar to the specification for symbolic representation (file) mode. But ls # combines multiple bits information in the third character of each set of permissions, as follows: s if the setuid # bit or setgid bit is set, and the corresponding executable bit is also set. S if the setuid bit or setgid # bit is set, but the corresponding executable bit is not set. T if the sticky bit is set and the corresponding executable bit is also set. T # if the sticky bit is set but the corresponding executable bit is not set. X # if only the executable bit is set instead of the above four cases. -other cases (that is, the executable bit is not set). -m,-- format=commas # lists files horizontally, with as many lines as possible, separated by commas and a space. -n,-- numeric-uid-gid # lists digitized UID and GID instead of user and group names. -o # lists the contents of the directory in a long format, but does not display group information. Is tantamount to using the "--format=long-- no-group #" option. This option is provided for compatibility with other versions of ls. -p # append a character to each file name to indicate the type of file. Similar to the "- F" option but does not mark the executable file. -Q,-- hide-control-chars # replaces non-printed characters in the file name with a question mark. This is the default option. -r,-- reverse # sorts the contents of the directory in reverse order. -s,-- size # outputs the size of the file, in 1024-byte blocks, to the left of each file name. If you set the environment variable for POSIXLY_CORRECT #, unless you use the "- k" option, the block size is 512 bytes. -t,-- sort=time # is sorted by the last modification time of the file (mtime in node I) rather than by file name dictionary, and the new file comes first. -u,-- time=atime,-- time=access,-- time=use # is similar to the option "- t", but the file modification time is replaced by the last file access time (atime in node I). If listed in a long format, the time printed is the most recent access time. -w,-- width cols # assumes that the screen width is a cols column (cols is replaced by an actual number). If this option is not used, the default value is obtained from these #: if it is possible to first try to take it from the terminal driver, otherwise try to take it from the environment variable COLUMNS (if set #), then take 80. -x,-- format=across,-- format=horizontal # multi-column output, horizontal sort. -A,-- almost-all # shows the division of "." And ".." All the files outside. -B,-- ignore-backups # does not output backup files ending with "~" unless they are already given on the command line. -C,-- format=vertical # multi-column output, vertical sort. This is the default when the standard output is a terminal. When using the command names dir and d, it is always the default. -D,-- dired # when output in a long format ("- l" option), after the main output, an additional line is printed: / / DIRED// BEG1 END1 BEG2 # END2. # BEGn and ENDn are unsigned integers, recording the position of the start and end of each file name in the output (# byte offset). This makes it easy for Emacs to find file names, even if they contain non-positive # constant characters such as spaces or line breaks. # # if the directory is listed recursively ("- R" option), each subdirectory is followed by a similar line: # / / SUBDIRED// BEG1 END1. [translation note: I tested TurboLinux4.0 and RedHat6.1 and found that they are both in "# / / DIRED// BEG1..." "then list" / / SUBDIRED// BEG1... ", that is, there is only one # rather than after each subdirectory. And "/ / SUBDIRED// BEG1..." lists the offsets of each subdirectory name. ]-F,-- classify,-- file-type # append a character to each file name to indicate the type of file. "*" represents a normal executable file; "/" represents a directory; "# @" indicates a symbolic link; "|" indicates a socket (sockets); nothing indicates a normal file. -G,-- no-group # does not display group information when listing directories in a long format. -I,-- ignorepattern # do not list files that match the shell filename match (pattern, not the general # expression) unless given on the command line. In shell, the file name is "." The beginning does not match the wildcard at the beginning of the file name match (pattern) #. -L,-- dereference # lists information about the file that the symbolic link points to, not the symbolic link itself. -N,-- literal # do not enclose the file name in quotation marks. -Q,-- quote-name # enclose the file name in double quotation marks, and the non-print characters are represented in C language. -R,-- recursive # recursively lists the contents of all directories. -S,-- sort=size # sorts directory contents by file size rather than dictionary order, with large files first. -T,-- tabsize cols # assumes that each tab width is cols. The default is 8. For efficiency, ls may use tabs in its output. If cols is 0, tabs are not used. -U,-- sort=none # does not sort directory contents; they are listed in the order in which they are stored on disk. (the difference between option "- U" and "- f" is that the former does not start or disables related options. This is especially useful when listing large directories, because unsorted # can be significantly faster. -X,-- sort=extension # by file extension (by the last "." The lexicographic sort of the following characters. List first without an extension. -- color [= when] # specifies whether to use color to distinguish file categories. The environment variable LS_COLORS specifies the color to use. How to set this variable is shown in dir- # colors (1). When can be omitted, or one of the following: none # does not use color, which is the default. # auto is used only when the standard output is a terminal. Always always uses colors. Specifying-- color and omitting when is equivalent to #-- color=always. -- full-time # lists the full time instead of using standard abbreviations. The format is the same as the default format of date (1); this format # cannot be changed, but you can use cut (1) to take out the date string and send the result to the command "date-d". The time of # output, including seconds, is very useful. (the time information of the Unix file system to store files is accurate to seconds, # so this option has given all the information known to the system. For example, this option helps when you have a Makefile file # that does not generate the file properly. Parameter directory: specify the directory where you want to display the list, or it can be a specific file.

Example $ls # list only current directory visible files $ls-l # list current directory visible file details $ls-hl # list details and display file size in readable size $ls-al # list details of all files (including hidden) $ls-human-readable-size-1-S-classify # sort by file size $du- Sh * | sort-h # displays a list of all files in the current directory, including shadow files, sorted by file size (ibid.)

[root@localhost] # ls-a. Anaconda-ks.cfg .bash _ logout .bashrc install.log .mysql _ history satools .tcshrc .vimrc.. .bash _ history .bash _ profile .cshrc install.log.syslog .rnd .ssh .viminfo output long format list

[root@localhost ~] # ls-1 anaconda-ks.cfg install.log install.log.syslog satools displays the inode information of the file

Index node (index inode referred to as "inode") is a special concept in Linux. Two texts with the same index node number are essentially the same file (except for different file names).

[root@localhost ~] # ls-I-l anaconda-ks.cfg install.log 2345481-rw- 1 root root 859 Jun 11 22:49 anaconda-ks.cfg 2345474-rw-r--r-- 1 root root 13837 Jun 11 22:49 list of install.log horizontal output files

[root@localhost /] # ls-m bin, boot, data, dev, etc, home, lib, lost+found, media, misc, mnt, opt, proc, root, sbin, selinux, srv, sys, tmp, usr, var modify the last edited file

The most recently modified file is displayed at the top.

[root@localhost /] # ls-t tmp root etc dev lib boot sys proc data home bin sbin usr var lost+found media mnt opt selinux srv misc displays recursive files

[root@localhost ~] # UID and GID of ls-R.:anaconda-ks.cfg install.log install.log.syslog satools./satools:black.txt freemem.sh iptables.sh lnmp.sh mysql php502_check.sh ssh_safe.sh print file

[root@localhost /] # ls-ntotal 254drwxr-xr-x 200 4096 Jun 12 04:03 bindrwxr-xr-x 400 1024 Jun 15 14:45 bootdrwxr-xr-x 600 4096 Jun 12 10:26 datadrwxr-xr-x 1000 3520 Sep 26 15:38 devdrwxr-xr-x 75 4096 Oct 16 04:02 etcdrwxr-xr-x 400 4096 Jun 12 10:26 homedrwxr-xr-x 1400 12288 Jun 16 04:02 libdrwx- 20 0 16384 Jun 11 22:46 lost+founddrwxr-xr-x 20 0 4096 May 11 2011 mediadrwxr-xr-x 20 0 4096 Nov 8 2010 miscdrwxr-xr-x 20 0 4096 May 11 2011 mntdrwxr-xr-x 20 0 4096 May 11 2011 optdr-xr-xr-x 232 0 0 0 Jun 15 11:04 procdrwxr-x--- 40 0 4096 Oct 15 14:43 rootdrwxr-xr-x 20 0 12288 Jun 12 04:03 sbindrwxr-xr-x 20 0 4096 May 11 2011 selinuxdrwxr-xr-x 20 4096 May 11 2011 srvdrwxr-xr-x 11 000 Jun 15 11:04 sysdrwxrwxrwt 300 98304 Oct 16 08:45 tmpdrwxr-xr-x 1300 4096 Jun 11 23:38 usrdrwxr-xr-x 19 4096 Jun 11 23:38 var lists details of files and folders

[root@localhost /] # ls-ltotal 254drwxr-xr-x 2 root root 4096 Jun 12 04:03 bindrwxr-xr-x 4 root root 1024 Jun 15 14:45 bootdrwxr-xr-x 6 root root 4096 Jun 12 10:26 datadrwxr-xr-x 10 root root 3520 Sep 26 15:38 devdrwxr-xr-x 75 root root 4096 Oct 16 04:02 etcdrwxr-xr-x 4 root root 4096 Jun 12 10:26 homedrwxr-xr-x 14 root root 12288 Jun 16 04:02 libdrwx- 2 root root 16384 Jun 11 22:46 lost+founddrwxr-xr-x 2 root root 4096 May 11 2011 mediadrwxr-xr-x 2 root root 4096 Nov 8 2010 miscdrwxr-xr-x 2 root root 4096 May 11 2011 mntdrwxr-xr-x 2 root root 4096 May 11 2011 optdr-xr-xr-x 232 root root 0 Jun 15 11:04 procdrwxr-x--- 4 root root 4096 Oct 15 14:43 rootdrwxr-xr-x 2 root root 12288 Jun 12 04:03 sbindrwxr-xr-x 2 root root 4096 May 11 2011 selinuxdrwxr-xr-x 2 root root 4096 May 11 2011 srvdrwxr-xr-x 11 root root 0 Jun 15 11:04 sysdrwxrwxrwt 3 root root 98304 Oct 16 08:48 tmpdrwxr-xr-x 13 root root 4096 Jun 11 23:38 usrdrwxr-xr-x 19 root root 4096 Jun 11 23:38 var lists readable files and folder details

[root@localhost /] # ls-lhtotal 254Kdrwxr-xr-x 2 root root 4.0K Jun 12 04:03 bindrwxr-xr-x 4 root root 1.0K Jun 15 14:45 bootdrwxr-xr-x 6 root root 4.0K Jun 12 10:26 datadrwxr-xr-x 10 root root 3.5K Sep 26 15:38 devdrwxr-xr-x 75 root root 4.0K Oct 16 04:02 etcdrwxr-xr-x 4 root root 4.0K Jun 12 10:26 homedrwxr-xr-x 14 root root 12K Jun 16 04:02 libdrwx- 2 root root 16K Jun 11 22:46 lost+founddrwxr-xr-x 2 root root 4.0K May 11 2011 mediadrwxr-xr-x 2 root root 4.0K Nov 8 2010 miscdrwxr-xr-x 2 root root 4.0K May 11 2011 mntdrwxr-xr-x 2 root root 4.0K May 11 2011 optdr-xr-xr-x 235 root root 0 Jun 15 11:04 procdrwxr-x--- 4 root root 4.0K Oct 15 14:43 rootdrwxr-xr- X 2 root root 12K Jun 12 04:03 sbindrwxr-xr-x 2 root root 4.0K May 11 2011 selinuxdrwxr-xr-x 2 root root 4.0K May 11 2011 srvdrwxr-xr-x 11 root root 0 Jun 15 11:04 sysdrwxrwxrwt 3 root root 96K Oct 16 08:49 tmpdrwxr-xr-x 13 root root 4.0K Jun 11 23:38 usrdrwxr-xr-x 19 root root 4.0K Jun 11 23:38 var displays folder information

[root@localhost /] # ls-ld / etc/drwxr-xr-x 75 root root 4096 Oct 16 04:02 / etc/ lists files and folders details by time

[root@localhost /] # ls-lttotal 254drwxrwxrwt 3 root root 98304 Oct 16 08:53 tmpdrwxr-xr-x 75 root root 4096 Oct 16 04:02 etcdrwxr-x--- 4 root root 4096 Oct 15 14:43 rootdrwxr-xr-x 10 root root 3520 Sep 26 15:38 devdrwxr-xr-x 14 root root 12288 Jun 16 04:02 libdrwxr-xr-x 4 root root 1024 Jun 15 14:45 bootdrwxr-xr-x 11 root root 0 Jun 15 11:04 sysdr-xr-xr-x 2.232 root root 0 Jun 15 11:04 procdrwxr-xr-x 6 root root 4096 Jun 12 10:26 datadrwxr-xr-x 4 root root 4096 Jun 12 10:26 homedrwxr-xr-x 2 root root 4096 Jun 12 04:03 bindrwxr-xr-x 2 root root 12288 Jun 12 04:03 sbindrwxr-xr-x 13 root root 4096 Jun 11 23:38 usrdrwxr-xr-x 19 root root 4096 Jun 11 23:38 vardrwx- 2 root root 16384 Jun 11 22:46 lost+founddrwxr-xr-x 2 Root root 4096 May 11 2011 mediadrwxr-xr-x 2 root root 4096 May 11 2011 mntdrwxr-xr-x 2 root root 4096 May 11 2011 optdrwxr-xr-x 2 root root 4096 May 11 2011 selinuxdrwxr-xr-x 2 root root 4096 May 11 2011 srvdrwxr-xr-x 2 root root 4096 Nov 8 misc lists files and folders by modification time

[root@localhost /] # ls-ltrtotal 254drwxr-xr-x 2 root root 4096 Nov 8 2010 miscdrwxr-xr-x 2 root root 4096 May 11 2011 srvdrwxr-xr-x 2 root root 4096 May 11 2011 selinuxdrwxr-xr-x 2 root root 4096 May 11 2011 optdrwxr-xr-x 2 root root 4096 May 11 2011 mntdrwxr-xr-x 2 root root 4096 May 11 mediadrwx- 2 root root 16384 Jun 11 22:46 lost+founddrwxr-xr-x 19 root root 4096 Jun 11 23:38 vardrwxr -xr-x 13 root root 4096 Jun 11 23:38 usrdrwxr-xr-x 2 root root 12288 Jun 12 04:03 sbindrwxr-xr-x 2 root root 4096 Jun 12 04:03 bindrwxr-xr-x 4 root root 4096 Jun 12 10:26 homedrwxr-xr-x 6 root root 4096 Jun 12 10:26 datadr-xr-xr-x root root 0 Jun 15 11:04 procdrwxr-xr-x 11 root root 0 Jun 15 11:04 sysdrwxr-xr-x 4 root root 1024 Jun 15 14 45 bootdrwxr-xr-x 14 root root 12288 Jun 16 04:02 libdrwxr-xr-x 10 root root 3520 Sep 26 15:38 devdrwxr-x--- 4 root root 4096 Oct 15 14:43 rootdrwxr-xr-x 75 root root 4096 Oct 16 04:02 etcdrwxrwxrwt 3 root root 98304 Oct 16 08:54 tmp classifies files by special characters

[root@localhost nginx-1.2.1] # ls-Fauto/ CHANGES CHANGES.ru conf/ configure* contrib/ html/ LICENSE Makefile man/ objs/ README src/ lists files and marks color classifications

[root@localhost nginx-1.2.1] # ls-this is the end of color=autoauto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src's article on "what ls commands are mainly used for in Linux". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report