Welcome to the new design! Please report any bugs or issues, thanks :)
Web Dev + WordPress + Security

List All Files and Folders Recursively via Terminal

From time to time I have occasion to generate a list all WordPress files or similar. As I’m not an expert in Terminal, it took awhile to figure out the magic recipe.. now having collected some useful commands, I want to post ‘em for future reference.

List all files, first level folders, and their contents

ls * -r

List all first-level subdirectories and files

file */*

Save file list to text

file */* *>> ../files.txt
file */* -r *>> ../files-recursive.txt

Get everything

find . -type f

Save everything to file*

find . -type f > ../files-all.txt

List contents of directory

mac:wordpress username$ ls -m1 *>> file-list.txt

Outputs this:

/
	index.php
	license.txt
	readme.html
	wp-activate.php
	wp-app.php
	wp-blog-header.php
	wp-comments-post.php
	wp-config-sample.php
	wp-cron.php
	wp-links-opml.php
	wp-load.php
	wp-login.php
	wp-mail.php
	wp-pass.php
	wp-register.php
	wp-settings.php
	wp-signup.php
	wp-trackback.php
	xmlrpc.php

Then if you want more information, try this:

mac:wordpress username$ ls -la *>> file-list-full.txt

..which outputs something like this:

-rw-r--r--@ 1 username  staff    397 May 25  2008 index.php
-rw-r--r--@ 1 username  staff  16899 Jun  8  2011 license.txt
-rw-r--r--@ 1 username  staff   9202 Apr 20 12:44 readme.html
-rw-r--r--@ 1 username  staff   4268 Oct 20  2011 wp-activate.php
-rw-r--r--@ 1 username  staff  40272 Oct 28  2011 wp-app.php
-rw-r--r--@ 1 username  staff    274 Nov 20  2010 wp-blog-header.php
-rw-r--r--@ 1 username  staff   3989 Apr 16 22:12 wp-comments-post.php
-rw-r--r--@ 1 username  staff   3177 Nov  1  2010 wp-config-sample.php
-rw-r--r--@ 1 username  staff   2684 Sep  9  2011 wp-cron.php
-rw-r--r--@ 1 username  staff   1997 Oct 23  2010 wp-links-opml.php
-rw-r--r--@ 1 username  staff   2546 Nov 15 14:47 wp-load.php
-rw-r--r--@ 1 username  staff  27695 Nov 23 06:03 wp-login.php
-rw-r--r--@ 1 username  staff   7777 Aug  5  2011 wp-mail.php
-rw-r--r--@ 1 username  staff    413 Sep 19  2011 wp-pass.php
-rw-r--r--@ 1 username  staff    334 Dec  9  2010 wp-register.php
-rw-r--r--@ 1 username  staff   9913 Oct 18  2011 wp-settings.php
-rw-r--r--@ 1 username  staff  18545 Nov 15 19:44 wp-signup.php
-rw-r--r--@ 1 username  staff   3702 Feb 24  2010 wp-trackback.php
-rw-r--r--@ 1 username  staff   3266 Apr 17  2011 xmlrpc.php

Getting serious

This is from Terminal fun: Options for printing folder and subfolder contents:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

..which outputs this:

 |-wp-admin
 |---css
 |---images
 |-----screenshots
 |---includes
 |---js
 |---maint
 |---network
 |---user
 |-wp-content
 |---plugins
 |-----akismet
 |---themes
 |-----twentyeleven
 |-------colors
 |-------images
 |---------headers
 |-------inc
 |---------images
 |-------js
 |-------languages
 |-----twentyten
 |-------images
 |---------headers
 |-------languages
 |-wp-includes
 |---Text
 |-----Diff
 |-------Engine
 |-------Renderer
 |---css
 |---images
 |-----crystal
 |-----smilies
 |-----wlw
 |---js
 |-----crop
 |-----imgareaselect
 |-----jcrop
 |-----jquery
 |-------ui
 |-----plupload
 |-----scriptaculous
 |-----swfupload
 |-------plugins
 |-----thickbox
 |-----tinymce
 |-------langs
 |-------plugins
 |---------directionality
 |---------fullscreen
 |---------inlinepopups
 |-----------skins
 |-------------clearlooks2
 |---------------img
 |---------media
 |-----------css
 |-----------js
 |---------paste
 |-----------js
 |---------spellchecker
 |-----------classes
 |-------------utils
 |-----------css
 |-----------img
 |-----------includes
 |---------tabfocus
 |---------wordpress
 |-----------css
 |-----------img
 |---------wpdialogs
 |-----------js
 |---------wpeditimage
 |-----------css
 |-----------img
 |-----------js
 |---------wpfullscreen
 |-----------css
 |---------wpgallery
 |-----------img
 |---------wplink
 |-------themes
 |---------advanced
 |-----------img
 |-----------js
 |-----------skins
 |-------------default
 |---------------img
 |-------------highcontrast
 |-------------o2k7
 |---------------img
 |-------------wp_theme
 |---------------img
 |-------utils
 |---pomo
 |---theme-compat

That’s all for this post, but there’s more on the way :)

Jeff Starr
About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
GA Pro: Add Google Analytics to WordPress like a pro.

2 responses to “List All Files and Folders Recursively via Terminal”

  1. Josh Eaton 2013/08/24 1:19 pm

    Have you seen the tree command? You have to install it with something like Homebrew, but it’s quicker than typing out that long pipeline with the ls command. :)

  2. How would you attach file –mime-encoding to this?

    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
BBQ Pro: The fastest firewall to protect your WordPress.
Thoughts
2 things I hate to see in stylesheets: _ and #
Love VLC media player but it fails miserably when it comes to randomizing large collections of mp3 and other files.
Dashlane redesigned, stating proudly they "removed all filigree". Should have kept it; the app now looks generic and boring. Killed your identity.
Working on integration for setaPDF + EDD on the new books subdomain. Good times.
Toggle visibility of hidden files on Mac: Cmd + Shift + .
Great tool for checking browser caching for web pages and all included files.
The new minimalist design styled by 14KB of CSS (uncompressed and un-minified). That covers 850+ posts and pages spanning 15 years of diverse content.