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:
- First I go to the temp directory.
- 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.
- 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.
- 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:
- 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.
- 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.
- 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
- 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.
- Windows: Do the same as above, but write "dir -r -filter"
- You can put any directory where the . (dot) is. Try another directory to
start your search there.
- 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?