I want to move all my drupal files in www folder to html folder. I don't know how to do this in terminal and I'm not sure if all folder and files including hidden ones are drupal in the www folder, is there a way of checking the lesser obvious ones or would www have been empty before and any hidden files will auto recreate?
How to move all files plus hidden to folder down
filesrename
Related Solutions
You can use the advanced globbing patterns in some shells to match all the files in a directory except for those matching a particular pattern. For example, in ksh, bash or zsh, the command
shopt -s extglob ## needed in bash only setopt ksh_glob ## needed in zsh only mv /source/!(*.bak) /destination
will move all files in
/source
to/destination
except for the files matching*.bak
. In zsh, you can also write/source/^*.bak
if you first runsetopt extended_glob
, and more generally (again requiringsetopt extended_glob
)/source/*~*.bak
(or/source/a*~*.bak
for all files whose name begins witha
except for.bak
files, etc).Zsh has a mass copy/move/link command that can be used, amongst others, to move all files except for those matching a pattern. For example, the following command moves all files except
*.bak
from/source
totarget
, and adds.bak
to their name in the process:autoload zmv zmv '/source/(*)~*.bak' '/target/$1.bak'
There are several commands called
rename
floating around. On Debian and Ubuntu,/usr/bin/rename
is a perl script that moves files to a new name generated by a perl expression. You can exclude files from renaming by not generating a new name if the file is to be excluded. For example, the following command (using this particularrename
program) moves all files except*.bak
from/source
to/target
:rename 's!/source!/target! unless m!\.bak$!' /source/*
You can use the
find
command to select the files you want to move. For example, the following command moves all regular files except*.bak
in/source
or a subdirectory into/target
(note that the directory structure is collapsed):find /source -type f \! -name '*.bak' -exec mv {} /target/ \;
or (more efficient if there are many files to move)
find /source -type f \! -name '*.bak' -exec sh -c 'mv "$@" "$0"' /target/ {} +
rsync
is a generalization ofcp
andscp
with very powerful include/exclude rules. For example, the following command copies all files except*.bak
in/source
or a subdirectory into/target
, respecting the directory structure:rsync -a --exclude '*.bak' /source/ /target/
pax
is (amongst other things) anothercp
on steroids. Its exclusion rules are not nearly as powerful as rsync's, but it has the additional ability to rename files as they are copied. If you rename a file to the empty string, it's excluded from the copy. For example, the following command copies all files except*.bak
in/source
or a subdirectory into/target
, and renames the files to.bak
in passing.cd /source && pax -rw -pp -s '/.*\.bak$//' -s '/$/.bak/' . /target/
The example above has the unfortunate side effect of creating directories called
foo.bak
, which can be avoided by combiningfind
withpax
:{ cd /source && find . -type f; } | \ pax -rw -pp -s '/.*\.bak$//' -s '/$/.bak/' /target/
That's a typical job for cpio
or pax
:
find . -type f -mtime -14 -print0 | pax -0 -rw /ModifiedFiles
You could also use the -l
option, to make links instead of copies. It doesn't work properly with the pax
command on Debian, but maybe the one on OS/X doesn't have the same problem.
You can do something similar with cpio
(an ancestor of pax
), but the cpio
implementation on OS/X doesn't seem to support a -0
/--null
option which would allow arbitrary file names. If you know your file names don't contain newline characters, you can still do:
find . -type f -mtime -14 | cpio -dp /ModifiedFiles
Both Debian (GNU) and OS/X versions of cpio
also have a -l
option to make links instead of copies. (and the one of Debian seems to work properly).
Best Answer
With zsh:
mv
will complain that it can't movehtml
to itself, but will still move the rest.With bash:
With ksh93:
POSIXly:
or
(you're likely to get errors for those of the patterns that have no match. That should be harmless but will still cause the exit status to be non-zero so in script you would not be able to distinguish that with a failure to move files).