Shell Commands
First, understanding Shell
In the Linux system, Shell acts as a bridge users and the Linux kernel, commonly known as shell protects the Linux kernel, is also responsible for the completion of the interaction between the user and the kernel.
When the user needs to interact with the kernel, the command is transmitted to Shell, and then by Shell command analysis command to the kernel can be appreciated, the operating system and then responds to the control hardware, and finally return the results to the user by Shell.
After years of development, by different organizations for different purposes, the development of many different types of Shell program. Shell popular main categories:
- Bourne Shell
- Bourne Again Shell
- C Shell
- K Shell
- Shell for Root
Bourne Again Shell referred Bash, due to the ease of use and free, Bash is widely used in daily work. Meanwhile Bash is the default most Linux systems Shell.
Two, Shell Command
(1) file directory class
1.pwd
Function: Display the current absolute path
2.ls
Function: Display information about files and directories
ls displays the contents of the current directory to default
All files including hidden files ls -a show
ls -l show details
3.cd
Function: Change directory
Switch to the directory dir dir CD
cd / change to the root directory
cd .. to switch to the parent directory
cd ~ handover to the user directory, such as the root user is switched in / root
4.mkdir
Function: Create a directory
Create a directory mkdir aa aa
mkdir a / b / c -p create multi-level directory
5.rm
Function: delete a file or directory
rm 1.txt 1.txt delete files
rm aa -r delete a folder aa
6.cp
Function: Copy a file or directory
cp 1.txt ./dest/ 1.txt to copy the directory dest
CP 1.txt 1.txt 3.txt copied to the same directory 3.txt
cp aa ./dest/ -r aa copy the folder to the next dest directory
7.mv
Function: Move command
mv 1.txt ./dest/ 1.txt to copy the directory dest
mv 1.txt 3.txt 1.txt will be renamed 3.txt
mv aa ./dest/ -r move to the next folder aa dest directory
8.cat
Function: Display the contents of the file
as 1.cpp
9.head、tail
Function: head display 10 lines before the files (default)
Function: tail displays the file after 10 lines (default)
10.touch
Function: Create a file or modify file timestamps
11.du
Function: display the specified directories or files take up more disk space
du -sh / home to K, M, G is the total size of the display unit of the home
12.ln
Function: to establish soft and hard-wired connection
ln -s dir linkdir to create a soft link dir linkdir
13.find
Function: Find
find / home -type f -name "1.c" Find 1.c file in your home directory
find ./ -type f -name "* .txt" in the current directory to find all the txt file
14.file
Function: display the file types
file 1.txt
file a.out
15.which
Features: Find files in your PATH
Find the path which ls ls
(2) Management System
1.shutdown 、reboot
Function: shut down or restart your computer
shutdown -h now
shutdown -r +10 10 minutes after restarting
shutdown -c cancel the restart or shutdown
reboot reboot
2.su
Function: Switch user
SU farsight to a farsight user switching
su - to root, while using the user environment
3.adduser
Features: Add User
adduser farsight
4.passwd
Function: Set or change user passwords
passwd user to modify user password
5.chown
Change the owner of a file or directory: Function
chown farsight / dir dir will be set for all users farsight
6.chmod
Function: to modify the file permissions
chmod 777 1.sh
chmod +x 1.sh
7.sudo
Function: for identity in other capacities to execute the command, the default is root
8.man
Function: Help command
man 1 ls ls command to view the manual
man 2 socket View socket function manual
9.clear
Features: clear screen
10.echo
Function: string output
echo "hello" output string hello
echo $ PATH PATH variable output
(3) archiving compression class
1.gzip gunzip
Function: Unzip the file
compressed gzip 1.txt 1.txt
gunzip -f file.gz extracting file
2.tar
Function: Unzip the file
packet decompression tar -vxf file.tar
tar -xzvf file.tar.gz 解压 tar.gz
tar -cvf file.tar dir The dir compression packing
(4) Process Management
1.ps
Function: Display process information
ps -ef The system displays detailed current process
ps -aux display all trips include other users
2.pstree
Function: all trips in tree
3.top
Features: real-time display of dynamic process
4.kill
Function: to process signal
to kill -signum pid pid signal
the end of the process kill pid pid
(5) Management Software
1.apt
Function: the software management
apt-get install nginx 安装nginx
apt-get update update source
apt-get upgrade software upgrade
apt-get remove cmatrix remove software
apt-get check to confirm correct resolution of dependencies
apt-get clean clean up cache
2.dpkg
Function: the software management
deb packages installed dpkg -i package.deb
dpkg -r package_name remove software
dpkg -l show all deb packages already installed system
dpkg -L cmatrix displays a list of files provided by the software cmatrix
dpkg --contents package.deb display a list of files in a package not yet installed the provided
dpkg -S / bin / ping ping command to confirm which provides a deb package
(6) based text processing
1.wc
Features: Statistics Text File
The number of rows wc -l 1.txt 1.txt of statistics
wc -w 1.txt 1.txt statistics of words
The number of bytes wc -c 1.txt 1.txt of statistics
2.grep
Function: Filter from a standard input file or content matching mode
ps -ef | grep "nginx" display process information on nginx
grep "jack" * .txt query keywords jack in all the txt file
Keyword id grep -r "id" * recursive search for all files
grep -n root / etc / passwd The / etc / passwd, there occurs root lines taken out line numbers
dmesg | grep -n --color=auto 'eth'
dmesg list contains core information eth find that line, and coloring
grep -f a.txt b.txt b output the same file in a file line
echo "A ab c" | xargs -n1 | -ia beginning grep matching case-insensitive word
grep -E -v "^ $ | ^ #" file.txt file to remove blank lines or lines beginning with # numbers
grep -r '192.168.1.1' / etc --include * .conf conf file matches the specified ip
3.sed
Function: Flow Editor, filtered and replacing text
sed -n '3,9p' file.log outputs the third row to the ninth row
sed -n '/ aaa /, / bbb / p' file.log aaa output from the start to the end of the row bbb
sed -i 's / string1 / string2 / g' file "string1" file.txt to replace "string2"
sed '/ ^ $ / d' file.txt Delete all blank lines from a file
sed '/ * # / d; / ^ $ / d' test.c removes all comments and blank lines from a file
sed -e '1d' file.txt excluded from the first line of the file
sed -e 's / * $ //' file.txt Delete end of each row of blank characters
sed -e 's / 00 * / 0 / g' file.txt replaced by a single multiple zero zero
4.awk
Function: awk is a programming language text processing tools, can handle short program or the standard input file, sort data, calculations, and generate reports, etc.
tail -n3 / etc / services | awk '{print $ 2}' output from the second field
awk -F ':' '{print $ 1}' / etc / passwd colon designated print the first field delimiter
tail / etc / services | awk '/ tcp / {print $ 0}' contains the line matching the tcp
tail / etc / services | awk '/ ^ [a-z0-9] {8} / {print $ 0}' matches the first field is the eight-character line
tail /etc/services |awk 'BEGIN{print"Service\t\tPort\t\t\tDescription\n==="}{print
$ 0} 'Print header
tail / etc / services | awk '/ blp5 / && / tcp / {print $ 0}' recording blp5 rows and tcp
echo "www.baidu.com/user/test.html" | awk 'BEGIN {RS = "/"} {print $ 0}' to / divided
tail -n2 / etc / services | awk 'BEGIN {RS = "/"; ORS = "#"} {print $ 0}' replacement character
(7) based network
1.ping
Function: Used to confirm the network connection is unblocked, network speed test
ping www.baidu.com
2.ifconfig、ifup、ifdown
Function: View user network configuration
ifconfig eth0 show configuration of an ethernet card
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 to set the address
Enable eth0 ifup eth0
ifdown eth0 eth0 disabled
3.ssh
Features: remote login to other hosts
ssh -l root 192.168.1.1 // login as root 192.168.1.1
4.scp
Function: to copy files and directories between Linux
file scp / root: [email protected] host / root file at copy the files to a directory to 192.168.1.1 ip
scp [email protected]: /root/1.c ./ copy ip 192.168.1.1 host for the next 1.c root directory of the current directory files to the local host
5.telnet
Function: Remote login TELNET protocol
telnet 192.168.1.1 ip login specified
telnet 192.168.1.1 6666 to log the specified ip and port
the Telnet www.baidu.com log on designated website
6.route
Function: View the routing information
route Display the routing information.
route add -host 192.168.1.66 dev eth0 add routes
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 Add 192.168.1.0 subnet routing and gateway to
route add default gw 192.168.3.1 add a default gateway address 192.168.3.1
route del -host 192.168.1.66 dev eth0 delete routes
route change 192.168.1.0 mask 255.255.255.0 192.168.3.123 subnet 192.168.1.0 next-hop address is set to 192.168.3.123
7.netstat
Function: display various network-related information
netstat shows the machine network connection.
netstat -a show all the information linked
netstat -l lists the socket in listening
netstat -ac refresh once every second until the user interrupts the display.
netstat -i display the list of network interfaces
netstat -r Displays the routing table.
netstat -an | grep ': 22' to identify processes running on the specified port
netstat -apn | grep ssh port to find the running program
netstat -st display TCP port information.
netstat -su displays UDP port information.
netstat -s to display statistics for each protocol.
8.iptables
Function: Firewall Settings
See iptables -L -n native iptables
iptables -F Clear filter preset table all the rules in the rule chain
iptables -X Clear filter preset table in user defined chain rule
service iptables restart restart firewall
iptables -A INPUT -p tcp --dport 80 -j ACCEPT open port 80
iptables -A INPUT -s 192.168.3.126 -p tcp --dport 22 -j ACCEPT limit specified log ip ssh
iptables -t filter -A INPUT -s 192.168.1.66 -i eth0 -j DROP designated ip prohibit access to the machine from eth0
iptables -I FORWARD -s 192.168.1.66 -j DROP prohibit specified ip access
iptables -A FORWARD -f -m limit --limit 200/s --limit-burst 200 -j ACCEPT
Deal with the number of ip fragments