Get List of Folder Names With ls and awk

Get List of Folder Names With ls and awk

On a day-to-day basis being a Linux Administrator you get ask for odd things, this is one of those things "can you provide me a list of all webites on a server" or all logs in a directory, etc. There's a bunch of tedious ways to do it, but the built in UNIX tools are great.

login to your server, you do not need root permissions for this task.

cd to the directory you want to get the list from

-bash-4.1$ ls -l | awk -F " " '{print $9}'
AngryIPScanner
bginfo
Drivers
Local_Backup_and_Restore.lnk
Local_Group_Policy.lnk
PuTTY
Scripts
Services.lnk
Xming
 

so the ls -l provides the list format, the awk -F provides the field seperator, in this case the " " is a blank space, so after the 9th blank space, print everything that comes from the outupt of ls -l in the 9th field.

 

That's it!

Hosted Linux Servers at www.zwiegnet.com/go