A wonderful way to list your project files 9

Posted by labria on September 10, 2009

This article is published as a reply to the last few articles on the thoughtbot blog.

Some time or another during the project development you may wonder: «What files does my project include?» or «Why am I a Star Wars fan anyway?». This article will focus on the first question, leaving the second to your own reflection.

Any shell you might be using comes with a lot of useful tools. The one of interest today is ls

Here's the most simple example of its usage in a Rails project

 
sample_project $ ls
README		app		db		lib		public		test		vendor
Rakefile	config		doc		log		script		tmp
 

As a little more complex example, you might want to get the list of your model files:

 
sample_project $ ls app/models/
comment.rb	post.rb
 

Or, it even can do crazy stuff, like list all your model files AND controller files AND helper files! Now thats some useful magic, isn't it?

 
sample_project $ ls app/*
app/controllers:
application_controller.rb	comments_controller.rb		posts_controller.rb
 
app/helpers:
application_helper.rb	comments_helper.rb	posts_helper.rb
 
app/models:
comment.rb	post.rb
 
app/views:
comments	layouts		posts
 

ls can do much. much more. Go check out the manual page here, you'll be amazed.

Note to Windows users: you also have a similar command, named dir.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Aleksandr Koss Thu, 10 Sep 2009 12:23:25 EDT

    Unbelievable! Thank you very much! I’ll know now!

  2. [...] robots, we have a reply to your outstanding articles: A wonderful way to list your project files. Please read it carefully, you definitely will find something useful for you! Thanks to @labria for [...]

  3. Dieinzige Thu, 10 Sep 2009 12:46:36 EDT

    =)

  4. sasha Thu, 10 Sep 2009 12:49:59 EDT

    find app -type d | sort | awk ‘{print “\n”$1″:”; system(”ls ” $1)}’

  5. Twitted by calavera Thu, 10 Sep 2009 13:55:38 EDT

    [...] This post was Twitted by calavera [...]

  6. mikhailov Thu, 10 Sep 2009 14:34:22 EDT

    черный юмор пошел нынче в моду

  7. da4nik Thu, 10 Sep 2009 14:34:24 EDT

    поржал

  8. Dan Croak Thu, 10 Sep 2009 15:25:22 EDT

    Hi Labria,

    Point well taken. “tail” is part of any developer’s toolbox.

    I never had a formal computer science education and have picked up scraps of UNIX on the job.

    The latest post wasn’t about tail so much as an application of it that I’ve found helpful recently while debugging some testing issues in Rails.

    It’s probably basic, but I don’t feel the need to hold back what might seem basic to many readers if it comes in handy for a few others.

    I try to keep such articles short so I’m not wasting anyone’s time, and in the theme of “this has been working for me; I hope it comes in handy for someone else, too.”

    Thanks for reading.

  9. Alexey Osipenko Thu, 10 Sep 2009 16:47:16 EDT

    A-A-A! моск взорван

Comments