For friends who often use linux systems, the basic common shell commands are indispensable. the following article summarizes the commonly used commands of Linuxshell. if you need them, you can refer to them for reference, let's study together. Preface
Using Linux shell is a basic task for some programmers every day, but we often forget some useful shell commands and techniques. Of course, I can remember commands, but I can't remember how to use them to execute a specific task. Note that you need to install additional software in your Linux system. I will not talk about it much below. let's take a look at the details.
Check whether the remote port is open to bash:
Echo>/dev/tcp/8.8.8.8/53 & echo "open"
Transfer the process to the background:
Ctrl + z
Switch the process to the foreground:
Fg
Generate a random hexadecimal number, where n is the number of characters:
Openssl rand-hex n
Execute the command in a file in the current shell:
Source/home/user/file. name
Extract the first five characters:
$ {Variable: 0: 5}
SSH debug mode:
Ssh-vvv user @ ip_address
SSH with pem key:
Ssh user @ ip_address-I key. pem
Use wget to capture the complete website directory structure and store it in the local directory:
Wget-r -- no-parent -- reject "index.html *" http: // hostname/-P/home/user/dirs
Create multiple directories at a time:
Mkdir-p/home/user/{test, test1, test2}
List the process trees that contain sub-processes:
Ps axwef
Create a war File:
Jar-cvf name. war file
Test hard disk write speed:
Dd if =/dev/zero of =/tmp/output. img bs = 8 k count = 256 k; rm-rf/tmp/output. img
Test hard disk read speed:
Hdparm-Tt/dev/sda
Obtain the md5 hash of text:
Echo-n "text" | md5sum
Check xml format:
Xmllint -- noout file. xml
Extract tar.gz to the new directory:
Tar zxvf package.tar.gz-C new_dir
Use curl to obtain HTTP header information:
Curl-I http://www.example.com
Modify the timestamp of a file or directory (YYMMDDhhmm ):
Touch-t 0712250000 file
Run the wget command to download ftp:
Wget-m ftp: // username: password @ hostname
Generate a random password (in this example, it is 16 characters long ):
LANG = c </dev/urandom tr-dc _ A-Z-a-z-0-9 | head-c $ {1:-16}; echo;
Quickly back up a file:
Cp some_file_name {,. bkp}
Access the Windows shared directory:
Smbclient-U "DOMAIN \ user" // dc.domain.com/#/test/dir
Execute the commands in the history (here is the 100th Line ):
! 100
Decompress:
Unzip package_name.zip-d dir_name
Enter multiple lines of text (CTRL + d to exit ):
Cat> test.txt
Create an empty file or clear an existing file:
\> Test.txt
Synchronization time with Ubuntu NTP server:
Ntpdate ntp.ubuntu.com
Use netstat to display all tcp4 listening ports:
Netstat-lnt4 | awk '{print $4}' | cut-f2-d: | grep-o '[0-9] *'
Qcow2 image file conversion:
Qemu-img convert-f qcow2-O raw precise-server-cloudimg-amd64-disk1.img \ precise-server-cloudimg-amd64-disk1.raw
Run the file repeatedly and display its output (the default value is 2 seconds ):
Watch ps-ef
List of all users:
Getent passwd
Mount root in read/write mode:
Mount-o remount, rw/
Mount a directory (this is the case where the link cannot be used ):
Mount -- bind/source/destination
Dynamically update the DNS server:
Nsupdate <
Recursive grep all directories:
Grep-r "some_text"/path/to/dir
List the top 10 largest files:
Lsof/| awk '{if ($7> 1048576) print $7/1048576 "MB" $9}' | sort-n-u | tail
Show remaining memory (MB ):
Free-m | grep cache | awk '/[0-9]/{print $4 "MB "}'
Open Vim and jump to the end of the file:
Vim + some_file_name
Git clone the specified branch (master ):
Git clone git@github.com: name/app. git-B master
Switch Git to another branch (develop ):
Git checkout develop
Myfeature ):
Git branch-d myfeature
Git deletes a remote branch
Git push origin: branchName
Git pushes the new branch to the remote server:
Git push-u origin mynewfeature
Print the last cat command in the history:
! Cat: p
The last cat command in the running history:
! Cat
Find all empty sub-directories under/home/user:
Find/home/user-maxdepth 1-type d-empty
Line 50-60 in the test.txt file:
<Test.txt sed-n '50, 60p'
Run The Last Command (if the last command is mkdir/root/test, run: sudo mkdir/root/test ):
Sudo !!
Create a temporary RAM file system-ramdisk (first create the/tmpram directory ):
Mount-t tmpfs/tmpram-o size = 512 m
Grep whole words:
Grep-w "name" test.txt
Append the text to a file when you need to escalate permissions:
Echo "some text" | sudo tee-a/path/file
List all kill signal parameters:
Kill-l
Do not record the last session in the bash history:
Kill-9 $
Scan the network to find open ports:
Nmap-p 8081 172.255.0.0/16
Set git email:
Git config-global user. email "me@example.com"
To sync with master if you have unpublished commits:
Git pull -- rebase origin master
Move all files whose names contain "txt" to the/home/user directory:
Find-iname "* txt *"-exec mv-v {}/home/user \;
Display files in parallel by row:
Paste test.txt test1.txt
Shell progress bar:
Pv data. log
Use netcat to send data to Graphite server:
Echo "hosts. sampleHost 10 'date + % s" '| nc 192.168.200.2 3000
Convert tabs to a space:
Expand test.txt> test1.txt
Skip bash history:
<Space> cmd
Go to the previous working directory:
Cd-
Split the tar.gz File (100 MB each) and merge it back:
Split-B 100 m/path/to/large/archive/path/to/output/files cat files *> archive
Use curl to obtain the HTTP status code:
Curl-sL-w "% {http_code} \ n" www.example.com-o/dev/null
Set the root password to enhance the secure installation of MySQL:
/Usr/bin/mysql_secure_installation
When Ctrl + c is not easy to use:
Ctrl + \
Get the file owner:
Stat-c % U file.txt
Block device list:
Lsblk-f
Find the file with spaces at the end of the file name:
Find.-type f-exec egrep-l "+ $ "{}\;
Find the file with tab indentions in the file name.
Find.-type f-exec egrep-l $ '\ t '{}\;
Print the horizontal line with "=": Select all copies and put them into notes.
Printf '% 100s \ n' | tr'' =
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. if you have any questions, please leave a message.
For more articles about 73 commands commonly used in Linux shell, refer to the PHP Chinese network!