Linux Simple to use
1. Basic Commands
Create directory Patha:mkdir Patha
Go to catalogue PATHA:CD Patha
View Catalog contents: ls
To view the files in the directory for more information: Ls-l, can also be: ll (l is lowercase l, don't look wrong)
Copy file FileA to directory Patha (same-level directory premise): CP FileA PATHB
Copy directory Patha (including all directories) to directory PATHB (same-level directory premise): Cp-r Patha PATHB
deleting files Filea:rm FileA
Delete directory Patha (including all of the directories): Rm-r Patha
Move all of the/usr/test directories to the current directory: mv/usr/test/*.
Package Patha in gzip compression: Tar zcvf pathA.tar.gz Patha
Decompression PathA.tar.gz:tar ZXVF pathA.tar.gz
Establish a soft connection for FileA slfilea:ln-s FileA Slfilea (L is lowercase l, don't look wrong)
Establish a hard connection Hlfilea:ln FileA Hlfilea for FileA
View All processes: Ps-aux
Kill a process (specify process with process ID): kill-9 process ID
Refresh Displays the end of the FileA (actual work used to view the log dynamically): Tail-f FileA
Emptying FileA (such as emptying log files): Truncate-s 0 FileA
2. file Permissions
View information about permissions in the current directory: Ls-l
The first field of the output is the encoding that describes the file and directory permissions.
The first character of the field gem file type:
-Representative documents
D Stands for Directory
L representative Link
C stands for the character type device
b Represents a block device
n Represents a network device
The following three characters define 3 access rights:
R stands for file readable
W stands for file writable
X represents file Executable
Access rights are divided into three groups, a set of three characters (RWX), if there is no permission to use "-". The first set of objects of the owner, the second set of objects of the genus Group, the third group of the system to provide other users.
Example: The owner of the Readme.txt file is given readable writable, and other read-only permissions are granted: chmod 644 Readme
3.Vim Simple to use
View FileA files: Vim FileA
Edit FileA file: Vim FileA---> Insert key---> Move cursor to edit---> Edit End Press ESC to end edit
Save and exit Edit Filea:shift key +;---> Wq---> Enter
Discard previous changes and exit: SHIFT +;--->!q---> Enter
Free copy: v---> Move the mouse to select what needs to be copied (starting at the cursor start position)---> y
Copy one line: yy
Copy all: GG---> v---> Shift key +g---> y
Free Cut: v---> Move the mouse to select what needs to be copied (starting at the cursor start position)---> D
Paste: P
Find test: Enter the command in VIM:/test (press N again to find the next, press N to look up)
The basic Linux commands below are basically available commands, with only a few common parameters added.
- CD: Switch directories
cd /root
- mkdir: Creating Files
mkdir /root/test
Creating directories requires that the root directory exists
mkrir -p /root/test
Looping through the creation of catalogs
- Touch: Create Text
- Vim: Text editing, Vim divided into edit mode and instruction mode
- Input I into edit mode in instruction mode, ESC exits edit mode to instruction mode
- In instruction mode, enter the line number to exit as a
;q
forced exit for exit :wq
after saving q!
:set nu
- Echo: Print content
echo "this is out"
- Cat: View Content
cat 文件名
- CP: Copying files
cp test.txt /root/test
Assignment test to Path/root/test
cp -apr /root/test /root/testcopy
Copy Directory
- PWD: View current path
- MV: Moving files
mv test.sh /root/test
- RM: Deleting files
rm test.txt
Delete this file
rm -fr /root/test
-r: Delete this directory-F: No prompt message, delete directly
- grep: You can pass regular expressions when filtering
grep ‘test’ d*
Displays all rows that contain test in a file that begins with D.
grep ‘[a-z]\{5\}’ aa
Displays all rows that contain a string of at least 5 consecutive lowercase characters for each string.
- Head: Displays the n rows of the file's head
head -n 5 log2014.log
Display the first five lines, default to the first 10 rows
- Tail: Displays n rows at the end of a file
tail -n 5 log2014.log
Print n rows from tail default to 10
- Find: Finding
- Results in find can be handled by pipelines
find -name filename #查找名为filename的文件
- SEQ: print n digits
seq 1 5
Printed from 1 to 5
seq 1 2 5
Print from 1 to 5 with a step size of 2
seq -s "z" 1 5
Connect the 1-5 with Z.1z2z3z4z5
- SED: A good line of action
sed -n /a/p t.txt
Filter output specified content -n
//Output only filter result /a
//filter rule (contains a)// /p
Output
sed -n 20,30p t.txt
Take 20-30 rows of output
sed -i s#aaa#goo#g t.txt
Replace AAA in T.txt with Goo, -i
//Replace file contents
- Xargs:xargs to do some file operation with the channel, for example,
find -type f -name "*.log"|xargs -i rm {}
Delete all the log types of files
-i
: parameter can replace the standard output of the pipeline directly with {}find -type f -name "*.log"|xargs -i rm {}
-I
: parameter requires the substitution character to be specified beforehandfind -type f -name "*.log"|xargs -I {c} rm {c}
find / -type f -name "t.txt"|xargs -i sed s#aa#mmmmm#g
Change the contents of all files named T.txt to Mmmmm
- awk: An operation that specializes in columns
awk -F "," ‘{print $1}‘ localhost.2017-10-12.log
Find the first column in a file, split
Linux Simple to use