文件搜索——find
命令 | 解释 |
---|---|
find 路径 -name file1 | 从指定路径搜索文件名为file1的文件 |
find 路径 -user user1 | 搜索用户uesr1的文件和目录 |
find 路径 -name \*.bin | 在指定路径下搜索以’.bin’结尾的文件 |
find 路径 -type f -atime +10 | 在指定路径搜索过去10天内未被使用过的文件 |
find 路径 -type -f -mtime +10 | 在指定路径搜索过去10天内未被创建/修改过的文件 |
which xx | 显示一个二进制文件或可执行文件的完整路径 |
文件内容查看
命令 | 解释 |
---|---|
cat file1 | 从第一行开始输出file1文件内容 |
tac file1 | 从最后一行开始输出file1文件内容 |
more file1 | 查看file1文件内容,敲回车往下翻页 |
less file1 | 查看file1文件内容,敲上下键翻页 |
head -2 file1 | 查看file1文件的前两行 |
tail -2 file1 | 查看file1文件的最后两行 |
tail -f /var/log/messages | 实时查看被添加到/var/log/messages文件的内容 |
文本文件处理
命令 | 解释 |
---|---|
cat file1 |grep root 或 grep root file1 | 输出file1中包括root字符串的行 |
cat file1 |grep ^root 或 grep ^root file1 | 在file1中查找以root开头的行 |
grep root -R 路径(当前路径可不写) | 在dir1目录下搜索全部文件包含root的行 |
sed s/root/ROOT/g file1 | 将file1中的root替换为ROOT(源文件内容不变) |
sed -e ‘1d’ file1 | 删除file1文件中的第一行(源文件内容不变) |
sed -n ‘/root/p’ file1 | 查看file1 中包含root的行 |
sed -n ‘1,5p’ file1 | 查看file1中第1-5行内容 |
sort file1 file2 |uniq | 取出两个文件的并集 |
sort file1 file2 |uniq -u | 两个文件删除交集 |