change the file and fold name in linux

how to change the files or folds name in linux ?

1. use mv command

##creat the folds
[heshuai@login01 tmp]$ for i in $(seq 1 4); do mkdir $i[_fold]; done [heshuai@login01 tmp]$ ll total 0 drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 1[_fold] drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 2[_fold] drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 3[_fold] drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 4[_fold]
##change the folds name with rename command [heshuai@login01 tmp]$ for i in $(ls); do rename fold dd $i; done [heshuai@login01 tmp]$ ls 1[_dd] 2[_dd] 3[_dd] 4[_dd]
##change the folds name with mv command [heshuai@login01 tmp]$ for i in $(ls); do mv $i $i$(echo $i|cut -d "_" -f1)ffff; done [heshuai@login01 tmp]$ ls 1[_dd]1[ffff 2[_dd]2[ffff 3[_dd]3[ffff 4[_dd]4[ffff ## we could change the files name with the same way as mentioned above

2. use the rename command

[heshuai@login01 tmp]$ rm -rf *
[heshuai@login01 tmp]$ for i in $(seq 1 4); do mkdir $i[_fold]; done
[heshuai@login01 tmp]$ ll
total 0
drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 1[_fold]
drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 2[_fold]
drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 3[_fold]
drwxr-xr-x 2 heshuai sysuccbei 512 Aug 26 22:57 4[_fold]
[heshuai@login01 tmp]$ for i in $(ls); do rename fold dd $i; done
[heshuai@login01 tmp]$ ls
1[_dd]  2[_dd]  3[_dd]  4[_dd]
[heshuai@login01 tmp]$ for i in $(ls); do mv $i $i$(echo $i|cut -d "_" -f1)ffff; done
[heshuai@login01 tmp]$ ls
1[_dd]1[ffff  2[_dd]2[ffff  3[_dd]3[ffff  4[_dd]4[ffff

  

posted @ 2018-08-26 22:16  何帅  阅读(123)  评论(0)    收藏  举报