Rename files in multiple directories to the name of the directory

后端 未结 3 1747
梦谈多话
梦谈多话 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:32

    You can use rnm. The command would be:

    rnm -fo -dp -1 -ns '/pd0/.txt' -ss '\.txt$' /path/to/the/directory
    

    -fo implies file only mode.

    -dp directory depth. -1 makes it recursive to all subdirectories.

    -ns implies name string i.e the new name of the file.

    /pd0/ is the immediate parent directory of the file which is subject to rename operation.

    -ss is a search string (regex). '\.txt$' regex searches for file with .txt at the end of the filename.

    /path/to/the/directory this is the path where the v_1, v_2 ... directories reside. You can pass the directories ( v_1, v_2 ...) too in place of the parent directory path. For example:

    #from inside the parent directory
    rnm -fo -dp -1  -ns '/pd0/.txt' -ss '\.txt$' v_* 
    

提交回复
热议问题