linux shell 命令笔记

标准输入、标准输出、标准错误

File descriptors are integers associated with an opened file or data stream. File descriptors 0,
1, and 2 are reserved as follows:
 0 –  stdin (standard input)
1 –  stdout (standard output)
2 –  stderr (standard error)

重定向(默认只重定向标准输出)  > 覆盖重写 >> 添加

重定向标准错误和标准输出到不同文件  cmd 2>stderr.txt 1>stdout.txt

重定向到同一个文件 cmd 2>&1 out.txt

不输出标准错误 cmd 2>/dev/null

管道命令(|)

find 命令

find ../ test.txt 

find -name "*.txt"

find . -iname "example*" -print  忽略大小写查找

find . \( -name "*.txt" -o -name "*.pdf" \) -print  多条件查找

find /home/users -path "*slynux*" -print  查找目录

find . -regex ".*\(\.py\|\.sh\)$"       正则表达式查找

find . ! -name "*.txt" -print    查找不是以.txt结尾的文件

find . -type d -print 查找目录

根据时间做查找

find . -type f -atime -7 -print    查找7天内访问过的文件

find . -type f -mtime -7 -print    查找7天内修改过的文件

find . -type f -ctime -7 -print    查找7天内修改过权限或者拥有者的文件

以下三个选项对应的是分钟

-amin (access time)
f -mmin (modification time)
f -cmin (change time)

find . -type f -newer file.txt -print   查找修改时间比file.txt早的文件

根据文件大小做查找

b – 512 byte blocks
c – bytes
 w – two byte words
 k – Kilobyte
 M – Megabyte
G – Gigabyte

find . -type f -size +2k  查找大于2k的文件

find . -type f -size -2k  查找小于2k的文件

find . -type f -size 2k  查找等于2k的文件

File type       Type argument
Regular file       f
Symbolic link    l
Directory          d
Character special device c
Block device    b
Socket             s
Fifo                  p

find . -type f -name "*.swp" -delete  找到文件的同时删除

猜你喜欢

转载自www.cnblogs.com/mangojun/p/11368955.html