Chapter 17
Finding Files (find, DIR -R)

17.1 Do This

This exercise is going to combine three concepts into one single command. I'm going to show you how to find all your text files and page through them.


Source 31: Linux/Mac OSX Exercise 17
  $ cd temp
  $ find . -name "*.txt" -print
  $ cd ..
  $ find . -name "*.txt" -print | less
  $ cd ..
  $ find . -name "*.txt" -print | less
  $


Source 32: Windows Exercise 17
  > dir -r
  > cd ..
  > dir -r -filter "*.txt"
  > cd ..
  > dir -r | more
  >

17.2 You Learned This

You just learned how to run the find (dir -r on Windows) command to search for all files ending in .txt and then look at the results with less (more on Windows).

Here's a breakdown of exactly what this does for Unix:

  1. First I go to the temp directory.
  2. Then I just do a plain find from there since there's not many .txt files. How "find" works is you write in a kind of sentence: "Hey find, start here (.) then find files named "*.txt" and print them". Thinking about commands as if you're telling the computer to do something is a good way to remember it.
  3. Next I go up one directory and then I do the same command, but this time I pipe the output to less. This command could run for a while, so be patient.
  4. I then do this again, but this one could take a really long time, so feel free to just hit CTRL-c to abort it.

On Windows it's nearly the same:

  1. I just do a plain dir from wherever you are since there's not many .txt files. This command says "do a directory listing of this directory and all the others under it", and is called a "recursive" command.
  2. Next I go up one directory and then I do the same command, but this time I pipe the output to more. This command could run for a while, so be patient.
  3. I then do this again, but this one could take a really long time, so feel free to just hit CTRL-c to abort it.

17.3 Do More

  1. Unix: Get your find index card and add this to the description side: "find STARTDIR -name WILDCARD -print". Next time you drill make sure you can say that phrase so you remember how find is formatted.
  2. Windows: Do the same as above, but write "dir -r -filter"
  3. You can put any directory where the . (dot) is. Try another directory to start your search there.
  4. Look for all the video files on your computer starting at the home drive and use the > to save the list to a file. Remember how you can do SOMECOMMAND > SOMEFILE.txt and it will write the output of SOMECOMMAND to the file SOMEFILE.txt?


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