ls command (listing all subdirectories and files)

Source: Internet
Author: User

function: LS is shorthand for the English word list, and its function is to list the contents of the catalog. This is one of the most commonly used commands for users, because users need to view the contents of a directory from time to times. This command is similar to the dir command under DOS.
Syntax: LS [options] [directory or file]
For each directory, the command lists all subdirectories and files in it. For each file, LS outputs its filename and other information required. By default, output entries are sorted in alphabetical order. When no directory name or filename is given, the information for the current directory is displayed.
Parameters:
-a displays all subdirectories and files in the specified directory, including hidden files.
-A displays all subdirectories and files in the specified directory, including hidden files. But do not list "." and ".."
-B Displays the octal escape character for the non displayed characters in the filename.
-C is sorted by file modification time.
-C is divided into multiple columns to display items.
-D If the parameter is a directory, display only its name without displaying the files below it. Often used with the L option to get detailed information about the directory.
-F not sorted. This option will invalidate the LTS option and make the AU option valid.
-F Mark "/" After the directory name, "*" After the executable file, Mark "@" after the symbol link, mark "|" after the pipe (or FIFO), and Mark "=" after the socket file.
-I displays the I node number of the file in the first column of output.
-L Displays the details of the file in long format. This option is most commonly used.
The information listed in each row is: File type and permission link number file is the main file of the group file size established or recently modified time name
For a symbolic link file, the file name that appears is followed by a "-〉" and a reference file path name.
For device files, the File Size field displays the primary, secondary, and not the file size.
The total number of blocks in the table of contents is displayed at the beginning of the long format list, which contains the indirect blocks.
-L Displays the file that the link points to if the specified name is a symbolic link file.
-M output is in character stream format, file spread, separated by commas.
-The N output format is the same as the L option, except that in the output Chinese part and the group are represented by the corresponding UID number and the GID number, rather than the actual name.
-O is the same as the L option, except that the owner information is not displayed.
-P adds a "/" to the back of the directory.
-Q Use the "?" for the characters that are not displayed in the file name. Replace.
-R Displays the output in alphabetical order or in the earliest priority.
-R recursively displays the files in each subdirectory of the specified directory.
-S gives the number of blocks to use for each directory entry, including the indirect block.
-The t is sorted by modified time (most recently first) instead of by name. If the file is modified in the same time, in dictionary order. The modification time depends on whether the C or U selection is used. The default time stamp is the last modification time.
-U when displayed by file last accessed time (most recent priority) instead of by name. The time tag for-T is modified to the last access time.
-X displays information about each sorted item by row.
-----------------------------------------------------------------------------------------------------
The information displayed with the LS-L command begins with a 10-character string with the first character representing the file type, which can be one of the following types:
-Common documents
D Directory
L Symbolic Link
B Block Device file
C Character device file
The following 9 characters represent the access rights of the file, divided into 3 groups, 3 bits per group.
The first group represents the permissions of the file owner, the second group represents the permissions of the same group of users, and the third group represents the permissions of other users. The three characters for each group represent read, write, and execute permissions on the file respectively.
The permissions are as follows:
R Read
W Write
X execution. For the directory, the entry permission is represented.
s when the file is executed, the UID or GID of the file is given the UID (user ID) or GID (group ID) of the execution process.
T sets the flag bit (left in memory, not swapped out). If the file is a directory, the files in that directory can only be deleted by Superuser, directory owner, or file owner. If it is an executable file, the pointer to its body section remains in memory after the file is executed. This allows the system to load the file more quickly when it is executed again.
-No permissions are set.
------------------------------------------------------------------------------------------------------
Example 1: Lists the contents of the current directory.
$ ls
Ls–f
Ls-a
Example 2: Lists the contents of a directory.
$ Ls–f/home/xu mai1/

Example 3: Lists all the files (including hidden files) under a directory.
$1s-af/home/xu

Example 4: Lists all the files (including hidden files) in a directory in a long format.
$1s-laf/home/xu

Example 5: Lists all files in a directory in a long format including hidden files and their I-node numbers. And the file owner and the group are displayed in the form of UID number and GID number.
$1s-1ainf/home/xu tota1 584 399672

There are three different types of users who can access files or directories: File owners, same group users, other users. The owner is generally the creator of the file. The owner can allow the same group of users to have access to the file, and to give the file access to other users on the system. In this case, each user in the system has access to the files or directories owned by the user.
Each file or directory has three sets of access rights, each with three-bit representation, read, write, and execute permissions for the owner of the file, as well as read, write, and execute permissions for the owner of the same group, read, write, and execute permissions for other users in the system. When you use the LS-L command to display the details of a file or directory, the leftmost column is the file's access rights. For example:
$ ls-l sobsrc. tgz
-rw-r--r--1 root 483997 Ju1 L5 17:3l. SOBSRC
Horizontal line represents a null license. R stands for read-only, W for write, X for executable. Note that there are 10 locations here. The first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it represents a file that is not a directory. If it is D, the representation is a directory.
For example:
-rw-r--r--
Normal file file main group user other user
is a file sobsrc.tgz access, which means that sobsrc.tgz is a common file; the owner of the SOBSRC.TGZ has read and write access; and SOBSR C.tgz the same group of users only Read permissions, and other users have only Read permissions. When the
determines the access rights of a file, users can use the chmod commands provided by the Linux system to reset different access rights. You can also use the Chown command to change the owner of a file or directory. Use the CHGRP command to change the user group for a file or directory.

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.