Possible Duplicate:
Can I keep . and .. out of .* expansion?

I know about

mv * ~/whatever
mv .* ~/whatever

but that tries to move . and .., which just caused me a bunch of pain. Is there a way to mv all the files, including the .* files, but exclude the current directory and it's parent?

marked as duplicate by Dennis, Gaff, Nifle, Indrek, Canadian Luke Aug 31 '12 at 5:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Just tell bash there is the second character and it is not a dot. Will not move files named like ..file, though.

mv .[^.]* somewhere/
  • This will work in most of the cases but will ignore files and directories beginning with two dots. For example ..name or ....name. – Matteo Aug 30 '12 at 14:13
  • @Matteo: I already mention the issue in the answer. – choroba Aug 30 '12 at 14:21
  • 1
    @chroba sorry: should learn to read the whole answer :-) – Matteo Aug 30 '12 at 14:25

From the Bash manual, shopt section:

dotglob     If set, bash includes filenames beginning with a `.' in the results
            of pathname expansion.

shopt can be used to set certain "shell options" as explained in the manual. See man bash.


shopt -s dotglob
mv * ~/whatever

does what you want. Test it with e.g.

shopt -s dotglob
ls -d *

to see which files are matched.

Since it is the de facto Bash way as per the manual, no hidden surprises should turn up regarding files with tricky names. If it does, it is by definition a bug in Bash.


Try this:

mv .[a-zA-Z0-9]* ~/whatever

Unless you have dot files that start with ._ or other non-alphanumeric characters, it should get them all.


If you don't want to move directories, this will move all files to ./foo/:

$ find . -type f  | while read n; do mv "$n" foo/; done

If you do need to do directories also, try:

$ find . | grep -vP '^\.$' | while read n; do mv "$n" foo/; done

Use find which excludes . and ..:

find . -name ".*" -mindepth 1 -maxdepth 1

and check the result. To move the files

find . -name ".*" -mindepth 1 -maxdepth 1 -exec mv {} ~/whatever \;

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