[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: quick howto-command questions?



On Tue, Mar 20, 2001 at 09:12:41AM -0000, john smith wrote:
> 
> 1. How can I find out the total number of files (also hidden)
> in the current directory?

	#!/path/to/perl
	my $dir = shift || '.';
	opendir DIR,"<$dir";
	my @f = grep(
		-f $_,	# files only, no dirs or other stuff
		readdir DIR);
	closedir DIR;
	print scalar @f;

> 2. How can I find out the total number of executable files
> (also hidden) in the current directory?

	#!/path/to/perl
	my $dir = shift || '.';
	opendir DIR,"<$dir";
	my @f = grep(
		-x $_,	# executable by current UID
		readdir DIR);
	closedir DIR;
	print scalar @f;

> 3. how to find the total number of files of a given an
> extension?  (ex."*.tar.gz")

	ls *.some.ext | wc -l

> 4.how to list files alphabetically that end in "*.c"?

	ls *.c

(ls defaults to lexical/alphabetic sorting; if yours doesn't, you
either have a script that's running in place of the normal
/bin/ls, or you have an alias that includes a 'sort by something
else' command line option.)

-- 
It is always hazardous to ask "Why?" in science, but it is often
interesting to do so just the same.
		-- Isaac Asimov, 'The Genetic Code'

will@serensoft.com
http://newbieDoc.sourceforge.net/ -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!



Reply to: