Command Line

The ls is my most used command when working with files especially working with command line stuff.

ls is a command to list files in Unix and Unix-like operating systems. While, ls on its own is quite useful, there are a few more options you can use to work with ls to make it superb!

Hidden Files

ls -la

The a option makes a list of files include files that are hidden. Files like .htaccess, .rvmrc and .gitignore, which are normally hidden, be seen.

total 80
drwxr-xr-x  23 teejay  staff   782 Jul  9 14:16 .
drwxr-xr-x  54 teejay  staff  1836 Jul  4 15:38 ..
drwxr-xr-x  17 teejay  staff   578 Jul  9 18:13 .git
-rw-r--r--   1 teejay  staff   541 Jul  9 14:16 .gitignore
drwxr-xr-x  12 teejay  staff   408 May 29 09:14 .idea
-rw-r--r--   1 teejay  staff    29 Apr 25 09:53 .rvmrc
-rw-r--r--   1 teejay  staff   352 Jul  9 14:16 Gemfile
-rw-r--r--   1 teejay  staff  2759 Jul  9 14:16 Gemfile.lock
-rw-r--r--   1 teejay  staff    33 Apr 25 01:21 README.md
-rw-r--r--   1 teejay  staff  9220 Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff   281 Apr 25 01:21 Rakefile
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 app
drwxr-xr-x  10 teejay  staff   340 Apr 25 11:04 config
-rw-r--r--   1 teejay  staff   166 Apr 25 01:21 config.ru
drwxr-xr-x   5 teejay  staff   170 Jul  9 14:16 db
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 doc
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 lib
drwxr-xr-x   4 teejay  staff   136 Apr 25 11:03 log
drwxr-xr-x   7 teejay  staff   238 Apr 25 01:21 public
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 script
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 test
drwxr-xr-x   6 teejay  staff   204 Apr 25 11:03 tmp
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 vendor

Human readable format

ls -h

The -h option makes a small formatting change to the filesize of files

total 64
-rw-r--r--   1 teejay  staff   352B Jul  9 14:16 Gemfile
-rw-r--r--   1 teejay  staff   2.7K Jul  9 14:16 Gemfile.lock
-rw-r--r--   1 teejay  staff    33B Apr 25 01:21 README.md
-rw-r--r--   1 teejay  staff   9.0K Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff   281B Apr 25 01:21 Rakefile
drwxr-xr-x   8 teejay  staff   272B Apr 25 01:21 app
drwxr-xr-x  10 teejay  staff   340B Apr 25 11:04 config
-rw-r--r--   1 teejay  staff   166B Apr 25 01:21 config.ru
drwxr-xr-x   5 teejay  staff   170B Jul  9 14:16 db
drwxr-xr-x   3 teejay  staff   102B Apr 25 01:21 doc
drwxr-xr-x   4 teejay  staff   136B Apr 25 01:21 lib
drwxr-xr-x   4 teejay  staff   136B Apr 25 11:03 log
drwxr-xr-x   7 teejay  staff   238B Apr 25 01:21 public
drwxr-xr-x   3 teejay  staff   102B Apr 25 01:21 script
drwxr-xr-x   8 teejay  staff   272B Apr 25 01:21 test
drwxr-xr-x   6 teejay  staff   204B Apr 25 11:03 tmp
drwxr-xr-x   4 teejay  staff   136B Apr 25 01:21 vendor

Order by Date Modified

The -t is useful if you want to see the last modified files first.

ls -lt
total 64
-rw-r--r--   1 teejay  staff   352 Jul  9 14:16 Gemfile
-rw-r--r--   1 teejay  staff  2759 Jul  9 14:16 Gemfile.lock
drwxr-xr-x   5 teejay  staff   170 Jul  9 14:16 db
drwxr-xr-x  10 teejay  staff   340 Apr 25 11:04 config
drwxr-xr-x   4 teejay  staff   136 Apr 25 11:03 log
drwxr-xr-x   6 teejay  staff   204 Apr 25 11:03 tmp
-rw-r--r--   1 teejay  staff    33 Apr 25 01:21 README.md
-rw-r--r--   1 teejay  staff  9220 Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff   281 Apr 25 01:21 Rakefile
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 app
-rw-r--r--   1 teejay  staff   166 Apr 25 01:21 config.ru
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 doc
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 lib
drwxr-xr-x   7 teejay  staff   238 Apr 25 01:21 public
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 script
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 test
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 vendor

Order by Date Modifed(Reverse)

-t accompanied by -r reverses the order by making the last modified file last.

ls -lt
total 64
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 vendor
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 test
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 script
drwxr-xr-x   7 teejay  staff   238 Apr 25 01:21 public
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 lib
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 doc
-rw-r--r--   1 teejay  staff   166 Apr 25 01:21 config.ru
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 app
-rw-r--r--   1 teejay  staff   281 Apr 25 01:21 Rakefile
-rw-r--r--   1 teejay  staff  9220 Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff    33 Apr 25 01:21 README.md
drwxr-xr-x   6 teejay  staff   204 Apr 25 11:03 tmp
drwxr-xr-x   4 teejay  staff   136 Apr 25 11:03 log
drwxr-xr-x  10 teejay  staff   340 Apr 25 11:04 config
drwxr-xr-x   5 teejay  staff   170 Jul  9 14:16 db
-rw-r--r--   1 teejay  staff  2759 Jul  9 14:16 Gemfile.lock
-rw-r--r--   1 teejay  staff   352 Jul  9 14:16 Gemfile

List Files (No other information)

ls -1
Gemfile
Gemfile.lock
README.md
README.rdoc
Rakefile
app
config
config.ru
db
doc
lib
log
public
script
test
tmp
vendor

Comma separated list of files (No other information)

ls -lm
Capfile, Gemfile, Gemfile.lock, Guardfile, README.md, README.rdoc, Rakefile, app, config, config.ru, db, doc, lib, log, public, script, spec, test, tmp, 
vendor