Acclaimed Contributor Acclaimed Contributor
Re: Finding file extension
It would be helpful if you provided a few examples but something like this:

cp *.gz /xxx/yyy/gzdir/
cp *.dat /xxx/yyy/tardir/

Note: UNIX has no concept of a file extension; that belongs to another OS.

If you wish to strip off a suffix then something like this:


typeset BASE=""
typeset FNAME=""
typeset SUFFIX=".gz"

ls | while read FNAME
BASE=$(basename "${FNAME}" "${SUFFIX}")
if [[ "${BASE}" != "${FNAME}" ]]
echo "Basename: ${BASE}"
# do your copy here

You only see the base part of the filename with the suffix stripped off. Files not matching the suffix are ignored. Man basename for details.
If it ain't broke, I can fix that.