Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've bunch of folders in folder A. I want to move files from all those folders to A.

Or

I want to cut all files from child folders and paste them in parent folder.

How to do that?

share|improve this question
1  
I haven't really tested this to be foolproof or anything, but have you tried simply entering this command from Folder A in a terminal: mv */* .? –  Marty Fried Jun 5 '12 at 6:06
    
Are you sure there are no duplicate file names? –  jippie Jun 5 '12 at 6:46
    
mv */* . won't move files from subfolders' subfolder. –  virpara Jun 5 '12 at 18:03
    
@jippie yep, there are no duplicate names –  virpara Jun 5 '12 at 18:03
add comment

3 Answers

up vote 5 down vote accepted

Go to your A directory and run find -mindepth 2 -type f -print -exec mv {} . \;

which means "find all files in this directory and its sub-directories and execute mv with target directory . for each file found to move them to current directory.

share|improve this answer
1  
it also tries to move files which are already in parent directory. –  virpara Jun 5 '12 at 17:57
    
virpara: now this your edition forgets all files in .dot directories. Revised it with -mindepth 2 instead to suppress warnings. –  Tuminoid Jun 6 '12 at 7:04
add comment

Well you could create a file and name it "cutme" (to create a file called cutme in the terminal type nano cutme. To save it press CTRL+X then press ENTER.) for example and paste the following in it assuming that:

  1. You want to do this recursively (In subfolders and subfolders of those subfolders)
  2. You want to skip moving the script file
  3. You have permissions to move the files in that folder
  4. Files may or may not include spaces in their names

find * -type f -print -not -type d -and -not -regex 'cutme' -exec mv {} .. \;

Note the name cutme inside the line. It should be the same as the script you will run.

After creating the file and pasting the above line, run the following in the same folder as the script:

chmod +x cutme. This will give your new file the "Executable" flag so you can execute it like this: ./cutme.

share|improve this answer
    
Why should I try to move files those are already in parent directory? –  virpara Jun 5 '12 at 17:56
    
You would run the script from inside the folder. Every file in it, if inside a subfolder or not would move to the folder's parent folder. The parent folder here is the parent in relation to where the script is. Actually by changing the last 2 dots you can tell where to move all files inside a folder where you run the script. –  Luis Alvarado Jun 5 '12 at 18:01
add comment

one simple way i did it was issuing three commands

mv *.* ..

mv * ..

mv *. ..

Cheers newbie

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.