Linux批量文件管理

Linux批量文件管理shell

 

实验目标:编程

经过本实验掌握批量创建、移动、复制文件或目录的操做,也能够做为后续shell编程的基础。3d

 

实验步骤:blog

一、如今有十台终端机器,要为每台机器创建3个文件,总共要创建30个文件。基础

文件名称为system_change-machineY-month_Z.txt终端

   其中Y为机器编号,1-10,Z为月份,jan,feb,marim

二、一次性建立3个目录,分别为jan,feb,mar,根据月份把新建的文件移动到相应的目录d3

三、删除和机器九、机器10相关的全部文件touch

 

 

参考命令:img

 

一、 批量创建文件

 

[root@localhost student]# touch system_change-machine{1..10}-month_{jan,feb,mar}.txt

{1..10} :这里的名称为1到10共10个,中间是两个句点

{jan,feb,mar} :这里的名称为3个,用逗号隔开,总文件是10x3=30个

ls system* :显示全部system开头的文件,这里的星号为通配符,意思匹配任何字符

 

 

 

 

2.2 批量创建文件夹

 

[root@localhost student]# mkdir -p /home/syschanges/{jan,feb,mar}

mkdir -p ,自动创建多层目录,好比mkdir –p /home/1/2/3,会把三个目录都创建

{jan,feb,mar}  , 创建平行的子目录,而不是多层次目录

经过ls –l 查看结果

 

 

 

2.3 批量移动文件

 

创建3个目录

[root@localhost student]# mkdir -p /home/student/system_change-machine/jan

[root@localhost student]# mkdir -p /home/student/system_change-machine/feb

[root@localhost student]# mkdir -p /home/student/system_change-machine/mar

 

批量移动(这里的星号为通配符)

[root@localhost student]# mv system_change-machine*jan.txt /home/student/system_change-machine/jan

 [root@localhost student]# mv system_change-machine*feb.txt /home/student/system_change-machine/feb

[root@localhost student]# mv system_change-machine*mar.txt /home/student/system_change-machine/mar

 

 

查看结果

 

 

 

2.4 批量删除

 

[root@localhost jan]# rm -f /home/student/system_change-machine/*/system_change-machine{9,10}*.txt

中间的星号表明任何文件夹,这里是jan,feb,mar三个文件夹下

{9,10},表明文件名machine后面有9或10的文件

后面的星号表明任何字符

rm –f ,f参数为强制删除,不问yes或no

 

查看结果,这里的cd ../为上一层目录的意思

 

相关文章
相关标签/搜索