linux运维常用命令


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
死机时按这三个键重启

+ +

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

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 *

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 [""] "<body>"<br><br>卸载软件,但不移除配置文件和数据文件,也不移除所依赖的包<br>sudo apt remove packagename<br><br>移除该软件的配置文件,但不移除所依赖的包<br>apt purge packagename 或者 apt remove --purge packagename<br><br>卸载当前系统中的所有孤立的包(remove orphaned packages)。<br>sudo apt autoremove<br><br>模拟卸载,但不会真的卸载。<br>apt-get -s remove packagename<br><br>pretend to be busy in office to enjoy a cup of coffee<br>喝杯咖啡,也得假装在工作</p> <p>cat /dev/urandom | hexdump -C | grep "ca fe"<br><br>Create a quick back-up copy of a file<br>快速备份文件</p> <p>cp file.txt{,.bak}<br><br>Nice weather forecast on your shell<br>查看天气</p> <p>curl wttr.in/wuxi<br><br>Broadcast your shell thru ports 5000, 5001, 5002 …<br>广播你的shell</p> <p>script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)<br><br>List only the directories<br>只列出目录</p> <p>ls -d */<br><br>Binary Clock<br>二进制时钟</p> <p>watch -n 1 'echo "obase=2;`date +%s`" | bc'<br><br>Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes<br>按千兆字节、千字节、兆字节然后字节对目录树的大小使用进行排序。</p> <p>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'<br><br>find files in a date range<br>查找某一时间段内的文件</p> <p>find . -type f -newermt "2019-10-01" ! -newermt "2019-12-01"<br><br>Exclude .svn, .git and other VCS junk for a pristine tarball<br>打包时排除 .svn 和 .git</p> <p>tar --exclude-vcs -cf src.tar src/<br><br>Show all current listening programs by port and pid with SS instead of netstat<br>用ss而不是netstat显示所有当前侦听程序的端口和PID。</p> <p>ss -plunt<br><br></p> </div> <!--conend--> <div class="p-2"></div> <div class="arcinfo my-3 fs-7 text-center"> <a href='/t/etagid107-0.html' class='tagbtn' target='_blank'>Linux</a> </div> <div class="p-2"></div> </div> <div class="p-2"></div> <!--xg--> <div class="lbox p-4 shadow-sm rounded-3"> <div class="boxtitle"><h2 class="fs-4">相关</h2></div> <hr> <div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-566392.html">linux环境开机自启动nginx</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-566464.html">Linux获取栈空间大小</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-566165.html">Xlib Linux判断程序窗口是否为最小化</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-565165.html">linux下如何添加一个用户并且让用户获得root权限</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-565241.html">linux 恢复mysql 误删除数据</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-565160.html">linux 用时统计</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="">Linux磁盘操作:分区、格式化、挂载【转】</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-564591.html">Linux 上安装配置 VNC Server</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-564052.html">Linux-Mysql 遗忘密码如何解决?</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-564028.html">linux安装mysqlclient库</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-564005.html">Kali-Linux 2020.1修改Root用户密码(root用户策略)</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div><div class="row g-0 py-2 border-bottom align-items-center"> <div class="col-7 col-lg-11 border-lg-end"> <h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-563788.html">linux命令收集</a></h3> <div class="ltag fs-8 d-none d-lg-block"> </div> </div> </div> <!----> <!----> </div> <!--xgend--> </div> <div class="col-lg-3 col-12 p-0 ps-lg-2"> <!--box--> <!--boxend--> <!--<div class="p-2"></div>--> <!--box--> <div class="lbox p-4 shadow-sm rounded-3"> <div class="boxtitle pb-2"><h2 class="fs-4"><a href="#">标签</a></h2></div> <div class="clearfix"></div> <ul class="m-0 p-0 fs-7 r-tag"> </ul> <div class="clearfix"></div> </div> <!--box end--> </div> </div> </div> </main> <div class="p-2"></div> <footer> <div class="container-fluid p-0 bg-black"> <div class="container p-0 fs-8"> <p class="text-center m-0 py-2 text-white-50">一品网 <a class="text-white-50" href="https://beian.miit.gov.cn/" target="_blank">冀ICP备14022925号-6</a></p> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?6e3dd49b5f14d985cc4c6bdb9248f52b"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </footer> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js"></script> </body> </html>