1.检查远程端口是否对bash开放:
1 |
echo >/dev/tcp/<span class="hljs-number">8.8.8.8</span>/<span class="hljs-number">53</span> && echo <span class="hljs-string">"open"</span> |
2.让进程转入后台:
1 |
Ctrl + z |
3、将进程转到前台:
1 |
fg |
4.产生随机的十六进制数,其中n是字符数:
1 |
openssl rand -hex n |
5.在当前shell里执行一个文件里的命令:
1 |
source /home/user/file.name |
6.截取前5个字符:
1 |
${variable:<span class="hljs-number">0</span>:<span class="hljs-number">5</span>} |
7.SSH debug 模式:
1 |
ssh -vvv user<span class="hljs-decorator">@ip_address</span> |
8.SSH with pem key:
1 |
ssh user<span class="hljs-decorator">@ip_address -i key.pem</span> |
9.用wget抓取完整的网站目录结构,存放到本地目录中:
1 |
wget -r --no-parent --reject <span class="hljs-string">"index.html*"</span> http://hostname/ -P /home/user/dirs |
10.一次创建多个目录:
1 |
mkdir -p /home/user/{test,test1,test2} |
11.列出包括子进程的进程树:
1 |
ps axwef |
12.创建 war 文件:
1 |
jar -cvf name.war file |
13.测试硬盘写入速度:
1 |
dd <span class="hljs-keyword">if</span>=/dev/zero of=/tmp/output.img bs=<span class="hljs-number">8</span>k count=<span class="hljs-number">256</span>k; rm -rf /tmp/output.img |
14.测试硬盘读取速度:
1 |
hdparm -Tt /dev/sda |
15.获取文本的md5 hash:
1 |
echo -n <span class="hljs-string">"text"</span> | md5sum |
16.检查xml格式:
1 |
xmllint --noout file.xml |
17.将tar.gz提取到新目录里:
1 |
tar zxvf package.tar.gz -C new_dir |
18.使用curl获取HTTP头信息:
1 |
curl -I http://www.example.com |
19.修改文件或目录的时间戳(YYMMDDhhmm):
1 |
touch -t <span class="hljs-number">0712250000</span> file |
20.用wget命令执行ftp下载:
1 |
wget -m ftp://username:password<span class="hljs-decorator">@hostname</span> |
21.生成随机密码(例子里是16个字符长):
1 |
LANG=c < /dev/urandom tr -dc _A-Z-a-z-<span class="hljs-number">0</span>-<span class="hljs-number">9</span> | head -c${<span class="hljs-number">1</span>:-<span class="hljs-number">16</span>};echo; |
22.快速备份一个文件:
1 |
cp some_file_name{,.bkp} |
23.访问Windows共享目录:
1 |
smbclient -U <span class="hljs-string">"DOMAIN\user"</span> //dc.domain.com/share/test/dir |
24.执行历史记录里的命令(这里是第100行):
1 |
!<span class="hljs-number">100</span> |
25.解压:
1 |
unzip package_name.zip -d dir_name |
26.输入多行文字(CTRL + d 退出):
1 |
cat > test.txt |
27.创建空文件或清空一个现有文件:
1 |
\> test.txt |
28.与Ubuntu NTP server同步时间:
1 |
ntpdate ntp.ubuntu.com |
29.用netstat显示所有tcp4监听端口:
1 |
netstat -lnt4 | awk <span class="hljs-string">'{print $4}'</span> | cut -f2 -d: | grep -o <span class="hljs-string">'[0-9]*'</span> |
30.qcow2镜像文件转换:
1 |
qemu-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img \precise-server-cloudimg-amd64-disk1.raw |
31.重复运行文件,显示其输出(缺省是2秒一次):
1 |
watch ps -ef |
32.所有用户列表:
1 |
getent passwd |
33.Mount root in read/write mode:
1 |
mount -o remount,rw / |
34.挂载一个目录(这是不能使用链接的情况):
1 |
mount --bind /source /destination |
35.动态更新DNS server:
1 2 3 4 |
nsupdate < <EOF update add $HOST <span class="hljs-number">86400</span> A $IP send EOF |
36.递归grep所有目录:
1 |
grep -r <span class="hljs-string">"some_text"</span> /path/to/dir |
37.列出前10个最大的文件:
1 |
lsof / | awk <span class="hljs-string">'{ if($7 > 1048576) print $7/1048576 "MB "$9 }'</span> | sort -n -u | tail |
38.显示剩余内存(MB):
1 |
free -m | grep cache | awk <span class="hljs-string">'/[0-9]/{ print $4" MB" }'</span> |
39.打开Vim并跳到文件末:
1 |
vim + some_file_name |
40.Git 克隆指定分支(master):
1 |
git clone git<span class="hljs-decorator">@github.com:name/app.git -b master</span> |
41.Git 切换到其它分支(develop):
1 |
git checkout develop |
42.Git 删除分支(myfeature):
1 |
git branch -d myfeature |
43.Git 删除远程分支
1 |
git push origin :branchName |
44.Git 将新分支推送到远程服务器:
1 |
git push -u origin mynewfeature |
45.打印历史记录中最后一次cat命令:
1 |
!cat:p |
46.运行历史记录里最后一次cat命令:
1 |
!cat |
47.找出/home/user下所有空子目录:
1 |
find /home/user -maxdepth <span class="hljs-number">1</span> -type d -empty |
48.获取test.txt文件中第50-60行内容:
1 |
< test.txt sed -n <span class="hljs-string">'50,60p'</span> |
49.运行最后一个命令(如果最后一个命令是mkdir /root/test, 下面将会运行: sudo mkdir /root/test):
1 |
sudo !! |
50.创建临时RAM文件系统 – ramdisk (先创建/tmpram目录):
1 |
mount -t tmpfs tmpfs /tmpram -o size=<span class="hljs-number">512</span>m |
51.Grep whole words:
1 |
grep -w <span class="hljs-string">"name"</span> test.txt |
52.在需要提升权限的情况下往一个文件里追加文本:
1 |
echo <span class="hljs-string">"some text"</span> | sudo tee -a /path/file |
53.列出所有kill signal参数:
1 |
kill -l |
54.在bash历史记录里禁止记录最后一次会话:
1 |
kill -<span class="hljs-number">9</span> $$ |
55.扫描网络寻找开放的端口:
1 |
nmap -p <span class="hljs-number">8081</span> <span class="hljs-number">172.20.0.0</span>/<span class="hljs-number">16</span> |
56.设置git email:
1 |
git config --<span class="hljs-keyword">global</span> user.email <span class="hljs-string">"me@example.com"</span> |
57.To sync with master if you have unpublished commits:
1 |
git pull --rebase origin master |
58.将所有文件名中含有”txt”的文件移入/home/user目录:
1 |
find -iname <span class="hljs-string">"*txt*"</span> -<span class="hljs-keyword">exec</span> mv -v {} /home/user \; |
59.将文件按行并列显示:
1 |
paste test.txt test1.txt |
60.shell里的进度条:
1 |
pv data.log |
61.使用netcat将数据发送到Graphite server:
1 |
echo <span class="hljs-string">"hosts.sampleHost 10 `date +%s`"</span> | nc <span class="hljs-number">192.168.200.2</span> <span class="hljs-number">3000</span> |
62.将tabs转换成空格:
1 |
expand test.txt > test1.txt |
63.Skip bash history:
1 |
< space >cmd |
64.去之前的工作目录:
1 |
cd - |
65.拆分大体积的tar.gz文件(每个100MB),然后合并回去:
1 2 |
split –b <span class="hljs-number">100</span>m /path/to/large/archive /path/to/output/files cat files* > archive |
66.使用curl获取HTTP status code:
1 |
curl -sL -w <span class="hljs-string">"%{http_code}\\n"</span> www.example.com -o /dev/null |
67.设置root密码,强化MySQL安全安装:
1 |
/usr/bin/mysql_secure_installation |
68.当Ctrl + c不好使时:
1 |
Ctrl + \ |
69.获取文件owner:
1 |
stat -c %U file.txt |
70.block设备列表:
1 |
lsblk -f |
71.找出文件名结尾有空格的文件:
1 |
find . -type f -<span class="hljs-keyword">exec</span> egrep -l <span class="hljs-string">" +$"</span> {} \; |
72.找出文件名有tab缩进符的文件
1 |
find . -type f -<span class="hljs-keyword">exec</span> egrep -l $<span class="hljs-string">'\t'</span> {} \; |
73.用”=”打印出横线:全选复制放进笔记
1 |
printf <span class="hljs-string">'%100s\n'</span> | tr <span class="hljs-string">' '</span> = |