linux运维常用命令

简介: 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

死机时按这三个键重启

<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

相关文章
|
9天前
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
|
3天前
|
Linux
【Linux】深入理解ls命令
【Linux】深入理解ls命令
|
1天前
|
安全 网络协议 Linux
【专栏】一文教你玩转 Linux 的 ping 命令,从此成为 Linux 网络高手
【4月更文挑战第28天】本文详细介绍了Linux系统中ping命令的使用,包括其基本语法、输出信息、常用参数及高级用法。通过ping,用户可测试网络连通性、诊断故障及评估性能。此外,文章还讨论了ping在不同协议、模拟网络环境及与其他命令结合使用时的场景。注意防火墙和网络环境可能影响ping结果,理解错误信息有助于网络问题排查。熟练掌握ping命令,能助你成为Linux网络专家。不断学习和实践,提升网络技能,为构建稳定网络环境贡献力量。
|
3天前
|
XML 安全 Linux
【Linux】深入探究CentOS防火墙(Firewalld):基础概念、常用命令及实例操作
【Linux】深入探究CentOS防火墙(Firewalld):基础概念、常用命令及实例操作
|
5天前
|
监控 Linux Windows
50个必知的Linux命令技巧,你都掌握了吗?(下)
50个必知的Linux命令技巧,你都掌握了吗?(下)
|
6天前
|
Linux Shell Windows
Linux 常用基本命令
Linux 常用基本命令
|
6天前
|
Ubuntu Linux Shell
linux免交互登陆远程主机并执行命令(密钥对和Expect)
linux免交互登陆远程主机并执行命令(密钥对和Expect)
|
6天前
|
Linux
【Linux】常用命令
【Linux】常用命令
25 0
|
6天前
|
安全 Ubuntu Linux
Linux 网络操作命令Telnet
Linux 网络操作命令Telnet
22 0
Linux 网络操作命令Telnet
|
8天前
|
存储 Ubuntu Linux
Linux 自动化处理命令 Expect 使用教程
Linux 自动化处理命令 Expect 使用教程
33 0