32 bits or 64 bits?
查看系统是32位还是64位
getconf LONG_BIT 或 uname -m
Generate a random password 30 characters long
生成一个30字符的随机密码
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
Recursively remove all empty directories
递归删除所有空目录
find . -type d -empty -delete
find all file larger than 500M
查找大小超过500M的文件
find / -type f -size +500M
Find usb device
查看3s之内的USB设备变化
diff <(lsusb) <(sleep 3s && lsusb)
Serve current directory tree at http://$HOSTNAME:8000/
在当前目录起一个web server
python -m SimpleHTTPServer
Salvage a borked terminal
终端显示混乱后,使用此命令重新初始化终端
reset
currently mounted filesystems in nice layout
以人类友好的列形式,查看当前已挂载的文件系统
mount | column -t
What is my public IP-address?
获取自己的公网IP
curl ifconfig.me
Execute a command at a given time
指定时间去干某件事情,一次性的,干完有邮件通知
echo "ls -l" | at midnight
Mount a temporary ram partition
在ram中创建一个分区,如果您需要一个临时的工作空间,这是很有用的,并且读写的速度非常快。
mount -t tmpfs tmpfs /mnt -o size=1024m
SSH connection through host in the middle
通过中间机,登录不可直达的机器
ssh -t reachable_host ssh unreachable_host
Watch Star Wars via telnet
通过telnet观看星球大战
telnet towel.blinkenlights.nl
Put a console clock in top right corner
在命令行窗口的右上角显示时间
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
Set audible alarm when an IP address comes online
机器重启时,你还在死盯着,苦苦等待吗?使用这条命令,当发现能ping通时,发出报警
ping -i 60 -a IP_address
List of commands you use most often
列出你最常用的命令
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Simulate typing
模拟打字
echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
Reboot machine when everything is hanging
死机时按这三个键重启
<alt> + <print screen> + <B>
Display the top ten running processes - sorted by memory usage
显示最占内存的十个进程
ps aux | sort -nk +4 | tail
Push your present working directory to a stack that you can pop later
pushd /tmp
Create a script of the last executed command
echo "!!" > foo.sh
Watch Network Service Activity in Real-time
lsof(list open files)是一个列出当前系统打开文件的工具。lsof -i显示符合条件的进程情况
lsof -i
Show apps that use internet connection at the moment. (Multi-Language)
显示当前用于互联网连接的应用程序
lsof -P -i -n
Reuse all parameter of the previous command line
重用前一个命令的所有参数;如:先使用ls查看文件是否存在,然后cat !*
!*
Add Password Protection to a file your editing in vim. vim
加密文件
vim -x <FILENAME>
Display which distro is installed
显示系统是哪个发行版
cat /etc/issue
A fun thing to do with ram is actually open it up and take a peek. This command will show you all the string (plain text) values in ram
显示内存中的字符串
sudo dd if=/dev/mem | cat | strings
Graphical tree of sub-directories
子目录的图形树
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
intercept stdout/stderr of another process
拦截另一进程的 stdout/stderr
strace -ff -e trace=write -e write=1,2 -p SOME_PID
Copy a file using pv and watch its progress
拷贝文件,并实时显示进度、当前速度、耗费时间、估计剩余时间等。
pv sourcefile > destfile
Make directory including intermediate directories
创建目录,包括中间目录
mkdir -p a/long/directory/path
Multiple variable assignments from command output in BASH
bash命令输出的结果给多个变量赋值
read day month year <<< $(date +'%d %m %y')
Create a pdf version of a manpage
创建一个PDF
man -t strcpy | ps2pdf - filename.pdf
Show apps that use internet connection at the moment. (Multi-Language)
显示目前使用互联网连接的应用程序
ss -p
Graph # of connections for each hosts.
图形化显示当前机器连接了哪些IP,每个IP有多少个连接
netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'
Job Control
作业控制
^Z $bg $disown
Edit a file on a remote host using vim
远程修改文件
vim scp://username@host//path/to/somefile
Record a screencast and convert it to an mpeg
录屏
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg
Search for a string inside all files in the current directory
在当前目录中的所有文件中搜索字符串
grep -RnisI <pattern> *
Convert seconds to human-readable format
时间戳转时间
date -d@1234567890
Get the 10 biggest files/folders for the current direcotry
获取当前目录中10个最大文件/文件夹
du -s * | sort -n | tail
Show numerical values for each of the 256 colors in bash
在bash中显示256种颜色和其值。
for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
Display a cool clock on your terminal
在你的终端上显示一个炫酷的时钟
watch -t -n1 "date +%T|figlet"
while true; do echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done
Processor / memory bandwidthd? in GB/s
处理器/内存带宽?以GB/S表示
dd if=/dev/zero of=/dev/null bs=1M count=32768
Send pop-up notifications on Gnome
在gnome上发送弹出通知。
notify-send ["<title>"] "<body>"
卸载软件,但不移除配置文件和数据文件,也不移除所依赖的包
sudo apt remove packagename
移除该软件的配置文件,但不移除所依赖的包
apt purge packagename 或者 apt remove --purge packagename
卸载当前系统中的所有孤立的包(remove orphaned packages)。
sudo apt autoremove
模拟卸载,但不会真的卸载。
apt-get -s remove packagename
pretend to be busy in office to enjoy a cup of coffee
喝杯咖啡,也得假装在工作
cat /dev/urandom | hexdump -C | grep "ca fe"
Create a quick back-up copy of a file
快速备份文件
cp file.txt{,.bak}
Nice weather forecast on your shell
查看天气
curl wttr.in/wuxi
Broadcast your shell thru ports 5000, 5001, 5002 …
广播你的shell
script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)
List only the directories
只列出目录
ls -d */
Binary Clock
二进制时钟
watch -n 1 'echo "obase=2;`date +%s`" | bc'
Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes
按千兆字节、千字节、兆字节然后字节对目录树的大小使用进行排序。
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'
find files in a date range
查找某一时间段内的文件
find . -type f -newermt "2019-10-01" ! -newermt "2019-12-01"
Exclude .svn, .git and other VCS junk for a pristine tarball
打包时排除 .svn 和 .git
tar --exclude-vcs -cf src.tar src/
Show all current listening programs by port and pid with SS instead of netstat
用ss而不是netstat显示所有当前侦听程序的端口和PID。
ss -plunt