# Knowledge Essentials
1. Find commands
2. Piping
3. Output
4. Vim Editor
5. Alias aliases
6. Install Python
Main commands: ' Find ', ' locate ', ' grep ', ' echo ', ' vim '
# 1. Find commands
# command Search
' Whereis ' Search for command location and help document location
' which ' search locations and aliases for commands
1 [[email protected] ~]$ whereis ls2 ls:/bin/ls/usr/share/man/man1/ls. 1 . GZ 3 [[email protected] ~]$ which ls4 alias ls='ls--color=auto' C11>5 /bin/ls
View Code
# file Lookup
' Find ' command format: ' Find [-path]-options '
Path: The directory you are looking for, the default is the current directory
Option
-name to find a rule by file name
-type Find by File type
-size Search by File size
Wildcard characters:
* Match any Content
? Match any one character
[] matches any one of the characters in brackets
1[Email protected] ~]$ Find/bin-name'ping*'2/bin/ping63/bin/Ping4[[Email protected] ~] $CD/bin5[Email protected] bin]$ Find-name'ping*'6./ping67./Ping8[Email protected] bin]$ Find-name'Ping?'9./ping6Ten[Email protected] ~]$ Find-name'f*' One./F2 A./F1 -[Email protected] ~]$ Find/bin-name'f*' -/bin/Find the/bin/Fgrep -/bin/findmnt -/bin/false -/bin/Fusermount +[Email protected] bin]$ Find-size 60k -./sed
View Code
' Locate ' command
Installation: Yum Install Mlocate
Locate is a search in the database by file name, the name of the file to find the string contained in the search data faster. The search database is:/var/lib/mlocate/mlocate.db, this database, automatically updated daily, before using locate, you can manually update the database using the UpdateDB command.
Initialization: sudo updatedb
1 [[email protected] ~]$ sudo yum install mlocate23 [[email protected] ~]$ sudo up Datedb4 [[email protected] ~]$ Locate ff*5 /home/tree/ff1.txt6 /home/tree/ Ff2.txt 7 /home/tree/ff3.txt8
View Code
1[[Email protected] ~]$ ls2 a B ff.py pass3[[Email protected] ~]$ Locate ff.py4/home/tree/ff.py5/usr/lib/python2.6/toaiff.py6/usr/lib/python2.6/Toaiff.pyc7/usr/lib/python2.6/Toaiff.pyo8[[Email protected] ~]$ Touch shishi.py9[[Email protected] ~]$ lsTen a B ff.py pass shishi.py One[[Email protected] ~]$ Locate shishi.py A[[Email protected] ~]$ Locate shishi.py -[[Email protected] ~]$ sudo updatedb -[sudo] Password forTaka: the[[Email protected] ~]$ Locate shishi.py -/home/tree/shishi.py
' grep ' string search command
Search for a qualifying string in a file containing a match that contains a line from a string
You can use regular expressions to match the content.
Command format: grep [options] string file name
Common options:
-N Display Line number
-I ignores case
-V excludes the specified string
1[[email protected] ~]$ grep root/etc/passwd2ROOT:X:0:0: root:/root:/bin/Bash3 operator: x: One:0:operator:/root:/sbin/Nologin4[Email protected] ~]$ grep-n root/etc/passwd5 1: root:x:0:0: root:/root:/bin/Bash6 One:operator: x: One:0:operator:/root:/sbin/Nologin7[Email protected] ~]$ grep-v root/etc/passwd
# 2. Piping
The output of one program or command as input to another program or command
The pipeline can connect a series of commands, and the output of the preceding command can be used as input to subsequent commands. Use pipe symbol ' | ' To create a pipe line.
1 [[email protected] ~]$ Mans Man
2 [[email protected] ~]$ Man Mans | more
# # # # 3. Output
```
Standard output Echo
Output redirection:
> writes the content to a file, and if the file exists, it deletes the original content.
>> write content to the end of a file
1[Email protected] ~]$ Echo123452 123453[[Email protected] ~]$ ls4 a B ff.py pass shishi.py5[Email protected] ~]$ Echo12345>ff.py6[[Email protected] ~]$ Cat ff.py7 123458[Email protected] ~]$ cat/etc/passwd >>ff.py9[[Email protected] ~]$ Cat ff.pyTen One[email protected] ~]$ Cat ff.py | grep-N Root A 2: root:x:0:0: root:/root:/bin/Bash - A:operator: x: One:0:operator:/root:/sbin/nologin
# 4.vim Editor
Install Vim
Yum Install vim
Operating mode: Command mode, input mode, last line mode
Switch between modes,
Press ESC multiple times to enter command mode
In command mode, press I or O or a to enter input mode
In command mode, press shift+; , the last line appears: The colon enters the last line mode
Press ESC to return to command mode
Entry and exit:
VI FileName Entry
When you open a file in command mode
Enter Q Exit file in last line mode
Wq Save exit
Q! Do not save exit
Move cursor
Command mode and edit mode can be used up and down keys (or h,j,k,l)
Enter text
in command mode
Press I to insert data from before the cursor position
Press A to enter data after the cursor position
Press O to add a row below the cursor line and enter the input mode
After entering the input mode,--insert--will appear in the last line
Copy and paste
in command mode
YY copy entire line contents to VI buffer
YW copy the current cursor to the end of the word to the VI buffer
y$ Copy the contents of the current cursor to the end of the line to the VI buffer
y^ Copy the contents of the current cursor to the beginning of the line to the VI buffer
P reads the contents of the vi buffer and pastes it to the current position of the cursor
Delete and modify
Command mode
DD deletes the cursor in the row
x Delete the character of the cursor
U Undo Last Action
Save document
: Q End Edit does not save exit, if any modification does not exit
: q! Discard the changes you made to force exit
: W Save changes
: Wq Save changes and exit
# 5.alias Aliases
View aliases ' Alias '
Define the command alias format: alias new command = ' original command-options/Parameters '
[[Email protected] ~]$ alias Llalias ll='ls-l--color=auto'~]$ alias la=< c5> 'ls-a'
Alias: ' Unalias ' Alias
1 [[email protected] ~]$ unalias la
2 [[email protected] ~]$ la
3 -bash:la:command not found
This way of defining aliases is only valid at the time of the login, if you want to permanently define the effective, you can modify the user (not all users) their own ' alias ', modify the ~/.BASHRC file, add their own definition of ' alias ' in the file.
This modification will take effect the next time you log in, and if you want to take effect immediately, enter ' source ~/.BASHRC '.
Linux file operations