Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to SSH. 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.

share|improve this question
Why do you need to use SSH, and presumably scp and sftp? Can you not get a shell on the remote server? – uther Feb 5 '13 at 21:02

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 
share|improve this answer
@uther - it's not always desirable to execute commands interactively, i.e. automated backup scripts on a cron job. – Stephan Feb 5 '13 at 23:00

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.)

share|improve this answer
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 '13 at 21:41

Your Answer


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.