Linux (Fedora/Ubuntu/RedHat) ls commands are frequently used. You can use the ls command to view the files contained in linux folders and file permissions (including directory, folder, and file permissions ), view directory information and so on. The ls command is frequently used in common linux operations. So here we will introduce how to use the ls command.
1. Introduction to ls commands
Ls command permission: all users.
Format: ls [Option] [directory name].
Function: Lists All subdirectories and files in the target directory.
Option description:
-A is used to display all files and subdirectories (Paul dot files ).
-L in addition to the file name, the File Permission, owner, file size, and other information are listed in detail.
-R displays the list of contents in alphabetical order.
-T sort by file modification time, rather than by file name.
-A is the same as-a, but does not list "." (indicating the current directory) and "." (indicating the parent directory of the current directory ).
-F adds a flag after the listed file name and directory name. For example, add "*" after the executable file and add "/" after the directory name to differentiate different types.
-R: if the target directory and Its subdirectories contain files, all files are listed.
-Cx sorts file names by row and cross-page.
-CF list the file names in the directory by column, and append a character after the file name to differentiate the Directory and file type: Add a slash (/) after the directory file name (/). Append an asterisk (*) to the executable file name (*). Append a @ symbol to the symbolic link file name. No characters are appended to a common file name.
-CR displays all the files in the target directory and Its subdirectories in a column format (both directories and files can be called files), also known as recursive lists.
The following two examples illustrate how to use the Linux ls command.
Ii. Examples of ls commands
Example 1: list all the files and directories in the/home/cc/Ruijie folder.
[Cc @ cc ~] $ Ls-l-R/home/cc/Ruijie
Enter the preceding command and press enter to display the details of all files in the directory, as shown below:
[Cc @ cc ~] $ Ls-l-R/home/cc/Ruijie
/Home/cc/Ruijie:
Total 2168
-Rwxr-xr-x 1 cc 112876 2008-06-26 libpcap. so.0.6.2-rwxr-xr-x 1 cc 737192 2008-06-26 libstdc ++. so.5-rwxr-xr-x 1 cc cc1938 2004-04-23 readme.txt
-Rwxr-xr-x 1 cc 1350772 xrgsu
[Cc @ cc ~] $
When using the ls command, Beginners should pay attention to the Command Format: After the command prompt, the first is the command keyword, the next is the command parameter, there must be a short line "-" before the command parameter, all command parameters have specific functions. You can select one or more parameters as needed. The command parameters are followed by the command operation objects. In the preceding command "ls-l-R/home/cc/Ruijie", "ls" is the command keyword and "-l-R" is the parameter, "/home/cc/Ruijie" is the operation object of the command. In this command, two parameters are used: "l" and "R". Of course, you can also use them together, as shown below:
[Cc @ cc ~] $ Ls-lR/home/cc/Ruijie
The execution results in this form are exactly the same as those in the preceding command form. 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 cc folder. To operate the Ruijie file under the cc folder, I can directly enter ls-lR Ruijie, you can also use ls-lR/home/cc/Ruijie.
Example 2: List the details of all directories starting with "t" in the current directory. Run the following command:
[Cc @ cc ~] $ Ls-l t *
In this way, you can view the information of 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.