hbthlw
7/19/2018 - 6:59 AM

[常用的bash命令] 常用的bash命令 useful bash commands #bash

[常用的bash命令] 常用的bash命令 useful bash commands #bash

  • 查看当前目录下文件占用
du . --max-depth=1 -h
  • 查看端口占用进程
PORT_NUMBER=1234
lsof -i tcp:${PORT_NUMBER}
  • 后台运行进程
# 后台运行某命令
nohup command &
nohup command > myout.file 2>&1 &
# 使用了nohup之后,很多人就这样不管了,其实这样有可能在当前账户非正常退出或者结束的时候,命令还是自己结束了。所以在使用nohup命令后台运行命令之后,需要使用exit正常退出当前账户,这样才能保证命令一直在后台运行。
# 可以将一个正在前台执行的命令放到后台,并且处于暂停状态。
ctrl + z 
# 终止前台命令。
ctrl + c
# 查看当前有多少在后台运行的命令。 
jobs
  • 根据名称查找文件夹
# shell - Use bash to find first folder name that contains a string ...
#
# You can use the -quit option of find:

find <dir> -maxdepth 1 -type d -name '*foo*' -print -quit
  • curl POST json
curl -H "Content-Type: application/json" -X POST  --data '{"data":"1"}'  http://127.0.0.1/
  • rsync 同步本地和远程的两个目录
rsync -e "ssh" -n -avvz --delete-after /root/test/live/ some.host:/root/html/

# -n:不真正执行