Linux檔案增刪改
阿新 • • 發佈:2019-01-06
Linux目錄/檔案增刪改
建立檔案
(1)
# touch <檔名稱>
(2)
花括號展開
touch /root/{1,3,9}.txt
touch /root/{0..100}.txt 批量建立檔案
刪除檔案
rm -f [檔名]
-rf 代表強制刪除
批量刪除檔案
rm -f *txt
複製檔案
cp 只能複製檔案
cp -r 可以複製目錄
# cp [option] 原始檔 目標檔案
[ [email protected] ~]# mkdir /root/{linux,windown}
[[email protected] ~]# ls
anaconda-ks.cfg linux mysql57-community-release-el7-8.noarch.rpm windown
[[email protected] ~]# touch /root/linux/{1,2,3}.txt
[[email protected] ~]# ls
anaconda-ks.cfg linux mysql57-community-release-el7-8.noarch.rpm windown
[ [email protected] ~]# cd linux/
[[email protected] linux]# ls
1.txt 2.txt 3.txt
[[email protected] linux]# cd /r
root/ run/
[[email protected] linux]# cd /root/
[[email protected] ~]# cp /root/linux/1.txt /root/windown/
[[email protected] ~]# cd windown/
[[email protected] windown]# ls
1.txt
[ [email protected] windown]# cd ..
[[email protected] ~]# ls
anaconda-ks.cfg linux mysql57-community-release-el7-8.noarch.rpm windown
[[email protected] ~]# cp /root/linux/2.txt /root/windown/2.jpg
[[email protected] ~]# cd windown/
[[email protected] windown]# ls
1.txt 2.jpg
-r 複製檔案目錄
[[email protected] ~]# cp -r /root/linux/ windown/
[[email protected] ~]# ls
anaconda-ks.cfg linux mysql57-community-release-el7-8.noarch.rpm windown
[[email protected] ~]# cd windown/
[[email protected] windown]# ls
1.txt 2.jpg linux
[[email protected] windown]# cd linux/
[[email protected] linux]# ls
1.txt 2.txt 3.txt
-fn 強制覆蓋
[[email protected] ~]# cp -fn /root/linux/1.txt /root/windown/
移動檔案
#mv 原始檔 目標檔案
檔案重名