Super User is a question and answer site for computer enthusiasts and power users. 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

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?

share|improve this question

marked as duplicate by Dennis, 8088, 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.

up vote 4 down vote accepted

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

mv .[^.]* somewhere/
share|improve this answer
This will work in most of the cases but will ignore files and directories beginning with two dots. For example or – Matteo Aug 30 '12 at 14:13
@Matteo: I already mention the issue in the answer. – choroba Aug 30 '12 at 14:21
@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.

share|improve this answer

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.

share|improve this answer

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
share|improve this answer

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 \;
share|improve this answer

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