Vi. File Search Commands
11:which
Function Description: Displays the directory where the system commands are located
Command path:/usr/bin/which
Execute Permissions: All Users
Syntax: which [command name]
Example: $ which LS
12:find
Function Description: Find files or directories
Command path:/usr/bin/find
Execute Permissions: All Users
Syntax: Find [Search path] [search keywords]
Example 1: Find file init in directory/etc
Find/etc-name Init
Example 2: Finding files larger than 100MB in the root directory
Find/-size +102400
Example 3: Find the Owner-lw3 file in the home directory
$ find/home-user LW3
Example 4: Find files and directories with properties modified within 24 hours under/home
$ find/home-ctime-1
Example 5: Find files that are larger than 100MB and less than 200MB in the/root directory
$ find/-size +102400-a-size-204800
Example 6: Finding an XML file under/etc
$ find/etc-name XML
$ find/etc-name Xml-o-name conf
13:locate
Function Description: Find files or directories
Directive English literal: List files in databases
Instruction Path:/usr/bin/locate
Execute permissions: All User
Syntax: Locate [search keywords]
Example 1: List all files related to file
$ Locate File
Locate A.txt
14:updatedb
Function Description: Create a database of the entire system catalog file
Directive English original meaning: update the Slocate database
Instruction Path:/usr/bin/updatedb
Execute permissions: Root
Syntax: UpdateDB
Example 1:# updatedb
15:grep
Function Description: Searches the file for string matching lines and outputs
Command path:/bin/grep
Execute Permissions: All Users
Syntax: grep [Specify string] [source file]
Example 1: Search for lines containing "EMP" strings from File//home/lw/dns2
grep emp/home/lw/dns2
Example 2: Searching for a line from the/etc/directory with a file with a. conf extension and a "text" string
grep text/etc/*.conf
16.WC [Options] File/statistics
Lines, words, and words in a statistical file
Cat A.txt
17.sort [-r]/[-u] files, sorting
Rearrange text sequentially and send it to display
Sort A.txt
18.diff [Options] File/diff
Report Text Variance Content
Diff-b A.txt C.txt
19.CMP Report Text Difference location
Cmp-c C.txt A.txt
20.uniq Remove duplicate rows from the file (do not modify the file, remove duplicate lines in the display content)
Uniq-c A.txt
21.cut display a column in a file (column: delimited)
Cut-c 1-10 File Name--Displays information from 1 to 10 columns
--cut-fz-d: File name
22.paste stitching text by column (left and right)
Paste A.txt C.txt
Seven, compression decompression command
. Gzip
Feature Description: Compressed files
Command path:/bin/gzip
Execute permissions: All users
Syntax: gzip options [File]
Example 1:
Touch T1 Create file
Gzip T1 compressed file format:. GZ
Gunzip
Function Description: Unzip the. GZ compressed File
Command path:/bin/gunzip
Execute permissions: All users
Syntax: gunzip options [ Compressed Files]
Example 1:
Gunzip t1.gz
. Tar
Feature Description: Package directory
Command path:/bin/tar
Execute permissions: All users
Syntax: tar options [CVF] [contents]
-C generates a. tar package file
-V displays details
-F To specify the compressed file name
-Z-Package compression
After the compressed files format:. tar.gz
Example 1: Compressing directory Oracle into a packaged and compressed file
$ TAR-ZCVF oracle.tar.gz Oracle
Tar command decompression syntax:
-X unpack. tar file
-V Show Details
-F Specify unzip file
-Z Extract
example 2:$ tar-zxvf o Racle.tar.gz
34. Compression Decompression command: Zip
Function Description: Compressed file or directory
Command path:/usr/bin/zip
Execute permissions: All users
Syntax: Zip option [-r] [compressed file name] [File or directory]
-R Compressed directory
compressed file format:. zip
Example 1: Compressed file
First cut the current location to the current user directory:
$ touch T1--Create file
$ zip t1.zip T1
Example 2: Compress directory
$ mkd IR dir1--Create directory
$ zip-r dir1.zip dir1
35. Compression Decompression Command: Unzip
Function Description: Unzip the. zip file
Command path:/usr/bin/unzip
Execute Permissions: All Users
Syntax: Unzip [compressed file]
Example 1: Extracting Files
RM T1
$ unzip T1.zip
Example 2: Extracting a Directory
$ unzip Dir1.zip
36. Compression Decompression Command: BZIP2
Function Description: Compress file
Command path:/USR/BIN/BZIP2
Execute Permissions: All Users
Syntax: bzip2 option [-K] [file]
-K retain original file after generating compressed file
File format after compression:. bz2
Example 1:
$ bzip2-k T1
37. Compression Decompression Command: BUNZIP2
Command path:/USR/BIN/BUNZIP2
Execute Permissions: All Users
Syntax: BUNZIP2 option [-K] [compressed file]
-K retain original file after decompression
Example: $ bunzip2-k t1.bz2
Viii. user groups and user management
41. Add User Group Groupadd
Groupadd GroupName
42. Delete a user group
Groupdel GroupName
43. Modify user Groups
Groupmod Lw3-n Lw_3
Groupmod
44. Switch User groups
Newgrp <groupname>
If a user belongs to more than one user group at a time,
You can use the NEWGRP command to switch to the destination group so that you can have permissions for that group.
ID-User Current group
45. View all Groups
All groups are actually/etc/group file content to do some filtering.
Cat/etc/group
46. View the group in which the user is located
Groups <username>
47. Add Users
Useradd <username> D <path>-m-g–g–p
Commonly used is the above several parameters, the meaning is:
-D: Specifies the owner directory. If this directory does not exist, this directory is created with-M.
-M: Create User home Directory
-G: User-owned group ID
-G: User-owned group name
-P: Login password. Note that this login password is not clear text and refers to the encrypted password.
Useradd testuser–m–g LW
A testuser user is created and the/home/testuser user home directory is created automatically, and the user is added to the LW group.
48. Delete a user
Userdel–f–r <username>
-R: Delete the user home directory and messages in the mailbox
-F: Forcibly deleting files, even if the owner is not the user
USERDEL-FR LW2
49. Modify the user
Usermod <username> D <path>-m-g–g–p
Parameter meaning is roughly the same as Useradd
Usermod lw2-g LW
50. User Password
passwd <username>: Change Password
Passwd–d <username>: command to delete the user's password, that is, the next login without a password.
Passwd–l <username>: Lock users so they can't sign in
Ix. Flow and piping
51. Flow
Keyboard input stream stdin (0) <, <<
Screen output stream stdout (1) >, >>, &>, z>
Error output stream stderr (2)
redirect
> Coverage
>> Append
REDIRECT Standard input stream:
Use cat > C.txt to read the data entered by the user's keyboard and save it to the C.txt file, specifying "!" As Terminator
Cat > C.txt <<!
Use cat > A.txt < b.txt to change the standard input stream to the stream that reads the contents of the B.txt file.
Ls-l
REDIRECT Standard output stream:
Ls-l > B.txt output to file B.txt in overwrite mode.
Cal 2018 >> cal.txt output to file Cal.txt in append mode.
REDIRECT Error output stream:
Remove 2>> error.txt Output the error message to Error.txt.
52. Piping "|"
The output of the previous filter is fed directly to the input of the latter filter.
Ls-l | More
53. Filter "grep"
Ps-ef | Grep/bin | More
PS View all processes in the system
| Pipeline
grep filtering
/bin using "/bin" for filtering
More split screen display
Ten, VI
61. Enter: VI, VIM,
VI filename
62. Exit
: Q
: q!
: Wq
: wq!
63.3 modes:
Normal mode: All keys on the keyboard may be a command.
Last-line mode: Press ": 、?、/" In normal mode to enter the last line mode. Return to ESC.
Input mode: In normal Mode Press "a (append append), I (insert insert), O (Open, new opening 1 lines that is newline)" can enter the input mode. Return to ESC.
64. Normal Mode VI operation
I Insert at the beginning of the current line and enter "Insert Mode"
A is appended at the end of the current line and enters "insert mode"
O open a new line before the current line and enter insert mode
DD Delete the current line//3DD Delete the current 3 rows
YY copy when moving forward
P Pastes the contents of the Clipboard into the current line
U Undo Previous Action
U undo all actions within 1 lines
G Go 25 lines
s deletes the current character and goes into "insert mode"
S deletes the current line and enters insert mode
X1 <del> Delete 1 characters
NX removes the next n characters
DW Delete to suffix
NDW Delete after n words
d$ Delete to end of line
d^ Delete to the beginning of the line
nd$ after deleting n rows
yy the row where the selected cursor is copied
YW the word of the selected cursor is copied
NYW Select the position of the cursor to the next n word copy
y$ the portion of the selected cursor to the end of the line copy
y^ copy of the selected cursor position to the beginning of the line
Nyy the position of the selected cursor to the next n-row copy
CC Cut When moving forward
NCC cuts the current line and the following n rows
P Paste at right of cursor
P paste at left of cursor
R Replace operation
/< text > forward lookup
? < text > Backward lookup
?? Repeat Last Lookup
65. Last-line mode command
Display line number: Set Nu
Line number not displayed: Set Nonu
: w filename
: Wq
: q!
:! < command > Run the Linux command, and then return for example:!pwd
: r < file name > insert file at cursor
: r! < command > < file name > insert the output of < command > into the current text
: Nr < file > put < file > insert to Nth row
: Sh go to Shell
: So < file > read < file, then execute the command inside the file
: 2,8 Copy 10 replication
Delete N Remove
M move n moves the M line to the position of n rows
Linux_ (2) Basic command (bottom)