一、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(不要被后缀名迷惑)