Rename files in multiple directories to the name of the directory

后端 未结 3 1743
梦谈多话
梦谈多话 2020-12-13 10:55

I have something like this:

v_1/file.txt
v_2/file.txt
v_3/file.txt
...

and I want to rename those files to something like this:

<         


        
3条回答
  •  一整个雨季
    2020-12-13 11:12

    Seem pretty straightforward to me:

    $ mkdir /tmp/sandbox
    $ cd /tmp/sandbox
    
    $ mkdir v_{1,2,3}
    $ touch v_{1,2,3}/file.txt
    
    $ rename -v 's#/file##' v_{1,2,3}/file.txt
    rename v_1/file.txt v_1.txt
    rename v_2/file.txt v_2.txt
    rename v_3/file.txt v_3.txt
    
    $ ls -F
    v_1/  v_1.txt    v_2/  v_2.txt    v_3/  v_3.txt
    

提交回复
热议问题