linux(文件、文件夹的复制与移动)

一、cp命令用于文件、文件夹的复制:

1、单个文件的复制:

[root@localhost lianxi]# touch   beautiful.txt ---新建beautiful空文件
[root@localhost lianxi]# ls  --查看当前目录下的内容
lily.txt  beautiful.txt
[root@localhost lianxi]# mkdir  changsha  --新建长沙文件夹
[root@localhost lianxi]# ls  
changsha lily.txt  beautiful.txt
[root@localhost lianxi]# cp beautiful.txt  changsha --将beautiful.txt 复制到changsha文件夹下
                                            源文件           目的地
                                             source           destination
[root@localhost lianxi]# ls changsha
beautiful.txt

2、多个文件的复制:

[root@localhost lianxi]# mkdir  hunan  --新建hunan文件夹
[root@localhost lianxi]# ls
changsha  lily.txt  hunan  beautiful.txt  lanqing.txt
[root@localhost lianxi]# cp lily.txt  lanqing.txt beautiful.txt   hunan
                                            前面的3个文件都是源文件                   目的地
[root@localhost lianxi]# ls
changsha lily.txt  hunan  beautiful.txt lanqing.txt
[root@localhost lianxi]# ls hunan
lily.txt  beautiful.txt  lanqing.txt

小思考:为什么复制文件的时候,如果文件在目的地已经存在,会给予提醒?
[root@localhost lianxi]# alias 
alias cp='cp -i'
       -i, --interactive 交互式
              prompt before overwrite在覆盖之前给予提醒 
解决方法:
    1.取消别名
    unalias  cp
    2.使用cp命令的绝对路径 --》绕过别名的使用  ---》推荐的方法
    [root@localhost lianxi]# which cp
    alias cp='cp -i'
    /usr/bin/cp
    [root@localhost lianxi]# /usr/bin/cp  *.txt hunan
    [root@localhost lianxi]# \cp *.txt hunan--绕过别名的使用

3、单个文件的复制粘贴与重命名

将xiaoyu.txt复制到hunan目录,改名为xy.txt
[root@localhost lianxi]# cp xiaoyu.txt  hunan/xy.txt

 

4、单个文件夹的复制

[root@localhost lianxi]# ls
changsha  lily.txt  hubei  hunan beautiful.txt  lanqing.txt
[root@localhost lianxi]# cp  -r hunan hubei  --将hunan文件夹递归的复制给hubei, --  -r表示递归复制
多个文件夹复制

[root@localhost lianxi]# cp -r hunan hubei  guangdong
                                                源文件夹     目的地
[root@localhost lianxi]# ls guangdong/
hubei  hunan

二、mv移动文件夹(相当于剪切)

1:如果目的地不存在则是给源文件重命名

[root@localhost lianxi]# mv gui changsha hubei guangdong/  china
                                                                          源文件          目的地

[root@localhost lianxi]# mv *.txt  china  --将.txt结尾的文件复制到china目录下


可以将多个文件或文件夹同时剪切或者复制到一个文件夹:

mv boot  weijunlin.txt  china

cp  boot  wenjunlin.txt  china  -r

五、file命令:查看文件类型             
[root@localhost lianxi]# touch zhangjian.jpg
[root@localhost lianxi]# ls
create_file.sh  name.txt  zhangjian.jpg  zhangjian.txt
[root@localhost lianxi]# file zhangjian.jpg 
zhangjian.jpg: empty(不要被后缀名迷惑)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值