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 cat /proc/version # Linux version 5.4.0-77-generic (buildd@lgw01-amd64-028) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021
ifconfig | grep “inet ” | grep -v 127.0.0.1
ifconfig en1
有时候是 en0curl 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 find ./ -type f -name "*0325*" // 文件名中含有 0325 的文件
查找并删除
find . -type f -name "*.DS_Store*" -exec rm -f {} \;
下面五个参数基本够用,更详细参数移步tar 命令详解
压缩大文件显示进度
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
用户ID id -u <username>
$ 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
# 列出所有已经加载的systemd units systemctl systemctl | grep docker.service # 列出所有service systemctl list-units --type=service systemctl --type=service #列出所有active状态(运行或退出)的服务 systemctl list-units --type=service --state=active # 列出所有正在运行的服务 systemctl list-units --type=service --state=running systemctl list-units --type service --state running,failed systemctl list-unit-files --state=enabled
交互命令 1)
// 查看已经连接的服务端口(ESTABLISHED) netstat -a // 查看所有的服务端口(LISTEN,ESTABLISHED) netstat -ap // 查看指定端口,可以结合grep命令: netstat -ap | grep 8080 // 也可以使用lsof命令: lsof -i:8888 // 若要关闭使用这个端口的程序,使用kill + 对应的pid kill -9 PID号
用CURL 发送 post 命令
参数 -d 指定数据
curl -X POST -d "name=John&age=30" https://example.com/api
还可以指定数据类型
curl -X POST -H "Content-Type: application/json" -d '{"name":"John","age":30}' https://example.com/api
发送邮件
curl --url "smtps://smtp.example.com:465" \ --ssl-reqd \ --mail-from "[email protected]" \ --mail-rcpt "[email protected]" \ --user "username:password" \ --upload-file - <<EOF Subject: Test Email From: [email protected] To: [email protected] Dies ist eine Test-E-Mail, die von curl gesendet wurde. EOF