帮助
- man
查看完整使用说明 - command –help 是最实用的用法说明
- whatis查看命令主要描述,whereis查找命令位置,which查找命令的真实引用
启动
halt, reboot, poweroff 三者类似同义词
bash builtins
echo
- echo -e 启用转义
history
time
date
- 格式输出2天前的日期
date --date='2 days ago' +%Y%m%d
date +%s
UNIX时间
cal
fg
- Resume jobspec in the foreground, and make it the current job.
bg
- Resume each suspended job jobspec in the background
用户管理
passwd
su
查看系统信息
uname
uname -a
hostname
hostnamectl
runlevel
who
w
last
运行状态
free
free --help
查看用法free -b|k|m|g
按单位换算,默认kilobytesfree -h
human-readable显示free -s 5
间隔5秒刷新显示
uptime
top
服务、进程
ps
- 内存占用前10
ps aux --sort -rss | head -10 | awk 'NR>1 {$6=int($6/1024)"M";}{ print;}'
- 内存占用总计
ps aux | grep ora | awk '{sum+=$6} END {print sum / 1024}'
pstree
- 需要安装
yum install -y psmisc
pgrep
- 需要安装
yum install -y procps-ng
- pgrep -a java
kill
- kill -9 ‘pid’
ps aux | grep ora | awk '{print $2}' | xargs kill -9
nohup
nohup ./test > myout.txt 2>&1 &
文件
ls
ll -Sh
文件大小排序ll -rt
时间升序ls -lt | less
时间降序ls -l | grep -v ^l | wc -l
文件个数
stat
stat --printf="%.19y\t%n\n" *
ln
ln -s /etc/nginx/sites-available/xxx.xiongjiaxuan.com.conf /etc/nginx/sites-enabled/
cd
pwd
mkdir
rmdir
file
- 能检测文本编码和是否CRLF换行
touch
- 更新访问文件的修改时间,如果不存在则创建该文件
cp
cp -R ../gpac-0.7.0/include/gpac ./
scp
scp root@host:/home/filename.txt ./
mv
rename
- 批量重命名
- 把htm结尾文件替换为html结尾
rename .htm .html *.htm
rm
-i
prompt before every removal
df
df -h
chmod
chmod -R 777 <filename>
tar
- 打包
tar -cvf static.tar static/
- 打包并压缩
tar -czvf static.tar static/
- 排除指定文件后压缩
tar -czvf static.tar.gz --exclude=static/video static/
- 解压至指定目录
tar -xzvf static.tar.gz -C ~/download
- 查看前5级
tar -tvf static.tar.gz | head -n5
zip & unzip
- 打包并压缩
zip -r static.zip static/
- 加密码
zip -rP 28c927f4-c863-11eb-8ce2-3c6aa7cc5bfe static.zip static/
- 解压至指定目录
upzip static.zip -d ~/download
bzip2
bzip2 -d last_x264.tar.bz2
find
- 文件名支持通配符
find / -name <filename*>
locate
- 需要安装
yum install -y mlocate
- 更新数据
updatedb
locate "*png"
lsof
- 需要安装
yum install -y lsof
- 列出所有打开的文件(查看端口使用程序)
lsof -i:80
查看80端口占用
文本处理
more
more /etc/profile
- space下一页,q退出
less
- PgUp上一页,space或PgDn下一页,q退出
- man page就是使用less输出的,有
/?
的搜索功能
head
head -n 20 /etc/profile
查看文件前20行
tail
tail -f /var/log/messags
检测输出文件内容
cat
cat -An /etc/profile ~/.bashrc
连接两个文件输出(显示空白字符及行号)cat /etc/profile | wc
查看文件行数、字数、字符数
tac
nl
nl -b a -n rn /etc/profile
右对齐显示行号(包括空行)nl -n rz -w 3 /etc/profile
三位长度左侧补零
strings
strings -t d /etc/profile
附加显示10进制字符位置
cut
echo $PATH | cut -d':' -f 1,5
冒号分割取第1和第5个的值export | cut -c 12-
获取第12列以后的内容
grep
grep -v '^#' /etc/my.cnf
非#开头行
sort
cat /etc/passwd | sort -t ':' -k 3 -n
按冒号分割的第三列作为数字排序
uniq
last | cut -d ' ' -f1 | sort | uniq -c
wc
cat /etc/passwd | wc -l
系统有多少个账号
tr
ls | tr [a-z] [A-Z]
转为大写字母cat ~/dos.txt | tr -d '\r'
Windows换行转为Linux换行
col
cat ~/.bashrc | col -x | cat -A
网络
ifconfig
ip
ip addr
netstat
- 需要安装
yum install -y net-tools
netstat -anp | grep '80'
查看端口占用程序
traceroute
traceroute -m 50 baidu.com
curl
curl -o index.html http://www.baidu.com
wget
wget -O index.html http://www.baidu.com
工具
bc