linux把data移动到root下,Linux基础命令实战 - 橙子柠檬's Blog

命令 [参数]  [文件路径]

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 命令9b3f1f9d309c0ae54cf617076dee0ca0.png赞0

c788d2554644b6a03084e98b2926d709.png

380c82d9930cb6b75d8471e9cb2da8a3.png踩0

版权声明:若无特殊注明,本文为《橙子柠檬》原创,转载请保留文章出处。

本文链接:https://qinzc.me/post-52.html

正文到此结束

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值