Linux ls command parameters detailed _linux

Source: Internet
Author: User
Tags parent directory file permissions

-A-all. Enumerates all the files in the directory, including hidden files (. filename). At the beginning of this list. And. In turn, the parent directory and your current directory.
-L-Length (long). Enumerates the details of the contents of the directory, including permissions (schema), owner, group, size, date created, whether the file is a link to other parts of the system, and the link's point.
-F--file type (filename). Add a symbol after each of the enumerated items. These symbols include:/indicate a directory; @ indicates a symbolic link to another file; * indicates an executable file.
-R-Reverse (reverse). Enumerates the contents of a directory from behind.
-R-Recursive (recursive). This option recursively enumerates the contents of all directories (under the current directory).
-S--size. Sorted by file size.

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 hidden files with a. Beginning
-A with-a, but not listed. (represents the current directory) and ".." (Represents the parent directory of the current directory).
-c  with-lt: sorting according to CTime and displaying CTime (file state last changed) cooperate with-L: Show CTime but sort by name otherwise: Sort by CTime
-C list items from top to bottom in each column
–color[=whe N] Controls whether color-resolved files are used. When can be ' never ', ' always ' or ' auto ' one of them
-d,–directory displays the directory as a file, not the file under it.
-d,–dired produces results that are used by the dired mode for Emacs
-F does not sort the output files, the-au option takes effect, the-LST option expires
-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 the file size in an Easy-to-understand format (for example, 1K 234M 2G)
–si is similar to-H, but the file size is 1000 of the second party instead of the 1024
-h,–dereference-comma Nd-line uses the symbolic link in the command column to indicate the true destination
–indicator-style= method to specify a symbol < method after each project name >: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 match the shell Universal Character < style >,
-K, –block-size=1k, which represents the size of the file in K-byte form.
-L Details the permissions, owner, file size, and so on of the file in addition to the file name.
-l,–dereference Displays the object indicated by the symbolic link instead of the symbolic link itself when displaying the file information for the symbolic link
-m all items are comma delimited and fill the entire line width
-O-like-l to display details of the file except group information.   
-r,–reverse in reverse order
-r,–recursive list all subdirectory layers

-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:

Copy Code code 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:

Copy Code code 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:

Copy Code code 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

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.