One linux Command every day (1): ls command

Source: Internet
Author: User
Tags sorted by name


One linux Command every day (1): the ls command is the most common command in linux. The ls command is the abbreviation of list. By default, ls is used to print the list of the current directory. If ls specifies other directories, the list of files and folders in the specified directory will be displayed. By using the ls command, you can view not only the files contained in linux folders, but also the file permissions (including the directory, folder, and file permissions. Ls commands are widely used in daily linux operations! 1. Command Format: ls [Option] [directory name] 2. Command function: list all subdirectories and files in the target directory. Www.2cto.com 3. common parameters:-a and-all list all files in the directory, including. the implicit file-A starts with-a, but does not list ". "(indicating the current directory) and" .. "(the parent directory of the current directory ). -C combination-lt: ctime-based sorting and ctime-based display (time when the last file state is changed) combination-l: ctime is displayed, but ctime is sorted by name otherwise: sort by ctime-C list items from top to bottom in each column-color [= WHEN] to control whether to use color resolution files. WHEN can be either 'never ', 'Always', or 'auto'-d.-directory displays the directory like a file instead of the file under it. -D and-dired generate results suitable for the dired mode of Emacs-f does not sort the output files, the-aU option takes effect, and the-lst option is invalid-g is similar to-l, but do not list owner-G,-no-group does not list any information about the group-h, -human-readable: list the file size in an easy-to-understand format (for example, 1 K 234 M 2G).-si is similar to-h, but the file size is equal to the power of 1000 instead of 1024-H, -dereference-command-line: Use the symbolic link in the command column to indicate the real destination-indicator-style = to specify that an indicator is added after each project name <method>: none (default ), classify (-F), file-type (-p)-I,-inode prints the inode number of each file-I, -ignore = the style does not print any project-k that meets the shell universal character <style>, that is,-block-s. Ize = 1 K, which indicates the file size in the form of k bytes. -L in addition to the file name, the File Permission, owner, file size, and other information are listed in detail. -L,-dereference: when the file information of the symbolic link is displayed, the objects indicated by the symbolic link are displayed instead of the information of the symbolic link itself.-m all items are separated by commas, and fill in the whole row width-o similar to-l, display the detailed information of the file except the group information. -R,-reverse in reverse order-R,-recursive lists all sub-directory layers-s at the same time, -size: lists the sizes of all files in block size.-S is sorted by file size.-sort = WORD: The following are optional WORD and the corresponding options they represent: extension-X status-cnone-U time-tsize-S atime-utime-t access-uversion-v use-u-t sort by file modification time-u with-lt: show access time and sort by access time with-l: show access time but sort by name otherwise: sort by access time www.2cto.com-U without sorting; list items in the original order of the file system-v sort items by version-w, -width = COLS: Specify the screen width by yourself without using the current value-x to list items row by row rather than column by column-X to sort by extension-1 to list only one file per line-help to display this help Help information and exit-version display version information and exit 4. example 1: run the following command to list all files and directories in the/home/peidachang Folder: ls-l-R/home/peidachang pay attention to the command format when using the ls command: After the command prompt, the first is the command keyword, followed by the command parameter, there must be a hyphen "-" before the command parameters. All command parameters have specific functions. You can select one or more parameters as needed, the command parameter is followed by the command operation object. In the preceding command "ls-l-R/home/peidachang", "ls" is the command keyword and "-l-R" is the parameter, "/home/peidachang" is the operation object of the command. In this command, two parameters are used: "l" and "R". Of course, you can also put them together for use as follows: command: the results of ls-lR/home/peidachang execution are the same as those of the preceding command. In addition, if the operation object of the command is located in the current directory, you can perform operations on the operation object directly. If the operation object is not in the current directory, you must provide the complete path of the operation object. For example, in the preceding example, my current folder is the peidachang folder. To operate the peidachang file in the home folder, I can directly enter ls-lR peidachang or ls-lR/home/peidachang. Example 2: List the details of all directories starting with "t" in the current directory. Run the following command: ls-l t * allows you to view information about all files whose names start with "t" in the current directory. In fact, in the command format, the content in square brackets can be omitted. For the command ls, if the command parameters and operation objects are omitted, enter "ls" directly ", the contents of the current working directory are listed. Example 3: only list sub-directory commands in a file: ls-F/opt/soft | grep/$ list sub-directory output under the/opt/soft file: [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" lists the detailed output of subdirectories under the/opt/soft file: [root @ localhost opt] # ls-l/opt/soft | grep "^ d" drwxr-xr-x 10 root 4096 09-17 jdk1.6.0 _ 16drwxr-xr-x 16 1016 1016 4096 10-11 0:25 subversion-1.6.1drwxr-xr-x 9 root 4096 2011-11-01 tomctomcat6.0.32 www.2cto.com Example 4: list all files whose names start with "s" in the current working directory. After a new row is added, run the following command: ls-ltr s * output: [root @ localhost opt] # ls-ltr s * src: Total 0 script: Total 0 soft: total 350644drwxr-xr-x 9 root 4096 2011-11-01 atat6.0.32-rwxr-xr-x 1 root 81871260 09-17 jdk-6u16-linux-x64.bindrwxr-xr-x 10 root 4096 09-17 jdk1.6.0 _ 16-rw-r -- r -- 1 root 205831281 09-17 apache-tomcat-6.0.32.tar.gz-rw-r -- r -- 1 root 5457684 09-21 Tomcat 6.0.32.tar.gz-rw-r -- 1 root 4726179 10-10 subversion-deps-1.6.1.tar.gz-rw-r -- r -- 1 root 7501026 10-10 subversion-1.6.1.tar.gzdrwxr-xr-x 16 1016 1016 4096 10-11 subversion-1.6.1 Example 5: list all files and directories under the current working directory. Add "/" after the directory name, and add "*" after the executable file name. Command: ls-AF output: [root @ localhost opt] # ls-AFlog/script/soft/src/svndata/web/Example 6: run the following command to calculate the number of files and directories in the current directory: ls-l * | grep "^-" | wc-l --- number of files ls-l * | grep "^ d" | wc-l --- directory number Example 7: the absolute path command for listing files in ls: ls | sed "s: ^: 'pwd'/:" output: www.2cto.com [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. Do not use the recursive command for the Directory: find $ PWD-maxdepth 1 | xargs ls-ld output: [root @ localhost opt] # find $ PWD-maxdepth 1 | xargs ls-lddrwxr-xr-x 8 root 4096 10-11/optdrwxr-xr-x 2 root 4096 2012-03-08/opt/logdrwxr-xr-x 2 root 4096 2012-03-08/opt/scriptdrwxr-xr-x 5 root 4096 10-11/opt/softdrwxr-xr-x 2 root root 4096/opt/srcdrwxr-xr-x 4 root 4096 10-11/opt/svndatadrwxr-xr-x 4 root 4096 10-09/opt/web example 10: recursively list all files in the current directory (including hidden files) using the absolute path command: find $ PWD | xargs ls-ld www.2cto.com 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 350644drwxr-xr-x 16 1016 1016 4096 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 350644drwxr-xr-x 16 1016 1016 4096 subversion-1.6.1 Extension: www.2cto.com 1. show the color directory list open/etc/bashrc and add the following line: alias ls = "ls -- color" the next time you start bash, you can display the color directory list as in Slackware, the color is as follows: 1. blue --> directory 2. green --> executable file 3. red --> compressed file 4. light blue --> link file 5. gray --> other files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.