Linux常用的基本命令cp、mv、rm、cat、find(三)

导读:本篇文章讲解 Linux常用的基本命令cp、mv、rm、cat、find(三),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

一、cp复制文件命令

1、cp file2 /tmp :复制file2文件到/tmp目录下
2、cp /tmp/file2 /home :复制/tmp/file2文件到/home目录下
3、cp /home/file2 /tmp/file3: 复制/home/file2到/tmp目录下并改名为file3
4、cp -p /tmp/file3 /home :复制/tmp/file3到/home目录下并复制文件属性
5、cp -r /dir5 /tmp :复制/dir5目录到/tmp下

二、mv移动文件或目录命令

1、mv file4 /tmp :移动file4文件到/tmp目录下
2、mv /home/file3 /tmp: 移动/home/file3文件到/tmp目录下
3、mv /home/file3 /tmp/file5: 移动/home/file3文件到/tmp目录下并改名为file5
4、mv file3 file4 :将file3改名为file4
5、mv dir10 /tmp :移动目录到/tmp下
6、mv dir10 dir11 :讲dir10目录改名为dir11

三、rm删除文件命令

1、rm file1 :删除文件file1
2、rm -f file1 :不用确认直接删除file1
3、rm -f file1 file2 file3 :不用确认同时删除多个文件
4、rm /tmp/file1: 删除指定目录/tmp下的文件file1
5、rm fi* :删除以fi开头的文件
6、rm -r dir: 递归的方式删除非空目录dir
7、rm -rf dir :不用确认直接删除非空目录dir

四、cat查看文件内容命令

1、cat /etc/passwd :查看/etc/passwd文件
2、cat /etc/passwd |more: 分屏查看文件内容
3、cat /etc/passwd |less: 分屏查看文件内容,可以上下翻页,“q”退出

五、find查找文件命令

1、find pass* :在当前目录下查找以pass开头的文件
2、find /etc/pass*: 在/etc目录中查找以pass开头的文件
3、find /etc/pass* -print: 在/etc目录中查找以pass开头的文件,并显示出来
4、find -amin -60:最近60分钟内访问过的文件
5、find -cmin -60:最近60分钟内修改过的文件
6、find ./ -name ‘*.log’:在当前目录下查找后缀为.log的文件
在这里插入图片描述
7、查找在当前目录下超过100字符的文件:find ./ -size +100c
8、查找dir1目录下文件后缀为.txt的文件,并将查询到的文件复制到dir3中:

find ./dir1 -name '*.txt' -exec cp {} ./dir3/ \;

或者为:

find ./*.txt -exec cp {} ../dir2/3.txt \;

六、grep在文件内容中查找关键字

1、grep “rpm” /etc/passwd :在/etc/passwd文件中查找关键字rpm

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/74310.html

(1)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!