Operating System - HP-UX
1831185 Members
2835 Online
110021 Solutions
New Discussion

Move 2004 files to new folder

 
SOLVED
Go to solution
Carles Viaplana
Valued Contributor

Move 2004 files to new folder

Hello,

I need to move all 2004 files from a directory to new one. Is there any way to do that with just one command?

Thanks in advance for your help.
Regards,

Carles
11 REPLIES 11
Arunvijai_4
Honored Contributor

Re: Move 2004 files to new folder

Hi Carles,

You can use # cp -R //*

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Warren_9
Honored Contributor

Re: Move 2004 files to new folder

hi,

for FILE in `cat LIST`
do
mv $FILE /new_dir/
done

GOOD LUCK!!
Peter Godron
Honored Contributor

Re: Move 2004 files to new folder

Carles,
you wanted to move (not copy) the directory:
mv dir1 dir2
(in effect a reneame of the directory)

Otherwise you may find the command returning problem with number of files being copied.
Enrico P.
Honored Contributor
Solution

Re: Move 2004 files to new folder

Hi,

cd /source_dir

for i in $(ll|grep 2004|awk '{print $9}'); do
mv $i /dest_dir
done

Enrico
Johnny Damtoft
Regular Advisor

Re: Move 2004 files to new folder

Are you saying that there is 2004 files in one folder you wanna move?

Or is it all files in one folder, that is created in the year 2004?

Raj D.
Honored Contributor

Re: Move 2004 files to new folder


Hi Carles,

You can use

# cp -p -r /dir1/* /dir2/

It will copy subdirectories as well with same permissions.


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
rariasn
Honored Contributor

Re: Move 2004 files to new folder

Hi Carles,

$ cd olddir
$find . -depth -print | cpio -pdm newdir

rgs,

ran
MarkSyder
Honored Contributor

Re: Move 2004 files to new folder

I think Enrico has given you the correct answer. I have only one thing to add: Enrico's answer will copy not only files modified in 2004 but files with a size of (for example) 2004, 12004, etc. Depending how many files you are dealing with, you may want to direct the output to a temporary file first to make sure you don't move files that should remain in situ.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Carles Viaplana
Valued Contributor

Re: Move 2004 files to new folder

Hi all,

Thanks for your replies, but as Mark said I need to move all files modified in 2004.

About any possibility to move files with size of 2004, 12004,... I can check it before and in case there aren't I can execute command sent by Enrico.

Regards,

Carles
jon2
Advisor

Re: Move 2004 files to new folder

Not a full answer - just a thought (no system for me to test on) .... but

find /xxx -mtime +NNNNN -exec mv {} /newdir \;


If you can somehow use mtime to select files from 2004....

There also is an option -newer (so maybe there is an older too so you could say older than a particular file... If there is not you can add "!" to say not newer than).

You can create a file of the correct date with touch -t YYMMDDhhmm FILE to compare against.
Carles Viaplana
Valued Contributor

Re: Move 2004 files to new folder

Finally I use Enrico solution and it works fine as all files I should move are bigger than 2004 bytes I set grep command with " 2004 " value.

Thanks to all for your help!
Regards,

Carles