Problem with bash script
Matthew Seaman
m.seaman at infracaninophile.co.uk
Tue Jun 16 16:58:49 UTC 2009
Carmel NY wrote:
> I am attempting to write a simple Bash script that will find all the
> '*.pem' files in a directory structure and move them to another
> directory. It seems to work until I get to the copy part where it fails.
>
> My scripting skills are not that good. Perhaps someone could tell me
> what I am doing wrong.
>
> This is the script:
>
> #! /usr/bin/env bash
>
> # Save the field separator
> oIFS=$IFS
>
> # Set it to line breaks
> IFS=$'\n'
>
> for i in $(find ./ -name "*.pem" -print); do
>
> # Get the basename
> BN=$(basename $i)
>
> # copy the file to another directory using the base name
> cp $i /usr/home/tmp/$BN
>
> done
>
> # Reset the IFS variable
> IFS=$oIFS
>
> exit
That's a one-liner:
% find . -depth -name '*.pem' -print0 | cpio -0pdmu /usr/home/tmp
Actually, that just /copies/ all of the *.pem files to the other directory
tree, so if you want to remove the original files, you'ld also need to do:
% find . -name '*.pem' -delete
once you're sure everything has copied across OK, and with the proviso
that '.' is neither a parent or child of /usr/home/tmp
Cheers,
Matthew
--
Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard
Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
Kent, CT11 9PW
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20090616/201d5b9b/signature.pgp
More information about the freebsd-questions
mailing list