1. Basic shortcut key Usage
CTRL + C: Stop process
CTRL + L: Clear screen
CTRL + R: Search History commands
CTRL + Q: Exit
2. Common directory or folder commands
Description: When installing Linux, create a itcast user and then log into the system using the root user
1. Go to the user root directory
CD ~ or CD
2. View your current directory
Pwd
3. Go to the Itcast user root directory
CD ~itcast
4. Return to the original directory
CD-
5. Go back to the top level directory
Cd..
6. View all files under the Itcast user's root directory
-A is an explicit hidden file-L is displayed in a more detailed list
Ls-la
7. Create a Itcast folder in the root directory
Mkdir/itcast
8. Create SRC and webroot two folders under the/itcast directory
Created separately: MKDIR/ITCAST/SRC
Mkdir/itcast/webroot
Create simultaneously: Mkdir/itcast/{src,webroot}
9. Folder Permission Description
Ls-ld/tmp
The permission value of DRWXRWXRWT is 1777
3. File commands 1. view file Details
Stat A.txt
2. Mobile
MV a.txt/ect/
Renamed
MV B.txt A.txt
Move and rename
MV A.txt. /b.txt
3. Copy and rename
CP A.txt/etc/b.txt
4.VI undo Changes
CTRL + U (undo)
Recovery
CTRL + R (Redo)
5. Use > To create a struts.xml
> Struts.xml
6. Create multiple files with touch
Touch A.txt B.txt
Touch/home/{a.txt,b.txt}
7. Create a file using Echo
Create a Test.txt file under the/itcast directory and write the content "This is test"
echo "This is Test" > Test.txt
Append write to Readme file "Please read Me first"
echo "Please read Me first" >> README
8. Copy file contents using Cat
Copy the contents of one file into another file
Cat A.txt > B.txt
Append content
Cat A.txt >> B.txt
Note the:>, Touch, Echo, and cat comparisons to file operations
①> can only create a single file;
②touch can create single or multiple files, unable to insert content into files;
③echo creates a file and inserts a line of string into the file, manipulating a single-line string;
④cat creates a file and inserts all the contents of another file into the new file, manipulating the entire file.
9. Take a look at the contents of Test.txt
Cat Test.txt
More Test.txt
Less test.txt
Note: More or less is paged view
10.CP Copy specific files
Copy all Java language programs to the finished subdirectory:
CP *.java finished
11.RM Delete a specific file
Delete the file with the Java extension in the current directory
Rm-f *.java
Delete Empty Directory
RmDir
12.WC Statistics File
See how many words the Readme file has, how many fewer lines
Wc-w README
Wc-l README
13.VI Editing file contents
VI Somefile.txt
① first enters the "General mode", which accepts only a variety of shortcut keys and cannot edit the contents of the file.
② Press i key, will go from the general mode into the editing mode, this mode, typed is the file content
③ after editing is complete, press ESC to exit the edit mode and return to the general mode;
④ Press:, enter the "Bottom line command mode", enter the Wq command, return to
Some useful shortcut keys (used in general mode):
A after the cursor one begins inserting
A in the last insert of the line
I insert at the front of the line
GG jumps directly to the first line of the file
G jump directly to the last line of the file
DD Delete Row, if 5dd, then delete the cursor 5 lines at once
yy copies the current row, copies multiple rows, then 3yy copies the 3 rows near the current row
P Paste
V Enter the character selection mode, select Done, press Y to copy, press p to paste
Ctrl + V into block selection mode, select Done, press Y to copy, press p to paste
Shift+v Enter row selection mode, select Done, press Y to copy, press p to paste
Find and replace (entered in command mode in the bottom line)
%s/sad/88888888888888 effect: Find all sad in file, replace with 88888888888888
/you effect: Find you in the file and navigate to the first found place, press N to navigate to the next matching position (press N to the previous one)
4. File and folder permissions command 1.linux file Permissions description format interpretation
Drwxr-xr-x (can also be expressed in decimal notation 755)
D: Identify node type (d: folder-: File L: Link)
R: Readable w: writable x: Executable
The first set of RWX: Represents the permissions of the owner of the file to it: a readable writable executable
The second set of R-x: Represents the permissions of the group to which this file belongs: readable, non-writable, executable
The third group of R-x: Represents the permissions of other users of this file (as compared to the above two categories of users) to it: readable, non-writable, executable
2. Grant owner u, owning Group G, and other user o permissions to the file
chmod ug+w,o-w a.txt b.txt indicates that a.txt, B.txt is set to its owner and that the group can be written to, but other people are not writable
chmod a+wx C.txt says to set the C.txt file to everyone can write and execute
Chmod-r a+r/itcast means that all files and subdirectories in the/itcast directory are set to anyone who can read
chmod G-RW Haha.dat indicates that the RW permission for the owning group will be Haha.dat canceled
chmod o-rw Haha.dat means to cancel Haha.dat to other people's RW rights
5. Set up users and user groups
The owner of all files and subdirectories under the/itcast directory is set to root, and the user has a group of users
Chown-r Root:users/itcast
Sets all files in the current directory and subdirectories to Itcast, set to users
Chown-r Itcast:users *
Note: -R means recursive execution, recursive execution on files and directories
5. Find a command 1. Find an executable command
which LS
2. Find the location of the executable commands and help
Whereis ls
3. Find files (need to update Library: updatedb)
Locate Hadoop.txt
4. Start a search from a folder
Find/-name "hadooop*"
Find/-name "hadooop*"-ls
5. Find and delete
Find/-name "hadooop*"-ok rm {} \;
Find/-name "hadooop*"-exec rm {} \;
6. Find files for Hadoop for users
Find/usr-user Hadoop-ls
7. Find the file that the user is Hadoop and (-a) has a group root
Find/usr-user hadoop-a-group Root-ls
8. Look for a file with a user who has a group root and is a folder type for Hadoop or (-O)
Find/usr-user hadoop-o-group root-a-type D
9. Find a file with a permission of 777
Find/-perm-777-type D-ls
10. Show Command History
History
11.grep
grep Hadoop/etc/password
6. Packaging and Compression 1.gzip decompression
Compression
Gzip A.txt
Extract
Gunzip a.txt.gz
Gzip-d a.txt.gz
2.BZIP2 Decompression
Compression
Bzip2 A
Extract
BUNZIP2 a.bz2
Bzip2-d a.bz2
3.tar Decompression
Package the files of the current directory to compress
TAR-CVF Bak.tar .
Append the/etc/password file to the Bak.tar (R)
TAR-RVF Bak.tar/etc/password
Extract
TAR-XVF Bak.tar
4.tar.gz Decompression
Package and Compress gzip
TAR-ZCVF a.tar.gz
Unzip
TAR-ZXVF a.tar.gz
Unzip to the/usr/.
TAR-ZXVF a.tar.gz-c/usr
Viewing the contents of a compressed package
TAR-ZTVF a.tar.gz
5.TAR.BZ2 Decompression
Package and compress into bz2
TAR-JCVF a.tar.bz2
Decompression bz2
TAR-JXVF a.tar.bz2
6.zip Decompression
Zip/unzip
7. Regular expression commands 1. Find and cut-split intercept
Cut intercept to: divide and hold the seventh paragraph
grep hadoop/etc/passwd | Cut-d:-f7
2. Sorting sort
Du | Sort-n
3. Queries that do not contain Hadoop
Grep-v hadoop/etc/passwd
4. Regular expression contains Hadoop
grep ' Hadoop '/etc/passwd
5. Regular expression (dots represent any one character)
grep ' H.*p '/etc/passwd
6. Regular expression begins with Hadoop
grep ' ^hadoop '/etc/passwd
7. Regular expressions End with Hadoop
grep ' hadoop$ '/etc/passwd
Rules:
. : any one character
A *: Any number of a (0 or more a)
A? : 0 or one A
A +: one or more a
. *: Any number of arbitrary characters
\. Escape.
\O\{2\}: o repeat two times
grep ' ^i.\{18\}n$ '/usr/share/dict/words
Find lines that do not start with #
Grep-v ' ^# ' a.txt | Grep-v ' ^$ '
Starting with H or R
grep ' ^[hr] '/etc/passwd
Not starting with H and R.
grep ' ^[^hr] '/etc/passwd
Not starting with H to R.
grep ' ^[^h-r] '/etc/passwd
8. Input and output redirection and piping 1. Create a new file
Touch A.txt
> B.txt
2. Error redirection:2>
Find/etc-name zhaoxing.txt 2> Error.txt
3. Enter the correct or incorrect information into the Log.txt
Find/etc-name passwd > /tmp/log.txt 2>&1
Find/etc-name passwd &> /tmp/log.txt
4. Append>>5. Convert lowercase to uppercase (input redirection)
TR "A-Z" "A-Z" </etc/passwd
6. Automatically create files
Cat > Log.txt << EXIT
> CCC
> DDD
> EXI
7. See how many files are in/etc
Ls-l/etc/| grep ' ^d ' | Wc-l
8. See how many files are in/etc, and enter the file details into the Result.txt
Ls-l/etc/| grep ' ^d ' | Tee Result.txt | Wc-l
9. User and Group command 1. Add a Tom user, set it to belong to the Users group, and add comment information
Step through: Useradd Tom
Usermod-g users Tom
Usermod-c "HR Tom" Tom
One-Step completion: Useradd-g users-c "hr Tom" Tom
2. Set the Tom User's password
passwd Tom
3. Add a Jerry user and set a password
Useradd Jerry
passwd Jerry
4. Change Tom User's login name to Tomcat
Usermod-l Tomcat Tom
5. Add tomcat to the SYS and root groups
Usermod-g Sys,root Tomcat
6. View the group information for Tomcat
Groups Tomcat
7. Add a America Group
Groupadd America
8. Add the Jerry user to the America Group
Usermod-g America Jerry
9. Remove the Tomcat user from the root group and the SYS group
gpasswd-d Tomcat Root
gpasswd-d Tomcat SYS
10. Change the America group name to AM
Groupmod-n am America
10. System commands 1. View Host Name
Hostname
2. Modify hostname (invalid after reboot)
Hostname Hadoop
3. Change the hostname (permanent after reboot)
Vi/ect/sysconfig/network
4. Modify IP (invalid after reboot)
Ifconfig eth0 192.168.12.22
5. Modify IP (permanent after reboot)
Vi/etc/sysconfig/network-scripts/ifcfg-eth0
6. View System Information
Uname-a
Uname-r
7. View ID Command
Id-u
Id-g
8. Date
Date
Date +%y-%m-%d
Date +%t
Date +%y-%m-%d ""%T
9. Calendar
Aa.
Cal 2012
10. View file Information
File filename
11. Mount the hard drive
Mount
Umount
Load Windows share
Mount-t CIFS//192.168.1.100/tools/mnt
12. View File Size
Du-h
Du-ah
13. View Partitions
Df-h
14. View Memory usage
Free
15. View the file system
/proc
16.ssh
SSH [email protected]
17. Turn off the machine
Shutdown-h Now/init 0
Shutdown-r Now/reboot
11. Process Control commands 1. View the user's most recent login status
Last
Lastlog
View current Online
W.H.O.
2. View the System log
ls/var/log/
3. Check the system error log
Tail/var/log/messages
Tail-f/var/log/messages
Tail-f/var/log/messages
4. View the process
Top
5. End Process
Kill 1234
Kill-9 4333
Linux Common Command Description