simple perl or unix listing quetsion: how do I list only the files and directories?

endervalentine

Senior member
Jan 30, 2009
700
0
0
yeah, I know, sounds really stupid ... but is there a way to do a listing on a directory that will return all the files and directories without the " ", "." and ".." ?

Right now, I'm stuffing the return values into a hash table and then deleting it, figure there must be a 'cleaner' and more elegant way to do this?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Not really, . and .. are valid directory entries so when you do a readdir they're going to be in there.
 

Platypus

Lifer
Apr 26, 2001
31,046
321
136
ls -lA | awk '{print $8}'

gives you a list of all files/dirs without the . and ..

note, you may need to adjust the $8 to another number depending on your environment
 
Last edited:

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
I've usually just seen '.' and '..' handled with quick if statements in perl scripts.