Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jun 2009 17:58:36 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Carmel NY <carmel_ny@hotmail.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Problem with bash script
Message-ID:  <4A37CF3C.5000808@infracaninophile.co.uk>
In-Reply-To: <BLU0-SMTP586D9F12148D0B6683B635933F0@phx.gbl>
References:  <BLU0-SMTP586D9F12148D0B6683B635933F0@phx.gbl>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig3BD5A5F4D1015FA78118F8E8
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

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=
=2E
>=20
> My scripting skills are not that good. Perhaps someone could tell me
> what I am doing wrong.
>=20
> This is the script:
>=20
> #! /usr/bin/env bash
>=20
> # Save the field separator
> oIFS=3D$IFS
>=20
> # Set it to line breaks
> IFS=3D$'\n'
>=20
> for i in $(find ./ -name "*.pem" -print); do
>=20
> # Get the basename
> BN=3D$(basename $i)
>=20
> # copy the file to another directory using the base name
> cp $i /usr/home/tmp/$BN
>=20
> done
>=20
> # Reset the IFS variable
> IFS=3D$oIFS
>=20
> 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 director=
y
tree, so if you want to remove the original files, you'ld also need to do=
:

 % find . -name '*.pem' -delete=20

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


--=20
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                  Kent, CT11 9PW


--------------enig3BD5A5F4D1015FA78118F8E8
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEAREIAAYFAko3z0IACgkQ8Mjk52CukIyb1QCfbWLKF5gh4ogdyVjDJeWLLNVm
6eQAnRvLzM2UYnR4T7kxFMeCT8i+nuf4
=TYen
-----END PGP SIGNATURE-----

--------------enig3BD5A5F4D1015FA78118F8E8--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4A37CF3C.5000808>