1

I would like to know how to move all the files, not the folder or directory, to an existing folder or directory two levels down.

1
  • Why do you need to use SSH, and presumably scp and sftp? Can you not get a shell on the remote server?
    – George M
    Feb 5, 2013 at 21:02

2 Answers 2

1

You'll want to use the find command.

find . -type f -name "*" -print0 | xargs -0 -I {} mv {} ../backup_dir ; mv ../backup_dir ./new/directory

Note that I've moved the files to a directory to one directory up, to prevent find from being stuck in a loop finding the new files that you're moving. Then move the directory two levels down.

If you need only files in the current directory, you can use the command:

find . -type f -maxdepth 1 -name "*" -print0 | xargs -0 -I {} mv {} ../backup_dir 
1
  • @uther - it's not always desirable to execute commands interactively, i.e. automated backup scripts on a cron job.
    – Stephan
    Feb 5, 2013 at 23:00
0

If you have zsh available, this is pretty simple. The pattern * matches all files (including directories). To match only regular files, add the glob qualifier .. Glob qualifiers are a zsh feature.

mv *(.) existing/subsubdirectory/

(Actually * skips files whose name begins with a . (“dot files”). This is probably not a concern here, but if you do need to move those as well, add a D inside the parentheses.)

1
  • Guys, I appreciate your efforts. I got more than I bargained for. Because I'm new to using PUTTY, I was able to copy the files, but will keep the code you offered to try later when I'm more comfortable. Thanks again for all the help.
    – user31836
    Feb 8, 2013 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .