Move files to directories based on extension

后端 未结 6 1481
慢半拍i
慢半拍i 2020-12-14 02:06

I am new to Linux. I am trying to write a shell script which will move files to certain folders based on their extension, like for example in my downloads f

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 02:40

    You can use for loop to traverse through folders and subfolders inside the source folder. The following code will help you move files in pair from "/source/foler/path/" to "/destination/fodler/path/". This code will move file matching their name and having different extensions.

    for d in /source/folder/path/*; do
        ls -tr $d |grep txt | rev | cut -f 2 -d '.' | rev | uniq | head -n 4 | xargs -I % bash -c 'mv -v '$d'/%.{txt,csv} /destination/folder/path/'
        sleep 30
    done 
    

提交回复
热议问题