find - What is the linux command to move the files of subdirecties into one level up respectively -
the path structure of files on server similar shown below,
/home/sun/sdir1/mp4/file.mp4 /home/sun/collection/sdir2/mp4/file.mp4
i move files of "mp4" 1 level up(into sdir1 , sdir2 respectively)
so output should be,
/home/sun/sdir1/file.mp4 /home/sun/collection/sdir2/file.mp4
i have no idea this, not tried yet anything...
there different ways solve problem
if want move specific files, run these commands:
cd /home/sun/ mv sdir1/mp4/file.mp4 sdir1/ mv sdir2/mp4/file.mp4 sdir2/
if want move mp4 files on directories (sdir1 , sdir2), run these commands:
cd /home/sun/ mv sdir1/mp4/*.mp4 sdir1/ mv sdir2/mp4/*.mp4 sdir2/
edit:
- make script iterates directories:
create script , name , edit favorite editor (nano, vim, gedit, ...):
gedit folderiterator.sh
the script file content is:
#/bin/bash # go desired directory cd /home/sun/ # action on subdirectories in folder dir in /home/sun/*/ dir=${dir%*/} mv "$dir"/mp4/*.mp4 "$dir"/ # if want remove subdirectory after moving files, uncomment following line # rm -rf "$dir" done
save file , give execute permissions:
chmod +x folderiterator.sh
and execute it:
./folderiterator.sh
Comments
Post a Comment