Posted: . At: 8:09 AM. This was 6 years ago. Post ID: 11608
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


An alternative to the ls command to print a directory listing.


This is a good alternative to the ls command to print a directory listing. This is very useful for quickly viewing the contents of a directory.

┌─[jason@parrot][~/Documents]
└──╼ $find ./  -printf "%f\n" 
./
password-01.kismet.netxml
password-01.cap
read.c
out.xml
netcomm.txt
a.out
password-01.kismet.csv
rockyou.txt
password-01.csv
mysql.txt
notify.js

Here is a more complicated example.

┌─[jason@parrot][~/Documents]
└──╼ $find ./password-*[0-9]*  -printf "%f\n" 
password-01.cap
password-01.csv
password-01.kismet.csv
password-01.kismet.netxml

This simple one-liner will also print the contents of a directory.

┌─[jason@parrot][~/Documents]
└──╼ $for n in *; do printf '%s\n' "$n"; done
a.out
mysql.txt
netcomm.txt
notify.js
out.xml
password-01.cap
password-01.csv
password-01.kismet.csv
password-01.kismet.netxml
read.c
rockyou.txt

Run the pushd command to switch to another directory.

ubuntu ~ $ pushd Documents/

Then run the command again, and it will return to the previous directory.

ubuntu ~/Documents $ pushd
~ ~/Documents

This is yet another way to list the contents of a directory. Wildcards may be used to control the output, and filter for certain files.

ubuntu ~ $ printf '%s\n' *.txt
bandit14.txt
clock.txt
hash.txt
nmap-log-54.159.49.238-.txt
nmap-log-healthcare.gov-.txt
out.txt
pentestlab.txt
rockyou.txt
xyz-wordlist.txt

One final example, this is the lsattr command. This can be used to list files in a directory.

ubuntu ~ $ lsattr -a | grep "txt"
-------------e-- ./pentestlab.txt
-------------e-- ./hash.txt
-------------e-- ./out.txt
-------------e-- ./nmap-log-54.159.49.238-.txt
-------------e-- ./clock.txt
-------------e-- ./bandit14.txt
-------------e-- ./nmap-log-healthcare.gov-.txt
-------------e-- ./rockyou.txt
-------------e-- ./my.txt2
-------------e-- ./xyz-wordlist.txt

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.