I've got a public
folder that includes .html
and non .html
files in its root and subfolders. I need to move all non .html
files to a subfolder of the public
folder, e.g. to public/assets
, preserving their full path.
So far I got something like this:
mkdir -p public/assets
find public -type f -not -name "*.html" -print0 | xargs -0I{} mv {} public/assets/
It doesn't work correctly, because it doesn't move files with full path, e.g. if there's a file public/foo/bar.js
, it will be moved to public/assets/bar.js
and not into public/assets/foo/bar.js
.
I also tried another version:
mkdir -p public/assets
find public -type f -not -name "*.html" | sed 's#\(public\)\(.*\)#\1\2 public/assets\2#' | xargs -I% mv %
but it complains about incorrect syntax of mv
command. I pass only one parameter to it, but after running sed
it consists of 2 paths separated with one space, so I hoped it will treat it as 2 parameters.
It would be also great, if there was a way to remove empty folders after moving all files, but it's not necessary.