总结表格
| 类别 | 常用命令 | 主要用途 |
|---|---|---|
| 系统版本 | lsb_release -a |
显示发行版信息(推荐) |
cat /etc/os-release |
查看标准系统信息文件 | |
hostnamectl |
查看系统d系统信息(简洁) | |
uname -a |
查看内核版本和架构 | |
| CPU | lscpu |
查看CPU信息(最常用) |
cat /proc/cpuinfo |
查看详细的CPU原始信息 | |
| 内存 | free -h |
查看内存使用情况(最常用) |
cat /proc/meminfo |
查看详细的内存原始信息 | |
| 综合工具 | lshw |
列出详细的硬件配置(需root) |
inxi -Fxz |
功能全面的系统信息脚本(推荐安装) | |
dmidecode |
查询底层硬件信息(需root) |
1
alias unalias
{a..z} {1..100..2}
ctrl+a e u k l
history !! !d !ech
基本正则:^$.[]*
扩展正则:(){}?+|等字符
nohup 2>&1 &用法
nohup python my.py >> /usr/local/python/xxf/my.log 2>&1 &
nohup命令
- nohup指不断地运行,是no hang up的缩写,指不间断,不挂断。运行一个进程的时候,不想让其在你退出账号时关闭,即可用nohup。
- nohup在不规定的情况下,所以输出内容会到nohup.out中
2>&1
0表示stdin标准输入,用户键盘输入的内容1表示stdout标准输出,输出到显示屏的内容2表示stderr标准错误,报错内容2>&1是一个整体,>左右不能有空格,即将错误内容重定向输入到标准输出中去。
&
为后台运行
echo
echo -n hello # 打印后不换行
echo $? # 上次的命令的执行结果,0表示成功 非零值表示失败
echo $JAVA_HOME
echo '$NAME' # 打印$NAME串
echo "$NAME" # 这个也会解析NAME变量
echo -e "hello\nworld"
mkdir
mkdir dir1 dir2
mkdir -p dir/dir1
mkdir -m 700 dir6
cp
cp -v test.txt testdir # -v打印复制细节
cp -r testdir testdir2 # 复制目录
cp -i test1.txt test2.txt # 覆盖前询问
cp -f test1 test2 # 目标文件已存在,但是无法打开时,删除源文件后重新复制
find
find . -name "*.txt"
find . -iname "*.txt"
find . -type f
find . -type l
find . -type d
find . -mmin +1 # 1分钟之前编辑的文件
find . -mmin -1 # 1分钟之内编辑的文件
find . -mtime +1 # 1天之前编辑的文件
find . -mtime -1 # 1天之内编辑的文件
find . -user user1 # user1用户有哪些文件
find . -group root # root组有哪些文件
cat
cat -n test1.txt # 显示行号
cat -b test1.txt # 只在非空行前面加行号
cat -s test1.txt # 多个空行合并为1个空行
cat -E test1.txt # 对每行末尾增加$表示结尾
cat -T test1.txt # 打印tab键替换为 ^I
cat -A test1.txt # 相当于-E和-T一起
cat test1.txt test2.txt # 打开两个文件(内容连接到一起显示)
cat file1 file2 file3 > files
cat > newfile.txt # 编辑文件,回车换行,ctrl+D结束输入
cat >> newfile.txt # 追加
cat file1.txt |wc -l 统计文件有多少行
rm
rm -r testdir1 # 删除文件夹
rm -i -r testdir1 # 删除前询问
wc
wc test1.txt
2 3 18 test1.txt # 表示test1.txt有2行,3个单词,18个字节
wc -l test1.txt # 表示只打印test1.txt的行数
wc -w test1.txt
wc -c test1.txt # 字节数
wc -m test1.txt # 字符数
tar
tar -cf testdir.tar testdir/ # c表示创建压缩文件,f表示指定tar文件名词
tar -cf test.tar test1 test2 # f必须紧跟归档文件名
tar -cf myfiles.tar *.txt #
tar -xf myfiles.tar # 解压tar
tar -zcf test.tar.gz testdir # 创建时用gzip压缩
tar -zxvf test.tar.gz testdir # 解压
tail
tail testfile1.txt
tail -n 5 test.txt
tail -n +5 test.txt
tail -f test.txt
tail -F test.txt
grep
grep hello test.txt
grep -i hello test.txt 忽略大小写
grep -w hello test.txt 全词匹配
grep -e hello -e world test.txt 查找多个
grep -n hello test.txt 打印出行数
grep -v hello test.txt 反向查找(查找不包含的)
grep -r hello testdir/ 指定目录下的
grep -lr hello testdir/ 返回查找到的文件名(-l)
grep -E ‘hello|world’ test.txt 正则表达式 (打印出hello或world的)
find / -name aaa |xargs grep bbb
grep "^10" test.txt
grep "11$" test.txt
sed
sed -e '1i\a new line' test1.txt # 文本第一行增加a new line,其中-e可以省略
sed -ie '1i\a new line' test1.txt # -ie会出现test1.txte备份文件
sed -i '1i\a new line' test1.txt # 不会新增备份文件
sed -e '4a\line' test1.txt
sed -e '4d' test1.txt # 删除
sed -e '1c\line' test1.txt # 修改
sed -e 's/old/new/' test1.txt # 所有行的第一个old都替换成new
sed -e '2s/old/new' test1.txt # 第二行的第一个old替换成new
sed -e '2s/old/new/g' test1.txt # 第二行所有的old都替换成new
sed -n '1p' test1.txt # 打印第一行
sed -f test.sh test1.txt # 从test.sh中读取参数