Linux ls command: View directory file

By learning cd and pwd command, readers have been able to believe in the huge Linux file system, free to wander and to determine their location up. This section continues to learn, how do you know what a directory contains files or subdirectories.

 

ls command, list of abbreviations, is the most common directory operations command, whose main function is to display the contents of the current directory. The basic format of the command is:

[Root @ localhost ~] # ls [options] directory name

Table 1 lists the ls command common options as well as their respective functions.

Table 1 ls command commonly used options and functions
Options Features
-a Show all files, including hidden files (beginning with. Files) also listed out together, which is one of the most commonly used options.
-A Show all files, hidden files together, but does not include. .. and two directories.
-d Directory lists only itself, instead of listing the data files in the directory.
-f ls default file name sorting, using the -f option listed directly results without sorting.
-F After the file or directory name with the file type indicator, for example, * on behalf of executable files, / directory behalf, on behalf of socket = file | on behalf of FIFO file.
-h Display file or directory sizes, such as 1KB, 234MB, 2GB and so on to human-readable way.
-i Displays the inode information.
-l Using the long list file and directory information.
-n UID and GID were replaced with the file name and user group name displayed.
-r The inverted output sort results, for example, if the original file name from small to big, from big to small, compared with the reverse.
-R Along with the contents of the subdirectory listed, equal to all the files in the directory are displayed.
-S File size capacity to sort, rather than the file name sorting.
-t In time sequence, rather than the file name sorting.
–color=never
–color=always
–color=auto
It never said they did not give color display based on document characteristics.
always display color, ls is the default used.
auto indicates that the system itself depending on the configuration to determine whether to give color.
–full-time In full time mode (containing year, month, day, hour, minute) output
–time={atime,ctime} Output access time or change the permissions attributes of time (ctime), rather than the content change time.

Note that when the ls command without any options, the default will only show the name of the non-hidden files and to sort the file name, file name and it will give color (blue catalog, white display general files) Depending on the type of file . In addition, if you want to use the ls command to display more content, you need to use the appropriate option in Table 1.

【Example 1】

[root@www ~]# ls -al ~
total 156
drwxr-x—  4 root root  4096 Sep 24 00:07 .
drwxr-xr-x 23 root root  4096 Sep 22 12:09 ..
-rw——-  1 root root  1474 Sep  4 18:27 anaconda-ks.cfg
-rw——-  1 root root   955 Sep 24 00:08 .bash_history
-rw-r–r–  1 root root    24 Jan  6  2007 .bash_logout
-rw-r–r–  1 root root   191 Jan  6  2007 .bash_profile
-rw-r–r–  1 root root   176 Jan  6  2007 .bashrc
drwx——  3 root root  4096 Sep  5 10:37 .gconf
-rw-r–r–  1 root root 42304 Sep  4 18:26 install.log
-rw-r–r–  1 root root  5661 Sep  4 18:25 install.log.syslog

By using -a, you will see to order several files at the beginning of the file and directory (.), (..) ,. gconf etc., which are hidden directories and files. Among them, the directory file name is displayed in blue, the general file is displayed in white.

Note, Linux systems, the file is not a hidden file in order to hide from other users to find, but to tell the user which files are important system files, if not necessary, do not move! So, whether Linux or Windows can very easily view hidden files in Windows but the vast majority of viruses and Trojans will transform itself into a hidden file, giving users the illusion that in order to prevent hidden files users found.

Not only that, there's also the ls command using the -l option, so it shows the details of the file, meaning that 7 this option displays are:

  1. The first column: specifies the file permissions for different users possess, will explain the meaning of specific rights in the subsequent sections.
  2. Second row: the reference count, reference count represents the number of file hard links to the file, directory and reference count represents the number of the directory has a subdirectory.
  3. The third column: the owner, that is, the files belong to which users. The default is the owner of the establishment of user files.
  4. The fourth column: group ownership, belongs to the default group is to establish an effective set of files the user, under normal circumstances is to set up a user's group.
  5. Fifth column: size, in bytes default.
  6. The sixth column: file modification time, file modification time status data or file modification time will change this time, note that this time is not the time to create the file.
  7. Seventh column: filename or directory name.

[Example 2]
If we want to see the details of a directory, for example:

[root @ localhost ~] # ls -l / root /
Total amount 44 is
-rw ---.. 1. 1 1207 the root the root-dated the ks.cfg Anaconda 18:18 14
-rw the root .1 the root-RR-24772 January 14, the install.log 18:17
-rw the root the root-RR-7690. 1 .1 dated 14 18:17 install.log.syslog

This command displays the contents of the directory, and detailed information on the directory itself will not be displayed. If you want to display information about the directory itself, you must join the "-d" option.

[root@localhost ~]# ls -ld /root/
dr-xr-x—.2 root root 4096 1 月 20 12:30 /root/

[Example 3]
"ls-l" shows the file size in bytes, but we are more accustomed to using kilobytes KB display, display megabytes MB, and the "-h" option is displayed in units of people's habits file size, for example:

[root @ localhost ~] # ls -lh
total amount of 44K
-rw --- the root the root. 1. 1 1.2K Anaconda-dated the ks.cfg 18:18 14.
-rw the root the root-RR-.1 January 14 25K 18: the install.log. 17
-rw the root the root-RR-7.6K. 1 .1 dated 14 18:17 install.log.syslog

Published 33 original articles · won praise 0 · Views 396

Guess you like

Origin blog.csdn.net/linuxanz/article/details/103474969
Recommended