1849240 Members
4478 Online
104042 Solutions
New Discussion

moving files

 
SOLVED
Go to solution

moving files

I want to move all html-files for a given subtree one directory up.

For example:
mv ./bla/dir1/subdir1/*.html ./bla/dir1/
mv ./bla/dir2/subdir2/*.html ./bla/dir2/
mv ./bla/dir2/subdir2/1/*.html ./bla/dir2/subdir2/
...

I have tried the following:

find . -name *.html|xargs -i -p mv {} ../{}
(-p for interactivity)

which does not work (of course). The output is:
mv ./bla/dir1/subdir1/doc1.html .././bla/dir1/subdir1/*.html ?...

Not beeing familiar with awk or sed I'd like to know how to replace the string before the last slash to "..".

Or is there a better way of doing this?

Thanks,
Aleks

4 REPLIES 4
Bharat Katkar
Honored Contributor

Re: moving files

Does this command works individualy for you:
mv ./bla/dir1/subdir1/*.html ./bla/dir1/

and Also What you are expecting exactly!! whether you want to move that same in one single command



You need to know a lot to actually know how little you know
Nicolas Dumeige
Esteemed Contributor

Re: moving files

Hello Alexs,

Can get xargs to work either! Anyway, test this :

find . -name '*.html' | while read line
do
echo mv $line `dirname $line | sed -e 's@\/[^\/]*$@@'`
done

Cheers

Nicolas
All different, all Unix
Bernhard Mueller
Honored Contributor
Solution

Re: moving files

Aleks,

what about
cd /
find /path/to/subdir -type d | while read dir
do
cd $dir
mv *.html ..
cd /
done

Regards,
Bernhard

Re: moving files

Thanks for your replies!

With the hints from you I made the following script ($1 being the wanted files(s) ):

CUR_DIR=`pwd`
# Remove . from results of find
FILES=`find . -name $1 | cut -c 2-`

for file in $FILES
do
# Construct absolute path
file=$CUR_DIR$file

cd `dirname $file`
mv `basename $file` ../
done
cd $CUR_DIR

Aleks