The full name of the list means that when we learn something, we have to know what it is, and when you know what it is, your mind will think of a lot of things to learn quickly.
1. Ls-a lists all documents under the document, including the following "." The beginning of the hidden file (Linux under the file hidden file is a. opening, if present. Represents the existence of a parent directory.
2. Ls-l lists the details of the file, such as the creator, the time of creation, the read-write permission list for the file, and so on.
3. Ls-f at the end of each file, add a character that describes the file's type. "@" denotes a symbolic link, a "|" Represents a FIFOs, "/" indicates a directory, "=" represents a socket.
4. Ls-s prints out the size of the file after each file. Size (sizes)
5. Ls-t sorting time for files (time)
6. ls-a list except "." and ".." Outside of the file.
7. Ls-r lists all the subdirectories in the directory, equivalent to the "recursive" implementation of our programming
8. Ls-l lists the name of the link for the file. Link (link)
9. Ls-s is sorted by file size
These are some of the use of the LS command, of course, there are many not listed, we can man. Help to learn English
LS can be combined with the pipe character "|" For a complex operation. For example: LS | Less is used to implement the paging of the file list, ls
Calculates the number of files in the current directory
LS-|*|grep "^-" | WC-|
Finally, some files in Linux under the meaning of the color
Green----> represent executable file, (green represents the meaning of the pass) hehe
Red----> representing compressed files
Dark blue----> representative directory
Light blue-----> representative Link file
Grey----> on behalf of some other documents
The LS command is the most commonly used command under Linux. ls command is the abbreviation of List save LS used to print out the list of the current directory if LS specifies a different directory then the list of files and folders in the specified directory is displayed. The LS command allows you to view not only the files contained in the Linux folder but also the file permissions (including directories, folders, file permissions) view directory information, and so on. The LS command is used a lot in everyday Linux operations!
1. Command format:
ls [options] [directory name]
2. Command function:
Lists all subdirectories and files in the destination directory.
3. Common parameters:
-a,–all lists all the files in the directory, including the. Implied file at the beginning
-A with-a, but does not list "." (represents the current directory) and ".." (Represents the parent directory of the current directory).
-C with-lt: According to CTime sorting and display CTime (file state last changed time) with-L: Show CTime but sort by name otherwise: Sort by ctime
-c Each column lists items from top to bottom
–color[=when] Controls whether color-resolved files are used. When it can be ' never ', ' always ' or ' auto ' one of them
-d,–directory Displays the directory as a file, rather than displaying the file under it.
-d,–dired produces results that are used in dired mode for Emacs
-F does not sort the output file, the-au option is in effect, and the-LST option is invalid
-G is similar to-l but does not list owners
-g,–no-group does not list any information about the group
-h,–human-readable the file size in an Easy-to-understand format (for example, 1K 234M 2G)
–si is similar to-H, but the file size takes 1000 of the second party instead of 1024
-h,–dereference-command-line Use the symbolic link in the command column to indicate the true destination
–indicator-style= specifies >:none (default) for each project name, classify (-f), File-type (-P)
-i,–inode Prints the inode number of each file
-i,–ignore= style does not print any items that conform to Shell Universal characters < style >
-K is –block-size=1k, representing the size of the file in K-byte form.
-l details the permissions, owner, file size, and so on for the file, in addition to the filename.
-l,–dereference displays the object indicated by the symbolic link rather than the symbolic link itself when displaying the file information for the symbolic link
-m all items are separated by commas and fill the entire line of line width
-O, similar to-l, displays details of the file except for group information.
-r,–reverse in reverse order
-r,–recursive Lists all subdirectory layers at the same time
-s,–size lists the size of all files in block size
-s sort by file size
–sort=word The following are the optional WORD and the appropriate options they represent:
Extension-x status-c
None-u time-t
Size-s Atime-u
Time-t Access-u
Version-v Use-u
-T to sort by file modification time
-U match-LT: Show access time and sort by access time
With-L: Show access time but sort by name
Otherwise: Sort by access time
-U does not sort; Lists items according to the original order of the file system
-V sorting based on version
-w,–width=cols to specify screen width without using current values
-X list items line by row instead of column
-x Sort by extension
-1 lists only one file per line
–HELP Display this help information and leave
–version display version information and leave
4. Common examples:
Example one: List details of all files and directories under the/home/peidachang folder
Command: Ls-l-r/home/peidachang
Pay attention to the format of the command when using the LS command: At the command prompt, the first is the command keyword, followed by the command arguments, preceded by a dash "-", all the command arguments have a specific effect, and you can select one or more parameters, depending on your needs, After the command parameter is the action object for the command. In the above command "Ls-l-r/home/peidachang", "LS" is the command keyword, "-l-r" is the parameter, "/home/peidachang" is the action object of the command. In this command, two parameters are used, "L" and "R", and of course, you can put them together as follows:
Command: Ls-lr/home/peidachang
This form is exactly the same as the result of the command form above. In addition, if the command's action object is in the current directory, you can manipulate the action object directly, and if you do not need to give the full path to the action object if you are not in the current directory, for example, in the example above, my current folder is the Peidachang folder. I want to operate the Peidachang file under the home folder, I can input LS-LR Peidachang directly, or I can use Ls-lr/home/peidachang.
Example two: Lists the details of all directories in the current directory that start with "T", you can use the following command:
Command: Ls-l t*
You can view information for all files in the current directory with the filename beginning with "T". In fact, in the command format, the contents of square brackets can be omitted, for the command LS, if the command parameters and Operation objects are omitted, directly enter "LS", will be listed in the current working directory of the contents of the list.
Example three: List only subdirectories under Files
Command: ls-f/opt/soft |grep/$
List the subdirectories below the/opt/soft file
Output:
The code is as follows:
[Root@localhost opt]# ls-f/opt/soft |grep/$
jdk1.6.0_16/
Subversion-1.6.1/
tomcat6.0.32/
Command: Ls-l/opt/soft | grep "^d"
List the details of the subdirectories below the/opt/soft file
Output:
The code is as follows:
[root@localhost opt]# ls-l/opt/soft | grep "^d"
Drwxr-xr-x root root 4096 09-17 18:17 jdk1.6.0_16
Drwxr-xr-x 1016 1016 4096 10-11 03:25 subversion-1.6.1
Drwxr-xr-x 9 root root 4096 2011-11-01 tomcat6.0.32
Example four: Lists all files under the current working directory with the name S, and the newer the rows, the following commands can be used:
Command: Ls-ltr s*
Output:
[Root@localhost opt]# ls-ltr s*
Src:
Total 0
Script
Total 0
Soft
Total 350644
Drwxr-xr-x 9 root root 4096 2011-11-01 tomcat6.0.32
-rwxr-xr-x 1 root root 81871260 09-17 18:15 jdk-6u16-linux-x64.bin
Drwxr-xr-x root root 4096 09-17 18:17 jdk1.6.0_16
-rw-r--r--1 root root 205831281 09-17 18:33 apache-tomcat-6.0.32.tar.gz
-rw-r--r--1 root root 5457684 09-21 00:23 tomcat6.0.32.tar.gz
-rw-r--r--1 root root 4726179 10-10 11:08 subversion-deps-1.6.1.tar.gz
-rw-r--r--1 root root 7501026 10-10 11:08 subversion-1.6.1.tar.gz
Drwxr-xr-x 1016 1016 4096 10-11 03:25 subversion-1.6.1
List all the files and directories under the current working directory; add "/" to the name and "*" after the name.
Command: LS-AF
Output:
[Root@localhost opt]# Ls-af
log/script/soft/src/svndata/web/
Example Six: Calculates the number of files and directories in the current directory
Command:
Ls-l * |grep "^-" |wc-l number of---files
Ls-l * |grep "^d" |wc-l---directory number
Example seven: Lists the absolute path of a file in LS
Command: LS | Sed "s:^: ' pwd '/:"
Output:
[Root@localhost opt]# ls | Sed "s:^: ' pwd '/:"
/opt/log
/opt/script
/opt/soft
/opt/src
/opt/svndata
/opt/web
Example nine: Lists the absolute path of all files (including hidden files) in the current directory and does not recursively
Command: Find $PWD-maxdepth 1 | Xargs Ls-ld
Output:
The code is as follows:
[Root@localhost opt]# find $PWD-maxdepth 1 | Xargs Ls-ld
Drwxr-xr-x 8 root root 4096 10-11 03:43/opt
Drwxr-xr-x 2 root root 4096 2012-03-08/opt/log
Drwxr-xr-x 2 root root 4096 2012-03-08/opt/script
Drwxr-xr-x 5 root root 4096 10-11 03:21/opt/soft
Drwxr-xr-x 2 root root 4096 2012-03-08/opt/src
Drwxr-xr-x 4 root root 4096 10-11 05:22/opt/svndata
Drwxr-xr-x 4 root root 4096 10-09 00:45/opt/web
Example Ten: Recursively lists the absolute path of all files (including hidden files) in the current directory
Command: Find $PWD | Xargs Ls-ld
Example 11: Specify the file time output format
Command:
LS-TL--time-style=full-iso
Output:
[Root@localhost soft]# Ls-tl--time-style=full-iso
Total 350644
Drwxr-xr-x 1016 1016 4096 2012-10-11 03:25:58.000000000 +0800 subversion-1.6.1
Ls-ctl--time-style=long-iso
Output:
[Root@localhost soft]# Ls-ctl--time-style=long-iso
Total 350644
Drwxr-xr-x 1016 1016 4096 2012-10-11 03:25 subversion-1.6.1
Extended:
1. Display a list of color catalogs
Open/ETC/BASHRC and add the following line:
Alias ls= "LS--color"
The next time you start bash, you can display a colorful list of directories as you would in Slackware, where the meaning of the color is as follows:
1. Blue--> Catalogue
2. Green--> executable file
3. Red--> Compressed file
4. Light blue--> link file
5. Grey--> Other documents