这是本文档旧的修订版!


SHELL 命令

nohup 后台进程

1指标准输出;2指错误输出,所以写成这样:command 1>output 2>error & ,正常的输出在output文件里,错误的输出在error文件里, command >output 2>error &

(1可以省略)

忽略错误输出:command 1>output 2>/dev/null &

忽略标准输出:command 1>/dev/null 2>error &

忽略全部输出:command 1>/dev/null 2>/dev/null &

忽略全部输出command >/dev/null 2>&1 &

错误输出和标准输出在一个文件:command 1>output 2>&1 &

错误输出和标准输出在一个文件:command 1>output 2>output & (X这种方式错误)

这样的文件输出,每次运行会覆盖现有的文件,如果我们希望追加而不是覆盖,那么就用»符号,这样命令就是: command 1»output 2»error &

如果想退出窗口乃至退出登录仍然保持程序运行,再加上nohup,形如:nohup command 1>output 2>&1 &

nohup sh run.sh 1>run_info.log 2>run_error.log &

查看系统

显示系统版本

uname -m
# armv7l
uname -a # 显示所有信息
Linux pi 5.10.17-v7l+ #1414 SMP Fri Apr 30 13:20:47 BST 2021 armv7l GNU/Linux

查看IP地址

  • 方式一: ifconfig | grep “inet ” | grep -v 127.0.0.1
  • 方式二:ifconfig en1 有时候是 en0
  • 外网地址 curl ifconfig.me

文件命令

  • 查看文件夹 du -h –max-depth=1 your_dest_dir
  • 查看文件夹大小 du -sh
  • 查看文件详细内容 ls -lht
  • 从远程服务器拷贝: rcp
  • 复制到远程服务器: scp

查找文件 locating linux files

find . -name thisfile.txt
find /home -name *.jpg
find . -type f -empty

TAR 压缩解压

下面五个参数基本够用,更详细参数移步tar 命令详解

  • z : 使用gzip压缩,否则仅仅打包不压缩。
  • c : 创建新文件。
  • v : verbose 处理过程输出信息
  • f : 指定备份文件
  • x : 解压

压缩大文件显示进度

download

# mac
tar -cf - questions.sql | pv -s $(($(du -sk questions.sql | awk '{print $1}') * 1024)) | gzip > question.tar.gz
# ubuntu
tar -cf - questions.sql | pv -s $(du -sk questions.sql | awk '{print $1}') | gzip > question.tar.gz

进程以及命令

查找

ps -ef #all process
ps -fC sshd # sshd 是名字
pgrep -fl ssh* #按名字查找,使用通配符
pgrep -fa mongo* # 显示所有信息!!!!!
pgrep mongod #按名字精确查找
ps -aux | grep mongo

pgrep -l 列出程序名和进程ID; -o 进程起始的ID; -n 进程终止的ID;

进程控制

  • 将任务放在后台运行:command + &
  • 将任务丢到后台暂停:ctrl-z
  • 查看后台所有任务状态:jobs -l (会列出 1、2、3序列号)
  • 将后台的任务拿到前台处理:fg %jobnumber (指序列号,而不是任务id)
  • 将后台的任务变成运行中:bg %jobnumber
  • 管理后台当中的任务:kill -signal %jobnumber

kill -9 <pid> 可以强制终止一个进程(是数字9,而不是字母g)

查看命令的目录

whereis ttyd
ttyd: /usr/local/bin/ttyd

定时任务

$ crontab -l #查看任务
$ crontab -e #编辑任务
$ crontab -r #删除任务

语法规则: 分钟(0-59) 小時(0-23) 日期(1-31) 月份(1-12) 星期(0-6)0和7都代表星期天

查找当前目录中三天前的文件并删除

find ./ -mtime +3 | xarg rm

隐藏文件夹

主要是mac系统上使用。快速命令,打开访达窗口,然后 ⌘ + ⇧ + . 就可以隐藏/显示。


//显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool true
//不显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool false

it/server/shell_command.1639985293.txt.gz · 最后更改: 2021-12-20 07:28 由 goldentianya
回到顶部
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0