Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on ls command

Status
Not open for further replies.

fireant

Technical User
Aug 12, 2001
28
PH
How do I use ls to exclude subdirectories, the . and .. but include all other files? I'll then just wc -w to get the total count of files?

TIA,
Louie C.
 
This is one way:
for i in $(ls *)
do
if [ -f $i ] ; then
echo $i
fi
done

man find, for another.

Good Luck.
 
using ls with the -A option will leave out the . and .. listing.

eg. ls -lA

should only list files with their details
 
Thanks for the reply guys. However, I found predamarcel's to be most helpful.

I'd like to follow up predamarcel on a few things.

How does the caret work generally? I understood the reverse matching on grep but not the caret (^). And what's the -1 at the end of the command for?

Hope you don't mind. =)

Thanks a lot everyone! Louie C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top