A total of 73 daily shell commands, there is always one you need!
1. Check if the remote port is open to bash:
Echo > / dev/tcp/8.8.8.8/53 & & echo "open"
two。 Let the process go to the background:
Ctrl + z
3. Move the process to the foreground:
Fg
4. Produces a random hexadecimal number, where n is the number of characters:
Openssl rand-hex n
5. Execute a command in a file in the current shell:
Source / home/user/file.name
6. Intercept the first five characters:
${variable:0:5}
7.SSH debug mode:
Ssh-vvv user@ip_address
8.SSH with pem key:
Ssh user@ip_address-I key.pem
9. Grab the complete website directory structure with wget and store it in the local directory:
Wget-r-no-parent-reject "index.html*" http://hostname/-P / home/user/dirs
10. Create more than one directory at a time:
Mkdir-p / home/user/ {test,test1,test2}
11. List the process trees that include child processes:
Ps axwef
twelve。 Create a war file:
Jar-cvf name.war file
13. Test the hard drive write speed:
Dd if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm-rf / tmp/output.img
14. Test the hard drive read speed:
Hdparm-Tt / dev/sda
15. Get the md5 hash of the text:
Echo-n "text" | md5sum
16. Check the xml format:
Xmllint-noout file.xml
17. Extract tar.gz to a new directory:
Tar zxvf package.tar.gz-C new_dir
18. Use curl to get HTTP header information:
Curl-I http://www.example.com
19. Modify the timestamp of a file or directory (YYMMDDhhmm):
Touch-t 0712250000 file
20. Use the wget command to perform the ftp download:
Wget-m ftp://username:password@hostname
21. Generate a random password (16 characters long in the example):
LANG=c
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo; 22.快速备份一个文件: cp some_file_name{,.bkp} 23.访问Windows共享目录: smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir 24.执行历史记录里的命令(这里是第100行): !100 25.解压: unzip package_name.zip -d dir_name 26.输入多行文字(CTRL + d 退出): cat >Test.txt
twenty-seven。 Create an empty file or empty an existing file:
\ > test.txt
twenty-eight。 Synchronize time with Ubuntu NTP server:
Ntpdate ntp.ubuntu.com
twenty-nine。 Use netstat to display all tcp4 listening ports:
Netstat-lnt4 | awk & apos; {print $4} & apos; | cut-f2-d: | grep-o & apos; [0-9] * & apos
30.qcow2 image file conversion:
Qemu-img convert-f qcow2-O raw precise-server-cloudimg-amd64-disk1.img\ precise-server-cloudimg-amd64-disk1.raw
thirty-one。 Run the file repeatedly to show its output (the default is once every 2 seconds):
Watch ps-ef
thirty-two。 List of all users:
Getent passwd
33.Mount root in read/write mode:
Mount-o remount,rw /
thirty-four。 Mount a directory (this is the case where links cannot be used):
Mount-- bind / source / destination
thirty-five。 Dynamically update DNS server:
Nsupdate
< 1048576) print $7/1048576 "MB "$9 }' | sort -n -u | tail 38.显示剩余内存(MB): free -m | grep cache | awk '/[0-9]/{ print $4" MB" }' 39.打开Vim并跳到文件末: vim + some_file_name 40.Git 克隆指定分支(master): git clone git@github.com:name/app.git -b master 41.Git 切换到其它分支(develop): git checkout develop 42.Git 删除分支(myfeature): git branch -d myfeature 43.Git 删除远程分支 git push origin :branchName 44.Git 将新分支推送到远程服务器: git push -u origin mynewfeature 45.打印历史记录中最后一次cat命令: !cat:p 46.运行历史记录里最后一次cat命令: !cat 47.找出/home/user下所有空子目录: find /home/user -maxdepth 1 -type d -empty 48.获取test.txt文件中第50-60行内容: < test.txt sed -n '50,60p' 49.运行最后一个命令(如果最后一个命令是mkdir /root/test, 下面将会运行: sudo mkdir /root/test): sudo !! 50.创建临时RAM文件系统 - ramdisk (先创建/tmpram目录): mount -t tmpfs tmpfs /tmpram -o size=512m 51.Grep whole words: grep -w "name" test.txt 52.在需要提升权限的情况下往一个文件里追加文本: echo "some text" | sudo tee -a /path/file 53.列出所有kill signal参数: kill -l 54.在bash历史记录里禁止记录最后一次会话: kill -9 $$ 55.扫描网络寻找开放的端口: nmap -p 8081 172.20.0.0/16 56.设置git email: git config --global user.email "me@example.com" 57.To sync with master if you have unpublished commits: git pull --rebase origin master 58.将所有文件名中含有"txt"的文件移入/home/user目录: find -iname "*txt*" -exec mv -v {} /home/user \; 59.将文件按行并列显示: paste test.txt test1.txt 60.shell里的进度条: pv data.log 61.使用netcat将数据发送到Graphite server: echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000 62.将tabs转换成空格: expand test.txt >Test1.txt
63.Skip bash history:
< space >Cmd
sixty-four。 Go to the previous working directory:
Cd-
sixty-five。 Split the large tar.gz file (each 100MB) and merge it back:
Split-b 100m / path/to/large/archive / path/to/output/filescat files* > archive
sixty-six。 Use curl to get HTTP status code:
Curl-sL-w "% {http_code}\\ n" www.example.com-o / dev/null
sixty-seven。 Set the root password to strengthen the MySQL security installation:
/ usr/bin/mysql_secure_installation
sixty-eight。 When Ctrl + c doesn't work:
Ctrl +\
sixty-nine。 Get the file owner:
Stat-c% U file.txt
70.block device list:
Lsblk-f
seventy-one。 Find the file with a space at the end of the file name:
Find. -type f-exec egrep-l "+ $" {}\
seventy-two。 Find files with tab indents in their names
Find. -type f-exec egrep-l $& apos;\ tgift apos; {}\
seventy-three。 Print a horizontal line with "=": copy it all and put it in your notes.
Printf & apos;0s\ nroomapos; | tr & apos; & apos; =
Article source: Ma GE Education
Official Wechat: Ma GE linux operation and maintenance staff
Technology Exchange Group: 485374463