Table of contents
1. Directory operation commands
1. Determine the current directory path
2. Change the current directory
5. List the contents of the directory
5. Display content page by page
3. Manage file access permissions
2. Change file access permissions:
2.1. User entity symbol representation
1. Directory operation commands
1. Determine the current directory path
The pwd (show working directory) command displays the full path of the current directory.
2. Change the current directory
The cd (change directory) command changes the current directory to a specified directory.
3. Create a directory
The mkdir (create directory) command is used to create a new directory
4. Delete directory
The rmdir (remove directory) command deletes the directory specified as its argument and can be abbreviated as rm -rf
5. List the contents of the directory
The ls (list directory contents) command is used to display the names of files and subdirectories in a directory. This operation will only display the file name, not the file type. The ls -l option will display a detailed list of files and directories.
The specific content of the file is displayed: characters symbolizing the file type
symbol | file type |
---|---|
- | Ordinary document |
d | Table of contents |
b | block special file |
c | character special file |
l | symbolic link |
s | socket |
p | command pipeline |
Some other common options provided by the ls command
Options | Function |
-a | List all files, including hidden files |
-F | Display file type and name ("/" represents directory, "*" represents executable file) |
-R | Provides a recursive list, meaning explicitly specifying the contents of a directory and all subdirectories |
-r | Display files and directories in reverse order |
-S | Sort by file size |
-A | Display all directory files except . and .directories. |
Practical operation: Hidden files are not displayed in the normal list (the names of hidden files begin with a period)
2. File command
1. Display file content
The cat (connect) command displays the contents of a specified file. Additionally, the cat command can be used to vertically concatenate the contents of multiple files
2. Copy files
The cp (copy) command copies the contents of the source file to the destination file. The syntax of cp is: cp [options] <source file/s> <destination directory/file>
<source file/s> specifies the file to be copied.
<destination directory> specifies the location where you want to copy the files.
<destination file> specifies the name of a copy of the file <source file/s>. You can specify any of the following parameters: <destination directory> or <destination file>.
Other common options used with the cp command:
Options | Function |
---|---|
-i | Prompt before rewriting |
-l | Hard link the file instead of copying it |
-s | Create symbolic link |
-v | Detailed description of what is being done |
-r | Copy recursively, including its subdirectories and all files |
3. Delete files
The re (remove) command is used to delete files or directories. The syntax of rm: rm [-r] [options] file/s
file/s is the name of the file to be deleted
If the file name to be deleted is not in the current directory, we must provide the complete path name
-r can delete directories and their subdirectories recursively, which is sometimes easier to use than our rmdir. This command can only be used to delete our empty directories.
Options | Function |
---|---|
-I | The option prompts for confirmation when deleting multiple files, so it may become tedious when deleting many files. If you wish to delete a large number of files without prompting for confirmation, use rm the command's -f options. |
-f | Force file deletion. Ignore non-existent files, which means that if the file does not exist, the command will not prompt an error |
-r or -R | Recursive deletion, which means deleting a directory and its subdirectories |
-v | Detailed information about the operation being performed |
4. Move and rename files
The mv (move) command is used to move a file or directory from one location to another or change the name of the file or directory. Note that moving a file is not the same as copying a file. Moving a file does not create a new file.
Move syntax: mv [option] source destination
source represents the file or directory to be moved
destination represents the location to be moved
mv source file name or directory name new file name/new directory name
5. Display content page by page
The cat (file display) command is used to display the contents of our files on the screen. However, if the file being displayed is very long, all the contents will scroll up on the screen. To view the file page by page, you can use more or less Order
type | illustrate |
---|---|
cat | Display all data, scroll up if the data is too long |
more | List data page by page. The more command is similar to the less command. The only difference is that more may also scroll up for display. |
less | The less command is faster than our more command. When executing the command, you can use the left and right keys to control page turning. When exiting, press the q key. |
Practical operation:
cat:
more: You can use the enter key to lengthen the content
less: use q to exit
6. Wildcard characters
The shell provides the ability to perform an operation on a set of files without specifying all the names of the files on which the operation is performed. This is accomplished by using specific characters in the command instead of the actual file name. The shell interprets these special characters as a specific character pattern. The shell then compares all file names in the directory specified in the command to find those that match that pattern. filename and then execute the command on files whose names match the pattern
character | use |
---|---|
* | This is called a wildcard and can match zero, one, or a string containing multiple characters. |
? | Matches only one character |
【】 | Matches only one of a specified set of characters |
Practical operation:
3. Manage file access permissions
1. Access permission table
1.1. Symbol mode
File Type: Directory, block device file, character device file, socket, etc.
Owner: permissions of the file owner
Group: Permissions of the group to which the file belongs
Other User: other users
1.2. Absolute mode
Number (the larger the number, the smaller the authority. Foreigners like the big one to mean the small one. For example, M means minutes and m means month) | Permissions |
---|---|
4 | read |
2 | Write |
1 | implement |
Permissions are displayed starting from the second position in the first column
Detailed explanation of permissions:
*Read permission allows users to perform the following operations:
List the contents of a directory
*Write permission allows the user to perform the following actions:
Copy from file to directory
Delete files from directory
Rename files in directory
Create subdirectory
Remove subdirectory from directory
Move files to or from a directory
*Execute permission allows the user to perform the following operations
Display the contents of a directory file from a directory
Change to directory
Copy files from directory
2. Change file access permissions:
2.1. User entity symbol representation
symbol | meaning |
---|---|
u | The owner of the file or directory |
g | members of the same group |
o | All other users |
a | all users |
2.2. Change user permissions
In Linux, supervisors can be allowed to use commands (such as chmod) to change file access permissions. The following points need to be noted.
chmod 用户类型[+ 授予或则 - 撤销]权限类型 文件名
*用更改其权限的用户类型
*要更改的权限类型
*要授予还是要撤销权限
*要更改其权限的文件的名称
例如: