Search code examples
shelldirectorymv

Move files from subfolders into parent folder


I downloaded a lot of files from S3, dumped them all into a new folder called contracts. Now, within contracts, each file is in its own named (as numbers) folder, ie 55, 66, etc.

Looking for a script to take all files within all these subfolders, move them into parent folder (/contracts), and delete the then empty folders.


Solution

  • yes | cp -a /contract/*/* /contract
    

    /contract means your contract directory resides in / but you can change the path wherever you want e.g. yes | cp -a /var/contract/*/* /var/contract

    This is from and to path. Please note change cp to mv if you want to move instead of copy. In your case this will work yes | cp -a contracts/*/* contracts