The shell in Linux is an outer-layer protection tool for the Linux kernel and is responsible for completing the interaction between the user and the kernel.
A command is a text stream in which a user issues a control request to the system kernel and interacts with it.
The shell is a command-line interpreter that resolves user commands to instructions that the operating system understands to enable the user to interact with the operating system. At the same time, the shell provides the operating system with the function of the kernel, which is used to manage and run the system directly.
Shell script: When you need to execute several commands repeatedly, you can assemble these commands, add some control statements, edit them into shell script files, and give them to the shell for batch execution.
The format of the shell command
1. Shell prompt:
[Email protected]:direction$
User name hostname directory name
The root directory is displayed as "/" when displayed as "~" in the user's home directory
2. Command format
Contains 3 features: command name, options, parameters
The prompt is "#" and the other user's prompt is "$"
If multiple commands are written on one line, separate the commands with a semicolon (;);
If one cannot finish writing on a line, use a backslash (\) at the end of the row to indicate that the command is not closed
Linux commands
1. User System related commands
2. File and directory related commands
(1) CD Change working directory
PWD Displays the current directory
CD-Can go back to previous working directory
./Represents the current directory: /representative Parent Directory
(2) LS lists the contents of the directory
Options:-L output one file at a line
-a,-all lists all files in the directory, including the "." The file that starts with
-d lists directory names like other files, rather than listing the contents of a directory
-F Do not sort directory contents, listed in the order they are stored on disk
Example: Ls-l
Ls-a (Show All ".") Files that begin with)
(3) mkdir Create a directory
Option:-M sets access permissions on the new directory, which can now be set with the chmod command
-P Create a directory if some directories in this path do not already exist, and with this option, the system will automatically set up those directories that do not already exist, that is, multiple directories can be established at one time
Example:
Mkdir-p./hello/new Create a multilevel directory
Mkdir-m 777./why Create a directory with the appropriate permissions
(4) Cat connects and displays information about one or more of the files specified
Options:
-N number of rows of all outputs starting from the first line
-B does not number blank lines
Example:
Cat-n hello1.c helloc2.c Specify output to hello1.c and hello2.c and specify line number
(5) CP copies the given file or directory to another file or directory
Options:
-A preserves links, file attributes, and copies its subdirectories, which are equal to the combination of the DPR option
-D Keep Links when copying
-F Delete a target file that already exists without prompting
-I will give a hint before overwriting the target file, asking the user to confirm that the target will be overwritten, and the interactive copy
-P At this point the CP will also copy the modification time and access rights to the new file in addition to the contents of the source file.
-R If the source file is a directory file, the CP will recursively replicate all subdirectories and files in that directory. The destination file must be a directory name at this time
Example:
Cp-a./my/why/./Use the "-a" option to copy all files under the/my/why directory to the current directory. At this point, there are existing files in the original directory.
(6) MV to rename files or directories or to move files from one directory into another directory
Options:
-I if the MV operation will result in overwriting an existing target file, the system asks whether to rewrite and asks the user to answer Y or N, which avoids overwriting the file by mistake
-F Disables interaction and does not give any hint when the MV operation is to overwrite an existing target file, after specifying this option, the I option will no longer work
Example:
Mv-i./my/why/./move all files in the/my/why directory to the current directory, the files in the original directory are automatically deleted
(7) RM deletes one or more files or directories in a directory
Options:
-I input Interactive delete
-F ignores files that do not exist, but never prompts
-R instructs RM to remove all directories and subdirectories listed in the parameters recursively
Example:
Rm-r-I/why use the "-r" option to delete all contents of the./why directory and the system will delete the confirmation
(8) Chown modification of file owners and groups
CHGRP changing the group ownership of a file
You must have root privileges to use the Chown and CHGRP commands
3, compression packaging related commands
Know the shell