Shell commands
1. Basic use of Linux command format
command [-options] parameter1 parameter3
Command Name Options Parameter 1 Participation 2
Note: (1) Linux is strictly case-sensitive.
(2) The command must be filled in "command" or "executable file name"
(3) -options is a special definition of the command, starting with "-", multiple options can be connected with "-", such as ls-la is the same as ls-la
(4) The running information of the command is provided at parameter1 parameter2 ..... or the file name used during the execution of the command
(5) In the command format, the above options are separated by spaces. No matter how many spaces there are, the shell treats them as one space.
(6) Use the semicolon ";" to separate two commands, so that multiple commands can be entered in one line, and the execution order of the commands is the same as the input order.
(7) After pressing the Enter key, the command will be executed immediately. If the command is too long and needs to use multiple lines, you can use the backslash "\" to divide a long command into multiple lines to enhance the readability of the command. After a newline, the shell automatically prompts
newline ">"
2. BASH Shell important hotkeys
(1) Tab key - command completion, file completion function
(2) Ctrl + C shortcut key - terminates a command or program function
(3) Ctrl + D shortcut key - the end of keyboard input, the end of file input function, can also be used to replace the input of exit
Use linux basic operation commands
(1) su command - switch user account command
Format: su [options] [username]
(2) exit command - exit the current user or command line execution
(3) shutdown command - restart or shut down the Linux system command
Format: shutdown [options] [time] [warning message]
(shutdown command can only be executed by root user)
(4) man command - online help command
(5) help - system help documentation, used to view the use of all Shell commands
(6) date - display or set the date and time of the system
(7) clear - clear screen command
(8) history - displays the most recent commands executed by the user
Use the logout command to log out of the system
Use the shutdown command to exit the system
Using Directory Manipulation Commands
Special Directories in Linux
special directory | effect |
. | Current directory |
- | previous working directory |
.. | previous directory |
~ | The current user's home directory |
~account | account user's home directory |
Common Linux directory operation commands
(1) mkdir command - create a new directory command
(2) rmdir command - delete "empty" directory command
rmdir [options] directory name
Note: The directory must be empty before it can be deleted
The rm -r dir command can be used instead of rmdir. It is deleted regardless of whether the directory is empty, so it is dangerous
When deleting a directory, you must have write permission to the parent directory
(3) cd command - switch working directory command
Format: cd [directory name]
(4) pwd command - displays the full path of the current directory where the user is located
Format: pwd
(5) ls command - list directory contents command
Format: ls [options] [directory or file]
Example:
1. Create the directory test1/test2/test3/test4 command
[root@localhost test] mkdir -p test1/test2/test3/test4
2. Create test5, and set attributes, user read and write execution permissions, group and others execution permissions
[root@localhost test] mkdir -m chmod 711 test5
Using the Manipulate File Command
Common Linux file operation commands
(1) touch command - create a new file command (the file content is empty)
(2) cp command - copy file or directory command
Format: cp [options] source file or directory destination file or directory
(3) mv command - move file or directory command, rename command
Format: mv [options] source file or directory target file or directory
(4) rm command - delete file or directory command
Format: rm [options] file...
(5) cat command - output the contents of a text file to the screen or terminal window command
Format: cat [options] filename
(6) grep command - in the specified file, find and display the command containing the specified string
Format: grep to find the string text file ming
(7) whereis command - find a specific file location command
Format: whereis [options] command name
(8) more command - display file content in split screen (page backwards)
Format: more[options] file
(9) less command - display file content in split screen (page forward and backward)
Format: less [options] file
(10) head command - display the first few lines of the file
Format: head [options] file
(11) tail command - write the specified file to standard output starting from the specified position
Format: tail [options] file
Example:
1. Display the content of the testfile file in a split screen
[root@localhost test] cat testfile|more
2. Copy the .bashrc file in the home directory to the directory exp and rename it to bashrc
[root@localhost test] cp ~/.bashrc /exp/bashrc
3. Find the line where include is located in the test.txt file
[root@localhost test] # grep include test.txt