Chapter 6
List Directory (ls)

6.1 Do This

Before you start, make sure you cd back to the directory above temp. If you have no idea where you are, use pwd to figure it out and then move there.


Source 9: Linux/Mac OSX Exercise 6
  $ cd temp
  $ ls
  stuff
  $ cd stuff
  $ ls
  things
  $ cd things
  $ ls
  frank
  $ cd frank
  $ ls
  joe
  $ cd joe
  $ ls
  alex
  $ cd alex
  $ ls
  $ cd john
  $ ls
  $ cd ..
  $ ls
  john
  $ cd ../../../
  $ ls
  frank
  $ cd ../../
  $ ls
  stuff
  $


Source 10: Windows Exercise 6
  > cd temp
  > ls
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            stuff
  
  
  > cd stuff
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            things
  
  
  > cd things
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff\things
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            frank
  
  
  > cd frank
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff\things\frank
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            joe
  
  
  > cd joe
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff\things\frank\joe
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            alex
  
  
  > cd alex
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff\things\frank\joe\alex
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            john
  
  
  > cd john
  > ls
  > cd ..
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff\things\frank\joe\alex
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            john
  
  
  > cd ..
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff\things\frank\joe
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            alex
  
  
  > cd ../../..
  > ls
  
  
      Directory: C:\Users\zed\temp\stuff
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            things
  
  
  > cd ..
  > ls
  
  
      Directory: C:\Users\zed\temp
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        12/17/2011   9:03 AM            stuff
  
  
  >

6.2 You Learned This

The ls command lists out the contents of the directory you are currently in. You can see me use cd to change into different directories and then list what's in them so I know which directory to go to next.

There are a lot of options for the ls command, but you'll learn how to get help on those later when we cover the help command.

6.3 Do More

  1. Type every one of these commands in! You have to actually type these to learn them. Just reading them is not good enough. I'll stop yelling now.
  2. On Unix, try the ls -lR command while you're in temp.
  3. On Windows do the same thing with dir -R.
  4. Use cd to get to other directories on your computer then use ls to see what's in them.
  5. Update your notebook with new questions. I know you probably have some, because I'm not covering everything about this command.
  6. Remember that if you get lost, then use ls and pwd to figure out where you are, then go to where you need to be with cd.


Online Video Course + PDF For $9

For the price of most other course's PDFs only, you can get the full PDF for this class and 2 videos demonstrating the whole book for both Unix/OSX Terminal and Windows PowerShell. The course is self-paced so you can go through it any time you want, as many times as you want.


Signup Now At Udemy.com For $9