Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons...
-
Upload
julie-mcbride -
Category
Documents
-
view
214 -
download
0
Transcript of Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons...
![Page 1: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/1.jpg)
Finding Things
Copyright © Software Carpentry 2010
This work is licensed under the Creative Commons Attribution License
See http://software-carpentry.org/license.html for more information.
The Unix Shell
![Page 2: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/2.jpg)
Finding Things Introduction
shell
![Page 3: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/3.jpg)
Finding Things Introduction
shell
![Page 4: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/4.jpg)
Finding Things Introduction
shell Let's Google
for that
![Page 5: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/5.jpg)
Finding Things Introduction
shellLet's grep
for that
![Page 6: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/6.jpg)
Finding Things Introduction
grep: global / regular expression / print
![Page 7: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/7.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
![Page 8: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/8.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
haiku.txt
![Page 9: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/9.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
haiku.txt
$ grep not haiku.txt
![Page 10: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/10.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
haiku.txt
$ grep not haiku.txt
Pattern
![Page 11: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/11.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
haiku.txt
$ grep not haiku.txt
Pattern
Every letter matches itself
![Page 12: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/12.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
haiku.txt
$ grep not haiku.txt
File(s)
![Page 13: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/13.jpg)
Finding Things Introduction
grep: global / regular expression / print
Finds and prints lines in files that match a pattern
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
haiku.txt
$ grep not haiku.txt
Is not the true Tao, until
"My Thesis" not found
Today it is not working
$
![Page 14: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/14.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep day haiku.txt
Yesterday it worked
Today it is not working
$
![Page 15: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/15.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep day haiku.txt
Yesterday it worked
Today it is not working
$ grep -w day haiku.txt
$
Match whole words
![Page 16: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/16.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep day haiku.txt
Yesterday it worked
Today it is not working
$ grep -w day haiku.txt
$ grep -n it haiku.txt
Prefix matches with
line numbers
![Page 17: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/17.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep day haiku.txt
Yesterday it worked
Today it is not working
$ grep -w day haiku.txt
$ grep -n it haiku.txt
5:With searching comes loss
9:Yesterday it worked
10:Today it is not working
$
![Page 18: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/18.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep day haiku.txt
Yesterday it worked
Today it is not working
$ grep -w day haiku.txt
$ grep -n it haiku.txt
5:With searching comes loss
9:Yesterday it worked
10:Today it is not working
$ grep -w -n it haiku.txt
Use multiple flags
to combine effects
![Page 19: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/19.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep day haiku.txt
Yesterday it worked
Today it is not working
$ grep -w day haiku.txt
$ grep -n it haiku.txt
5:With searching comes loss
9:Yesterday it worked
10:Today it is not working
$ grep -w -n it haiku.txt
9:Yesterday it worked
10:Today it is not working
$
![Page 20: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/20.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep -i -v the haiku.txt
You bring fresh toner.
With searching comes loss
Yesterday it worked
Today it is not working
Software is like that.
$
![Page 21: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/21.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep -i -v the haiku.txt
You bring fresh toner.
With searching comes loss
Yesterday it worked
Today it is not working
Software is like that.
$-i case insensitive
![Page 22: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/22.jpg)
Finding Things Introduction
The Tao that is seenIs not the true Tao, untilYou bring fresh toner.
With searching comes lossand the presence of absence:"My Thesis" not found.
Yesterday it workedToday it is not workingSoftware is like that.
$ grep -i -v the haiku.txt
You bring fresh toner.
With searching comes loss
Yesterday it worked
Today it is not working
Software is like that.
$-i case insensitive
-v invert and print
non-matches
![Page 23: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/23.jpg)
Finding Things Introduction
Many more options
![Page 24: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/24.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
![Page 25: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/25.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
manual
![Page 26: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/26.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
Complex patterns use regular expressions
![Page 27: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/27.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
Complex patterns use regular expressions
(The 're' in grep)
![Page 28: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/28.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
Complex patterns use regular expressions
(The 're' in grep)
Ideas are covered in a separate lecture
![Page 29: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/29.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
Complex patterns use regular expressions
(The 're' in grep)
Ideas are covered in a separate lecture
grep's regular expressions are slightly different
from those provided in most programming languages
![Page 30: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/30.jpg)
Finding Things Introduction
Many more options
Use man grep to get help
Complex patterns use regular expressions
(The 're' in grep)
Ideas are covered in a separate lecture
grep's regular expressions are slightly different
from those provided in most programming languages
But the ideas are the same
![Page 31: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/31.jpg)
Finding Things Introduction
find: finds files (rather than lines in files)
![Page 32: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/32.jpg)
Finding Things Introduction
find: finds files (rather than lines in files)
Again, too many options to cover here
![Page 33: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/33.jpg)
Finding Things Introduction
find: finds files (rather than lines in files)
Again, too many options to cover here
vlad
data toolsthesis notes.txt
first.txt second.txt format stats old
![Page 34: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/34.jpg)
Finding Things Introduction
find: finds files (rather than lines in files)
Again, too many options to cover here
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
Output of tree
![Page 35: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/35.jpg)
Finding Things Introduction
find: finds files (rather than lines in files)
Again, too many options to cover here
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
Output of tree
Trailing / shows directories
![Page 36: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/36.jpg)
Finding Things Introduction
find: finds files (rather than lines in files)
Again, too many options to cover here
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
Output of tree
Trailing / shows directories
Trailing * shows executables
![Page 37: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/37.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -type d
![Page 38: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/38.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -type d
Root directory of search
![Page 39: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/39.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -type d
Things of type 'd'
(directory)
![Page 40: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/40.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -type d
./
./data
./thesis
./tools
./tools/old
$
![Page 41: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/41.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -type d
./
./data
./thesis
./tools
./tools/old
$ find . -type f
./data/first.txt
./data/second.txt
./notes.txt
./tools/format
./tools/stats
$
![Page 42: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/42.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -maxdepth 1 -type f
./notes.txt
$
![Page 43: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/43.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -maxdepth 1 -type f
./notes.txt
$ find . -mindepth 2 -type f
./data/first.txt
./data/second.txt
./tools/format
./tools/stats
$
![Page 44: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/44.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -maxdepth 1 -type f
./notes.txt
$ find . -mindepth 2 -type f
./data/first.txt
./data/second.txt
./tools/format
./tools/stats
$ find . -empty
./thesis
./tools/old
$
![Page 45: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/45.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -perm -u=x
./data
./thesis
./tools
./tools/format
./tools/old
./tools/stats
$
![Page 46: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/46.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -perm -u=x
./data
./thesis
./tools
./tools/format
./tools/old
./tools/stats
$ find . -perm -u=x -type f
./tools/format
./tools/stats
$
![Page 47: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/47.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -name *.txt
./notes.txt
$
![Page 48: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/48.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -name *.txt
./notes.txt
$* expanded by shell
before command runs
![Page 49: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/49.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -name notes.txt
./notes.txt
$* expanded by shell
before command runs
This is the actual
command
![Page 50: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/50.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -name *.txt
./notes.txt
$ find . -name '*.txt'
Single quotes prevent
shell from expanding
wildcards
![Page 51: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/51.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -name *.txt
./notes.txt
$ find . -name '*.txt'
Single quotes prevent
shell from expanding
wildcards
So find gets the pattern
![Page 52: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/52.jpg)
Finding Things Introduction
./
+-- data/
| +-- first.txt
| +-- second.txt
+-- notes.txt
+-- thesis/
+-- tools/
+-- format*
+-- old/
+-- stats*
$ find . -name *.txt
./notes.txt
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$
![Page 53: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/53.jpg)
Finding Things Introduction
The command line's power lies in combining tools
![Page 54: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/54.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$
![Page 55: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/55.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
![Page 56: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/56.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
Back quotes
![Page 57: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/57.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
Back quotes
Replace what's inside with output from
running that command
![Page 58: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/58.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
Back quotes
Replace what's inside with output from
running that command
Like wildcards * and ?, but more flexible
![Page 59: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/59.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
./data/first.txt ./data/second.txt ./notes.txt
![Page 60: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/60.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
$ wc -l ./data/first.txt ./data/second.txt ./notes.txt
![Page 61: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/61.jpg)
Finding Things Introduction
The command line's power lies in combining tools
$ find . -name '*.txt'
./data/first.txt
./data/second.txt
./notes.txt
$ wc -l `find . -name '*.txt'`
70 ./data/first.txt
420 ./data/second.txt
30 ./notes.txt
520 total
$
![Page 62: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/62.jpg)
Finding Things Introduction
Use find and grep together
![Page 63: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/63.jpg)
Finding Things Introduction
Use find and grep together
$ grep FE `find . -name '*.pdb'`
./human/heme.pdb:ATOM 25 FE 1 -0.924 0.535 -0.518
$
![Page 64: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/64.jpg)
Finding Things Introduction
What if your data isn't text?
![Page 65: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/65.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
![Page 66: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/66.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
![Page 67: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/67.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
Hasn't happened, and probably won't
![Page 68: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/68.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
Hasn't happened, and probably won't
2. Convert data to text (or extract text from data)
![Page 69: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/69.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
Hasn't happened, and probably won't
2. Convert data to text (or extract text from data)
Simple things are easy
![Page 70: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/70.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
Hasn't happened, and probably won't
2. Convert data to text (or extract text from data)
Simple things are easy
Complex things are impossible
![Page 71: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/71.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
Hasn't happened, and probably won't
2. Convert data to text (or extract text from data)
Simple things are easy
Complex things are impossible
3. Use a programming language
![Page 72: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/72.jpg)
Finding Things Introduction
What if your data isn't text?
Images, databases, spreadsheets…
1. Teach standard tools about all these formats
Hasn't happened, and probably won't
2. Convert data to text (or extract text from data)
Simple things are easy
Complex things are impossible
3. Use a programming language
Many have borrowed ideas from the shell
![Page 73: Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .](https://reader036.fdocuments.us/reader036/viewer/2022062519/5697c0251a28abf838cd4f2b/html5/thumbnails/73.jpg)
August 2010
created by
Greg Wilson
Copyright © Software Carpentry 2010
This work is licensed under the Creative Commons Attribution License
See http://software-carpentry.org/license.html for more information.