Linux common commands

Some shell commands and brief introduction of Linux. Some commands need to be downloaded, such as tree. You can find the download command on the Internet or download it according to the command line prompt
The following command descriptions are not guaranteed to be completely accurate or complete. Please refer to the Linux command manual for details

1. pwd (present work directory) -- displays the name of the current directory
2. cd (change directory) -- change directory

	 cd ~Return to user home directory

3. ls (list) -- lists the files in the current folder

Color: Blue--Catalog, green--Executable, white (black background)--Ordinary documents,
Light blue (blue)--Link (similar to Windows (Shortcut under)
Parameters:-F    Add after directory/,Add after linked file@,Add after executable*(dir (with the same parameters)
	 -a		Show hidden files
	 -l		List details
	 -t		In chronological order (from small to large)
	 -r		And-t Shared, arranged in reverse chronological order (from large to small)
	 -R		Lists the file and its child file containment relationships
	 -i		see i Node( inode(Pronunciation: eye-node)Translated into Chinese is the index node
	 It is used to store the basic information of files and directories, including time, file name, user and group, etc.)

4. dir - similar to ls function, but does not distinguish colors. It is recommended to add the parameter - F
vidr -- equivalent to ls -l
5. cat (concatenate) --- view the contents of the file (the man command is concatenate files and print on the standard output. Connect the file and output it to the standard output)

Parameters:-n	set number 

6. more -- the same as cat. In case of multiple pages, display the current comparison column, turn the page by space, enter the next line, and exit Q
7. head -- lists the file contents in a specified number of lines from top to bottom, and multiple files can be selected at one time

Parameters:-n (*number*)or -(*number*)Specifies the number of rows to display

8. tail -- specify the number of lines from bottom to top to list the contents of the file. The parameters are the same as head

Parameters:-f	When there is information input.log Print new entries in real time when file

9. less -- Text viewing

Parameters:-M	Show more detailed information
 Function: after entering, enter/(*char*) You can find the content, highlight the first content and continue
 Find available inputs/Continue after
	Space bar page down, B Page up 
	Q sign out less

10. grep (Global Regular Expression Print) - find the content in the file

Parameters:-r	Recursive lookup of directories
	-n	Find line number
	-i	Case insensitive
	-v	Parameter does not display a string	

Form: grep  *char*  *filename* ,Will be in filename Find in char All right, check
 Find phrase to add''

11. Find (path) -- find command

Parameters:-name *name*	Find a file named name File
	-size	Search by file size;
	-type			file type
	-atime/mtime	n Find last time in n Files modified days ago
	-ctime n		lookup n Files created days ago	
	-print			output
 Advanced find:
	find . -name "name" - exec *shell command* {} \
	Will take name List a table for the file named and edit it shell command Operation,
	shell command Is a built-in command, such as ls
	find . -name "name" - ok *shell command* {} \
	Similar to the previous one, but will prompt whether to execute command
	find . -name "name" | xargs shell command

12. locate -- find the file location. No path is required. updatedb is required
13. Where is -- find the location of program binaries, documents, source code and manuals
14. which -- find command location
15. who -- view users using the server
16. whoami -- view the current user name
17. uname -- view the system version

Parameters:-a	detailed information
	-r	Kernel information

18. man -- Linux help command (manual)

Description: actual call less Display, by J,K Complete page turning, space page down, B(back)Page up 

19. whatis -- view a brief introduction to the command
20. apropos -- find the command by describing the keyword of the command
21. mkdir -- create folder

Parameters:-p	Add this parameter to create a subdirectory structure

22. touch - create an empty file or update the file creation date
23. mv target.file direct -- set target. Move file to direct directory

Description: when there is a duplicate name between the moved file and the target folder, there is no prompt for direct overwrite. A prompt can be displayed by adding a parameter
	Available for renaming
	When direct When it does not exist, the actual renaming operation (renaming) is performed
	When the operation is two files, the function is also rename
 Parameters:-i	When the moved file has the same name as the target folder, you will be prompted whether to overwrite the file
	-b	Add after moving files with duplicate names~

23. cp target.file target -- copy the file to the target folder

Parameters:-b,-i with mv
	-r	Copy subdirectory contents together
	-a Keep copies of source file attributes, such as creation time, etc

24. rmdir/rm -- delete folder / file

Parameters:-r	Delete all, including the contents under the subdirectory
	-i	Prompt whether to delete the file
	-f	For read-only permission files, delete them directly without asking

25. sudo -- obtain administrator permission
26. groupadd - create a user group
27. chgrp group file -- transfer the permission of file to group
28. chmod -- file read / write permission change

Format: chmod[who][+|-|=][mode]
	-u  user
	-g	group
	-o	other
	-a	all(By default, if there is no parameter, it means that all users are allowed to change permissions)
	-	Reduce permissions
	+	Add permissions
	=	Delete other permissions and keep only the given permissions
 Number format:
	0	No permission (000)
	1	Execution Authority x(001)
	2	Write permission w(010)
	4	Read permission r(100)

29. history - lists all commands that have been used
30. Tree -- list file relationships in a tree structure
31. ln -- link

Parameters:-s(soft) Soft link
	No parameters	Hard link
 Format: ln -s File link name (self-defined), it is best to use the absolute path, which can still be used when moving the link
 Find the file. When using relative path, if you move the link location, the file will not be found
ln File link name, create a hard link, and the hard link points to the same file as the source file i Node, move the link
 Files can be found
 Description: modifying a link affects the source file
	It is not allowed to establish a hard link for the directory, but a soft link can be established. The operation of the directory soft link is essentially to
	Operate from the original directory

32. wc -- view file bytes, characters, and lines

Parameters:-l	Display rows( line)
	-c	Number of characters displayed( char)
	-w	Displays the number of words( word)

33. chown -- the person who changes the document

format:chown username: groupname file name
	Change the user owner and group of the file

34. chgrp -- change user group

35. Sudo apt get install - install software
36. Sudo apt get remove -- delete the software
37. Sudo apt get update - software update list
38. Sudo apt get clean -- clean the software installation package
39. sudo dpkg -i xxx.deb - software package installation
40. sudo dpkg -r software name - Software uninstall
41. gzip/bzip2 -- file compression command. You can only compress one by one. After compression, the original file disappears and the directory cannot be compressed

	gzip *    Compress all files in the current directory, But directories cannot be compressed
	gunzip *  Unzip all files in the current directory.gz file
	bzip2 *   Compress all files in the current directory, But directories cannot be compressed
	bunzip2 * Unzip all files in the current directory. bz2 file

42. tar -- compression / decompression command

Parameters:-j	use bzip2 Compress and decompress
	-z	use gzip Compress/decompression 
	-c	Create a new compressed file, and x Mutually exclusive use
	-x	Release files from compressed files, and c Mutually exclusive use
	-v	Detailed report tar Processed information
	-f	Specifies the name of the compressed file
	-t	See which files are in the compressed file
	Tail addition-C catalogue	Specify the extraction directory
 Description: you can compress files or directories
	appear tar: Exiting with failure status due to previous errors You do not have permission to read, change or use the file sudo
	Note: to view the contents of the compressed package, you must t As the first parameter

43. rar -- compression / decompression

	Format: tar a -r file name	Files to compress	Compressed file(-r (indicates a directory)
		tar x xxx.rar Directory name unzip file


Format: compression: zip -r Compressed package name file to be compressed(Including files or directories)
	Extract to the specified directory: unzip  –d Unzip directory

Command line action shortcuts

ctrl+p-Previous command found (from history Medium)( previous)
ctrl+n-Find next command( next)


ctrl+d-Delete the character where the cursor flashes
ctrl+h-delete before cursor 
ctrl+u-Delete everything before the cursor
ctrl+k-All contents after deleting the cursor (including cursor contents)


ctrl+a-Move to the leftmost end
ctrl+e-Transplant the rightmost end
ctrl+f-Move forward (move left)( front)
ctrl+b-Move back (move back)( back)

vim using shortcut keys
Last line mode

ZZ: Save and exit
gg=G:Code formatting
w:Move a word
gg:Move the cursor to the beginning of the file
G:Move the cursor to the end of the file
0:Move the cursor to the beginning of the line
$:Move cursor to end of line
nG:Line jump to n that 's ok.
h:Move cursor left
j:Cursor down
k:Move cursor up
l:Move cursor right

Delete command

x: Delete the character at the cursor
X: Delete character before cursor
dw: Delete a word
dd: Delete a row
d0: Delete the character from the cursor to the beginning of the line, and do not delete the character at the cursor
d$(D): Delete all characters from the cursor to the end of the line, including the characters at the cursor
ndd: Delete this line and below n that 's ok
v/ctrl+v: Select Delete, v Non column mode, ctrl+v For column mode, please try to distinguish after learning the differences

Withdraw order

u: Withdraw order
ctrl+r: Anti revocation

Copy command

yy: Copy this row
nyy: copy n that 's ok
p: Paste to next line
P: Paste to previous line

Replace command

r: Replace the character at the cursor position
R: Replace word

Find command

	/(word): Find words
	?(Word): ditto
	shift+k: View help documentation


i: Insert before cursor
a: Insert after cursor
I: Insert at the beginning of the line where the cursor is located
A: Insert in the row of the cursor
o: Insert a new key line under the line where the cursor is located
O: Create a new insertion line above the line where the cursor is located
s: Delete the character after the cursor and insert it from the current position
S: Delete the current line where the cursor is located and insert from the beginning of the line

Quick page turning
ctrl+u: turn up half a page
ctrl+d: half page down
ctrl+f: scroll down one screen
ctrl+b: flip up one screen

Command mode


:s/old/new/	The first in the line where the cursor is located old Replace with new
:s/old/new/g	All of the lines in which the cursor is located old Replace with new
:m,ns/old/new/g	Will be the first m Line to n Between rows old Replace all with new
:%s/old/new/g	All in the file old Replace with new
:1,$s/old/new/g	ditto
:%s/old/new/g	Same as above, but each replacement needs to be confirmed by the user

Split screen

:sp file name	The current file is split from another file
:vsp file name	The current file is vertically split from another file

Tags: Linux

Posted on Fri, 15 Oct 2021 14:13:44 -0400 by xsaero00