In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the usage of ls command in Linux". In daily operation, I believe that many people have doubts about the usage of ls command in Linux. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the usage of ls command in Linux". Next, please follow the editor to study!
1. Ls-a lists all the files under the file, including "." The beginning of the hidden file (linux file hidden file is with. At the beginning, if it exists.. Represents the existence of a parent directory).
2. Ls-l lists the details of the file, such as creator, creation time, list of read and write permissions for the file, and so on.
3. Ls-F adds a character at the end of each file to indicate the type of file. "@" indicates symbolic link, "|" indicates FIFOS, "/" indicates directory, and "=" indicates socket.
4. Ls-s prints the file size at the end of each file. Size (size)
5. Ls-t sorts files by time Time (time)
6. Ls-A lists except "." And ".." Other than documents.
7. Ls-R lists the files of all the subdirectories under the directory, which is equivalent to the "recursive" implementation in our programming.
8. Ls-L lists the link name of the file. Link (link)
9. Ls-S sorts by file size
The above are some of the uses of the ls command, of course, there are many not listed, you can man. Help to learn English
Ls can be combined with the pipe character "|" to perform a complex operation. For example: ls | less is used to paginate the file list, ls
Calculate the number of files in the current directory
Ls-| * | grep "^ -" | wc-|
Finally, let's talk about the meaning of some file colors under linux.
Green-> represents the executable document, (green represents the meaning of the pass) hehe
Red-> represents a compressed file
Dark blue-> represents the catalogue
Light blue-> represents a linked file
Gray-> represents some other documents.
The ls command is the most commonly used command under linux. The ls command is the abbreviation of list by default ls is used to print out the list of the current directory if ls specifies another directory then it will display a list of files and folders in the specified directory. Through the ls command, you can view not only the file contained in the linux folder, but also the file permissions (including directories, folders, file permissions) to view directory information, and so on. The ls command is often used in daily linux operations!
1. Command format:
Ls [option] [directory name]
two。 Command function:
Lists all subdirectories and files in the target directory.
3. Common parameters:
-a,-all lists all the files in the directory, including. The implied file at the beginning
-An is the same as-a, but not listed "." (represents the current directory) and ".." Represents the parent directory of the current directory.
-c fit-lt: sort by ctime and display ctime (time when the file status last changed) match-l: show ctime but sort by name otherwise: sort by ctime
-C list items from top to bottom in each column
-color [= WHEN] controls whether color resolution files are used. WHEN can be one of 'never',' always', or 'auto'
-d,-directory displays the directory like a file, not the file under it.
-D,-dired produces results suitable for the use of dired mode for Emacs
-f does not sort the output files,-aU option takes effect,-lst option is invalid
-g is similar to-l, but does not list the owner
-G,-no-group does not list any information about the group
-h,-human-readable lists file sizes in an easy-to-understand format (for example, 1K 234m 2G)
-si is similar to-h, but the file size is to the power of 1000 instead of 1024
-H,-dereference-command-line indicates the real destination using symbolic links on the command line
-indicator-style= mode specifies that each project name is followed by an indicator: none (default), 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
-k, or-block-size=1K, represents the file size in k bytes.
-l in addition to the file name, the file permissions, owner, file size and other information are listed in detail.
-L,-dereference when displaying the file information of the symbolic link, displays the object indicated by the symbolic link rather than the information of the symbolic link itself
-m all items are separated by commas and fill the entire line width
-o similar to-l, displays the details of the file except for the group information.
-r,-reverse in reverse order
-R,-recursive lists all subdirectory layers simultaneously
-s,-size lists the size of all files in block size
-S sorts by file size
-sort=WORD the following are the available WORD and the corresponding options they represent:
Extension-X status-c
None-U time-t
Size-S atime-u
Time-t access-u
Version-v use-u
-t sort by file modification time
-u match-lt: displays the access time and sorts by access time
Match-l: display access time but sort by name
Otherwise: sort by access time
-U does not sort; items are listed in the original order of the file system
-v sort by version
-w,-width=COLS specifies the screen width instead of the current value
-x list items line by line instead of column by column
-X sorts by extension
-1 only one file is listed per line
-help displays this help and leaves
-version displays version information and leaves
4. Common examples:
Example 1: list the details of all files and directories under the / home/peidachang folder
Command: ls-l-R / home/peidachang
In the use of ls command should pay attention to the format of the command: after the command prompt, the first is the command keyword, followed by the command parameters, before the command parameters to have a short dash "-", all the command parameters have a specific role, you can choose one or more parameters, after the command parameters is the command operation object. In the above command "ls-l-R / home/peidachang", "ls" is the command keyword, "- l-R" is the parameter, and "/ home/peidachang" is the operator of the command. In this command, two parameters are used, "l" and "R". Of course, you can also use them together, as shown below:
Command: ls-lR / home/peidachang
The result of this form is exactly the same as that of the above command form. In addition, if the operating object of the command is located in the current directory, you can operate on the operating object directly; if it is not in the current directory, you need to give the full path to the operating object, for example, in the above example, my current folder is the peidachang folder, and I want to operate on the peidachang file under the home folder. I can type ls-lR peidachang directly or use ls-lR / home/peidachang.
Example 2: to list the details of all directories starting with "t" in the current directory, you can use the following command:
Command: ls-l t *
You can view information about all files in the current directory whose file names begin with "t". In fact, in the command format, the contents in square brackets can be omitted. For the command ls, if you omit the command parameters and operands and type "ls" directly, a list of the contents of the current working directory will be listed.
Example 3: list only the subdirectories under the file
Command: ls-F / opt/soft | grep / $
List the subdirectories under 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 under the / opt/soft file
Output:
The code is as follows:
[root@localhost opt] # ls-l / opt/soft | grep "^ d"
Drwxr-xr-x 10 root root 4096 09-17 18:17 jdk1.6.0_16
Drwxr-xr-x 16 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 4: list all files whose names begin with s in the current working directory. The newer the files, you can use the following command:
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 10 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 16 1016 1016 4096 10-11 03:25 subversion-1.6.1
Example 5: list all files and directories under the current working directory; add "/" to the name of the directory, and "*" after the name of the executable file.
Command: ls-AF
Output:
[root@localhost opt] # ls-AF
Log/ script/ soft/ src/ svndata/ web/
Example 6: calculate 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-number of directories
Example 7: list the absolute path of the 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 9: list the absolute paths of all files (including hidden files) in the current directory without recursion to the directory
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 10: recursively lists the absolute paths 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 16 1016 1016 4096 2012-10-11 03Partition 25purl 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 16 1016 1016 4096 2012-10-11 03:25 subversion-1.6.1
At this point, the study of "the use of ls commands in Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.