move all files in current directory to upper directory including dotfiles, files starting with .. and dash
There are many ways to chop a tree down as we all know.
- Here are a couple ways to do it.
- With
mv
$ mv * .[^.]* ..
Important note: this will not match files starting with ..
- If you want to match files starting with
..
and--
use the belowmv
command instead.
$ mv -- * .[^.] .??* ..
- which will match everything except
.
and..
.. *
will match everything that doesn't start with a.
and.[^.]
will match all 2 character filenames starting with a dot except..
,and.??*
will match all filenames starting with a dot with at least 3 characters. As well as--
to match files starting with a dash.
- With
shopt
$ (shopt -s dotglob; mv -- * ..)
this has got you covered for files starting with ..
- The above is wrapped in parens so that it executes in a subshell, and so files beginning with
--
are not interpreted as arguments tomv
.
- Another alternative with
find
$ find . -mindepth 1 -maxdepth 1 -exec mv -t.. -- {} +
- If you have
rsync
on your machine you can use this. (Windows doesn't really have a good port ofrsync
that I am aware of. If anyone knows of one for Git Bash, I would love to know.)
$ rsync -a --remove-source-files . ..
With the above command, we are telling rsync to copy the content of
.
into..
The switch
-a
enables recursion into.
,subdirectories and enables some other common options.The switch
--remove-source-files
tellsrsync
to remove the source files after a successful copy, i.e. it makesrsync
behave similarly to themv
command.Enjoy.
Written by Jupiter St John
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#