1755724 Members
3639 Online
108837 Solutions
New Discussion юеВ

move file script

 
SOLVED
Go to solution
rhansen
Frequent Advisor

move file script

Hello,

I am trying to move a file on many servers. I am going to use a find command to find the file under /home and if it is found then move it to /var.
Like find / -name abc.txt and if abc.txt is found then move it to /var.

Can someone tell me how I can do this using a simple script.

Thanks in advance.
5 REPLIES 5
davesec
Advisor

Re: move file script

Use:
---
find / -name abc.txt -exec mv {} /var \;
---
rhansen
Frequent Advisor

Re: move file script

How about using the find command only to look at a specific location like just /tmp.
James R. Ferguson
Acclaimed Contributor
Solution

Re: move file script

Hi:

> How about using the find command only to look at a specific location like just /tmp.

Of course, in fact you can look at multiple locations all at once:

# find /tmp /home -xdev -type f -name "*.log"

It is generally a good idea to add the '-xdev' argument to prevent crossing mountpoints. This can be especially important when visiting the '/' directory.

The '-type f' argument means confine results only to files; not directories, for instance.

The double quotes around the '-name' argument prevent the shell from expanding the filename. This lets the expression be passed along to 'find'.

Regards!

...JRF...
rhansen
Frequent Advisor

Re: move file script

Thanks.
James R. Ferguson
Acclaimed Contributor

Re: move file script

Hi (again):

I see that you are new to this Forum. Welcome!

That said, please read the link below about points. Points are not only a way of saying "thanks!" but bread-crumbs for future trollers to find the tastiest (most applicable) solution:

http://forums.itrc.hp.com/service/forums/helptips.do?#28

...JRF...