Re: [opensuse] Re: BASH - better way to get total number of files matching glob??
- From: Per Jessen <per@xxxxxxxxxxxx>
- Date: Mon, 07 Jun 2010 13:12:00 +0200
Joachim Schrod wrote:
Per Jessen wrote:
David C. Rankin wrote:
Guys,
Doing a quick backup of config files (like .bashrc) from within
bashrc and I need to find a better way to find the total number of
files matching a glob in a directory. Currently I'm using:
total=$(ls $budir/bashrc-* | wc -l)
to determine how many copies I have in my bashrc.tar.bz2 backup +
the new one I just copied to the backup location so I can determine
the number to delete to just save the last 3 when I tar it up again..
The ls | wc combination works fine, but I don't like the fact that
there is a pipe in the middle of it. If there is a cleaner way to do
it, let me know.
I can't get rid of the pipe for you, but personally I'd do:
total=$(find $budir -iname bashrc-* -type f | wc -l)
That barfs if you're in the directory with the bashrc files.
You need to add single quotes around the -iname arg.
Or add a backslash, whic I always do:
total=$(find $budir -iname bashrc-\* -type f | wc -l)
--
Per Jessen, Zürich (18.4°C)
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
- References:
- [opensuse] Re: BASH - better way to get total number of files matching glob??
- From: Joachim Schrod
- [opensuse] Re: BASH - better way to get total number of files matching glob??
- Prev by Date: [opensuse] Re: BASH - better way to get total number of files matching glob??
- Next by Date: [opensuse] Re: BASH - better way to get total number of files matching glob??
- Previous by thread: [opensuse] Re: BASH - better way to get total number of files matching glob??
- Next by thread: [opensuse] Re: BASH - better way to get total number of files matching glob??
- Index(es):
Relevant Pages
|