Search code examples
linuxfile-renamebatch-renamemv

Add suffix to all subdirectories in current directory in Linux


In current directory: folders: 001, 002, 003, 004......etc. I want to add the suffix '_ses-1' to all folders and it makes for example 001_ses-1

Tried

for d in *; do mv "$d" "${d}_ses-1"; done


find ./ -type d -exec bash -c mv "$folder" "${folder}_ses-1"

All failed and would like some help to figure this out.


Solution

  • The first command (for) won't match only directories.

    The second (find) is problematic if you have nested directories.

    If you don't have nested folders, you can use:

    find . -maxdepth 1 -type d -exec mv {} {}_ext \;