Basic Linux commands-Common Operations, linux -----
Linux/Unix Command Format:
Command name [Option] [parameter]
Note: The content in [] can be omitted.
Example: $ ls
$ Ls-l #-l is an option
Start symbol:
File Name or folder name
. Current folder
.. Folder at the upper level
~ User main directory (Home Directory)
View class:
Pwd command:
Usage:
Path used to display the current operation location (current working path)
Example:
$ Pwd
/Home/Tarena
Ls command:
Usage:
Displays the file or folder information of a specified directory.
Format:
Ls [Option] [Folder name/file name]
Common options:
-L detailed file information displayed in the list
-A: displays all files/folders.
History command:
Purpose:
View commands previously entered
Format:
$ History <press enter>
Grep command:
Purpose:
Search for the corresponding file based on the file content
Format:
Grep "content" [Option] File Name or path
Common options:
-N: display the row number
-R/-r recursive search for files in a file
Cat command:
Purpose:
Display file content to screen output
Format:
Cat File Path 1 file path 2 ······
Example:
Cat/etc/passwd
Less command:
Purpose:
Display the content of a text file to the screen (you can roll it up or down)
Basic operations:
Q exit
J flip down
K flip
Flip one page by Space
Example:
Less ~ /Aid1710/Linux/day01/day01.txt
New class:
Mkdir command:
Usage:
Create one or more folders (directories)
Format:
Mkdir file name (Multiple folders must be created and separated by spaces)
Mkdir-p option:
Mkdir-p create folders step by step
Touch command:
Purpose:
1. If the file does not exist, create an empty file.
2. If a file or directory exists, use the system time to update its modification time.
Format:
Touch file or folder name (the extension name must be specified for the file)
To operate a path with special characters:
Enclose the path with two double quotes ("")
Example:
Mkdir "a B"
Touch "python base.txt"
Cp command:
Purpose:
Copy a file or folder
Format:
Cp option original folder/file name target path
Option:
-A: copy the content in the folder.
Example:
$ Cp a aaabbcc.txt
Delete class:
Clear command:
Purpose:
Clear terminal content
Format:
Clear
Shortcut Key:
Ctrl + L
Rm command: rm (remove)
Purpose:
Delete a file or folder
Format:
Rm [Option] file or folder
Common options:
-R recursively deletes files and folders in a folder.
-I Prompt before deletion (y indicates yes, n indicates no)
-F: Force Delete. No prompt is given.
Rmdir command:
Purpose:
Delete one or more folders (there must be no files in the folder, empty folders)
Format:
Rmdir [Option] file name (if you want to delete Multiple folders, separate them by spaces)
Rmdir-p option:
Rmdir-p xxx If the internal file is empty, delete the intermediate folder step by step
Positioning class:
Cd command:
Purpose:
Change the current working directory (to a directory/path)
Format:
Cd directory name
Help:
Command help:
Three methods:
1. $ help command name
2. $ command name -- help
3. $ man command name Test
Note q exit
File Processing class:
Gzip command:
Purpose:
Compress the file with a zip compression algorithm. Generate compressed files
Format:
Gzip file name
Note:
The compressed file is usually .gz.
Gunzip command:
Purpose:
Decompress the file in .gz format generated by zipzip computation.
Format:
Gunzip file name
Tar command:
Package and package files or folders
Format:
Tar [Option] Save the file name or path [original file name or path]
Option:
-C: Create a package
-X unpack
-F file name
-V: displays the operated files.
-Z: Use gzip/gunzip to compress and decompress the package.
-C path: Change the decompressed path
Example:
Tar-cf file.tar files/
Note:
Common Packaging Commands:
Tar-czvf file.tar.gz files/
Unpack:
Tar-xzvf file.tar.gz
Permission operation class:
File Permission:
Command for viewing file permissions:
Ls-l
File Permission type:
R read permission
W write permission
X execution permission
-No permission
File Permission group:
User | group | other permissions (other)
?????????
Maximum permissions:
-Rwx
Minimum permissions:
----------
Administrator Account:
Windows: administrator
Unix/Linux: root
Chmod command:
Purpose:
Used to modify File Permissions
Format:
Chmod permission file name/folder name
Permission:
U owner (owner/owner)
G same group users (Group)
O other users
A All Users
+ Add permissions
-Remove Permissions
777 maximum Permissions
000 minimum Permissions
Binary: Dual-entry
0000
0011
010 2
0113
100 4
101 5
110 6
111 7
Process Management:
What is process:
The program being executed is called a process.
Ps command:
Purpose:
View Processes
Format:
Ps [Option]
Option:
-Aux: view all process information in the current Linux System
Example:
Ps <press enter>
Ps-aux
Kill command:
Purpose:
Kill Process
Format:
PID Number of the kill Process
Example:
Sudo command:
Purpose:
Run these commands with root privileges of Super Users
Format:
Sudo Command [Option] Parameter
Option:
-I: Enter the root user.
Example:
$ Sudo-I
Exit command:
Purpose:
Log out
Format:
Exit
Common classes:
Pipeline Operation:
OPERATOR:
| (Shift ++ \)
Purpose:
Redirects the command output to the input of another command.
Format:
Command 1 [select parameter 1] | command 2 [parameter 2] | command 3 [parameter 3] |...
Output redirection:
There are two types of output:
1. standard output
2. Standard Error output
Standard output redirection:
> Redirects the standard output of a command to a file.
> Append the standard output to the end of a text.
Format:
Command> file name # New (overwrite if any)
Command> file name # New (if any, append the object to the end)
Standard Error output redirection:
2> redirect the standard error output of a command to a file
2> append a standard error output to a file
Format:
Command 2> file name # New (overwrite if any)
Command 2> file name # New (if any, append the object to the end)
Example:
Grep "tedu"-nR/etc> out.txt
Grep "tedu"-nR/etc 2> error.txt
Grep "tedu"-nR/etc> out.txt 2> error.txt
Redirect all outputs:
&> Redirect all outputs to a file # & (Shift + 7)
& >> Redirect all output to an object
What we know now