The Linux CLI for Beginners, or, Fear Not the Linux Command Line! - page 3
Please Meet the Linux Terminal
"grep" is kind of a nasty name -- there's some disagreement on what it stands for, including "Globally search for Regular Expressions and Print" and "General Regular Expression Parser". But it's an incredibly useful program that prints just the lines matching a particular pattern.
For instance, to combine the squirrel search and the tiger search, you just pipe one search through grep, passing grep the second pattern:
$ locate squirrel | grep tiger /home/akkana/Images/MiscImages/tiger-squirrel.jpg
locate squirrel found all those squirrel images, then
grep searched through all of them to find any that also had "tiger" in
the name. Now I know exactly where the file is.
Pipelines aren't limited to just two commands, though. For instance, remember that long list of files with cat in the name? I know there's a program called "cat"; suppose I want to know how many of those other files with "cat" in the name are programs.
Programs are usually located in /usr/bin, but sometimes they're in /bin or some other place. But they usually have "bin" in the name somewhere. So if I take all the files that have both "cat" and "bin" in the name:
$ locate cat | grep binI can then find out how many lines there were, by using the useful wc (word count) program:
$ locate cat | grep bin | wc -l
wc -l says to count the number of lines (that's ell for
"lines", not a one) -- if you omit the -l part, it prints lines,
words and characters.
On my system I have 34 programs with cat in the name. How many do you have?
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: CoreOS, Oracle Enterprise Linux 7 and Ubuntu 14.10
- 5Linux Top 3: Debian Gives Up on Upstart, Ubuntu and Linux Kernel Updates