命令 [参数] [文件路径]
rm -f /tmp/test
1、创建一个目录 /data解答:mkdir /data
2.在/data 下面建立一个文件test.txt解答:touch test.txt
3、为test.txt 增加内容为“heloo world"解答:
echo "heloo world">test.txt
vi test.txt
cat >test.txt
4、把 test.txt 拷贝到 /tmp解答: cp test.txt /tmp/
5、把 /data 目录移动到/root 下解答: mv /data /root
6、进入 root 目录 下的 data 目录,删除 test.txt解答:cd /root;rm test.txt
7、已知文件 test.txt 内容为:123
456
789
heloo
请给出打印test.txt内容时,不包含heloo 字符串命令。解答:
grep -v heloo test.txt
head -2 test.txt
sed '/heloo/d' test.txt
awk /[^heloo]/ test.txt
8、请恋情一条命令完成目录/data/test, 即创建/data 目录及 /data/test目录。解答:mkdir -p /data/test 或 mkdir /data /data/test
查看目录树:tree
9、已知 /tmp 目录下已经存在test.txt, 如何执行命令才能把 /mnt/test.txt 拷贝到/tmp 下覆盖掉 /tmp/test.txt,而让Linux 系统不提示是否覆盖(root权限下)。解答:/bin/cp /mnt/test.txt /tmp/test.txt 或 \cp /mnt/test.txt /tmp/
查命令位置:which cp
查看别名:alias
取消别名:unalias xxx
增加别名:alias rm='echo "heloo.."'
cat ~/.bashrc
查找命令:find / -type f -name "test.txt"
查找并删除:find / -type f -name "test.txt" -exec rm -f {} \;
查找并删除2:find / -type f -name "test.txt"|xargs rm -f
按时间查找删除::find /root/ -type f --mtime +5 |xargs rm -f
10、只查看test.txt文件(100行)内第20到第30行内容。解答:
head -30 test.txt|tail -11
sed -n 20,30p test.txt
awk '{if(NR<31&&NR>19) print $0}' test.txt
序列:seq -s "#" seq 5 seq 2 5 seq 1 2 9 |tac
11、把/data/ 下所有 txt后缀文件 里的"heloo"字符串替换成123。解答:find /data/ -type f -name "*.txt"|xargs sed -i s#heloo#123#g
-n 取消默认输出
-i 改变输出内容
s 表示编辑替换
g 表示全部替换
find /data/ -type f -name "*.txt"|xargs cat
find /data/ -type f -name "*.txt"|xargs ls
作业:
总结 xargs,find,awk,sed,grep,vi,vim,seq 命令赞0
踩0
版权声明:若无特殊注明,本文为《橙子柠檬》原创,转载请保留文章出处。
本文链接:https://qinzc.me/post-52.html
正文到此结束