[Ilugc] Need Help
- From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
- Date: Fri Apr 23 19:44:59 2010
On Fri, Apr 23, 2010 at 1:25 PM, S Alex <alexbe.ece@xxxxxxxxx> wrote:
Hi All,
Plz tell me what will the below script does.
? ?/var/log/ ?-name '*.log' -type f -size ?+64k ? -exec cp {} /home && ?dd
if=/dev/null of='{}'
You left out find I guess.
$ find /var/log -name *.log -type f -size +64k
translates to this in English:
Find the files recursively under /var/log directory of name "*.log"
and of type file(-type f).
We also put another condition that their size should be more than 64 kilobytes.
Until this point it is clear.
now the remaining part.
-exec cp {} /home/
translates to
copy the files that match these criteria to /home.
{} stands for find results.
&& is used in shell to give one command after another in such a way
that the following command
will run only if the previous command returned success.
dd if=/dev/null of={} will truncate a given file to zero bytes. So in
this case, we are truncating all
found files to be of zero bytes length.
Now I would write the same thing like this.
$ find /var/log -name "*.log" -type f -size +64k | xargs -J ^ cp ^ /home
Somehow dd does not take more than one argument for of=.
So it has to be done in a loop.
Something like this would work.
$ find /var/log/ -type f -name "*.log" -size +64k > /tmp/files
$ for f in `cat /tmp/files`
do
dd if=/dev/null of=$f
done
-Girish
--
Gayatri Hitech
web:
http://gayatri-hitech.com
SpamCheetah Spam filter:
http://spam-cheetah.com
Other related posts: