Operating System - HP-UX
1828354 Members
3011 Online
109976 Solutions
New Discussion

Script to create an empty file in each directory

 
SOLVED
Go to solution

Script to create an empty file in each directory

I need to create an empty file (touch) in every directory hanging from mount point /data/webroot. Since the directory tree is a very big one, I`d appreciate any suggestions to accomplish this task with a script.
Thanks a lot,
Fernando
5 REPLIES 5
Biswajit Tripathy
Honored Contributor
Solution

Re: Script to create an empty file in each directory

How about:

for dir in `find /data/webroot -type d`
do
touch $dir/filename
done

(Test before use).

- Biswajit
:-)
Slawomir Gora
Honored Contributor

Re: Script to create an empty file in each directory

Hi,

try this

find /data/webroot -type d -exec touch {}/empty_file_name \;


replace empty_file_name with your file_name
Peter Godron
Honored Contributor

Re: Script to create an empty file in each directory

Fernando/slawomir,
it may be just me, but I can't get Slawomirs solution to run.
Although the {} should be replaced with the result of the find, they don't seem to be?!
Can somebody please clarify/re-test?
Biswajit's solution works.
Thanks
Slawomir Gora
Honored Contributor

Re: Script to create an empty file in each directory

Hi Peter,

I tried this on linux box and it works,
on hpux it does not work.

Re: Script to create an empty file in each directory

Me too, that is why I assigned 10 points to the first answer -it`s just perfect and the answer came just some minutes after being posted- and only 5 to the second answer which is not so good. Under hpux I also tried and got
(root@xenon1):/>find /tmp/a -type d -exec touch {}/.empty_file_name \;
touch: {}/.empty_file_name cannot create