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. Joachim -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod Email: jschrod@acm.org Roedermark, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org