Four ways to find commands and find files in Linux | Linux Tutorial
for Beginners (4:52)
Code Examples and Video Script
Welcome. Today's question: How do you find commands in Linux?
I'm Paul, and I think the greatest challenge for those transitioning
from Mac and Windows, to Linux, is knowing what's available beyond
that intimidating command prompt.
Step 1 - Overview of 4 Linux Commands for Search
So in this tutorial, I'll demonstrate four ways to filter through the
900, or so, commands so you can zero in on what you want to do.
We'll practice commands at the Terminal.
apropos
locate
find
which
Then review commands used earlier, and a cheat sheet.
cal
cd
ls
whatis
nano
clear
exit
And because the command line is difficult to master and we intend to
go pretty far here, I will dedicate a few tutorials to finding help.
Here we will focus on finding commands, and in the next tutorial we'll
cover finding help on how to use those commands.
Step 2 - Practice With the apropos and locate Commands
Okay, so I've logged in to a local Linux server in my office, on this
rainy day in California.
paul@fullstack:~$ cal
February 2017
Su Mo Tu We Th Fr Sa
1 2 *3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28
Let's start with pwd to see where we
sit in the directory structure, change directories to
notes for later and
ls to see what's in here.
paul@fullstack:~$ pwd
/home/paul
paul@fullstack:~$ cd notes
paul@fullstack:~/notes$ ls
video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt
video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt
paul@fullstack:~/notes$ clear
The Linux apropos command to search names and descriptions
Okay, Linux is obediently waiting for us now, so let's start with a
beginner-level command, apropos, to
see what's available once we have a topic in mind.
paul@fullstack:~/notes$ whatis apropos
apropos (1) - search the manual page names and descriptions
Let's say we want to do something with 'search'. So the term
search is an argument.
paul@fullstack:~/notes$ apropos search
apropos (1) - search the manual page names and descriptions
badblocks (8) - search a device for bad blocks
bzegrep (1) - search possibly bzip2 compressed files for a regular expression
bzfgrep (1) - search possibly bzip2 compressed files for a regular expression
bzgrep (1) - search possibly bzip2 compressed files for a regular expression
Class::ISA (3pm) - report the search path for a class's ISA tree
exigrep (8) - Search Exim's main log
exiqgrep (8) - Search in the exim queue
find (1) - search for files in a directory hierarchy
lzegrep (1) - search compressed files for a regular expression
lzfgrep (1) - search compressed files for a regular expression
lzgrep (1) - search compressed files for a regular expression
manpath (1) - determine search path for manual pages
oldfind (1) - search for files in a directory hierarchy
xzegrep (1) - search compressed files for a regular expression
xzfgrep (1) - search compressed files for a regular expression
xzgrep (1) - search compressed files for a regular expression
zegrep (1) - search possibly compressed files for a regular expression
zfgrep (1) - search possibly compressed files for a regular expression
zgrep (1) - search possibly compressed files for a regular expression
paul@fullstack:~/notes$ clear
It returns roughly 20 commands that include the term 'search' in the
description, or command name.
Let's try ssh, which is the secure
protocol I'm using currently to communicate to this server.
paul@fullstack:~/notes$ apropos ssh
authorized_keys (5) - OpenSSH SSH daemon
rlogin (1) - OpenSSH SSH client (remote login program)
rsh (1) - OpenSSH SSH client (remote login program)
slogin (1) - OpenSSH SSH client (remote login program)
ssh (1) - OpenSSH SSH client (remote login program)
ssh-add (1) - adds private key identities to the authentication agent
ssh-agent (1) - authentication agent
ssh-argv0 (1) - replaces the old ssh command-name as hostname handling
ssh-copy-id (1) - use locally available keys to authorise logins on a remote machine
ssh-keygen (1) - authentication key generation, management and conversion
ssh-keyscan (1) - gather ssh public keys
ssh-keysign (8) - ssh helper program for host-based authentication
ssh-pkcs11-helper (8) - ssh-agent helper program for PKCS#11 support
ssh_config (5) - OpenSSH SSH client configuration files
sshd (8) - OpenSSH SSH daemon
sshd_config (5) - OpenSSH SSH daemon configuration file
paul@fullstack:~/notes$ clear
And last let's try apropos find.
paul@fullstack:~/notes$ apropos ssh
Devel::InnerPackage (3pm) - find all the inner packages of a package
exinext (8) - Finding individual retry times
exiwhat (8) - Finding out what Exim processes are doing
find (1) - search for files in a directory hierarchy
find2perl (1) - translate find command lines to Perl code
findaffix (1) - Interactive spelling checking
findfs (8) - find a filesystem by label or UUID
findmnt (8) - find a filesystem
locate (1) - find files by name
mlocate (1) - find files by name
oldfind (1) - search for files in a directory hierarchy
pidof (8) - find the process ID of a running program.
systemd-delta (1) - Find overridden configuration files
xdg-user-dir (1) - Find an XDG user dir
paul@fullstack:~/notes$ clear
Good, now, let's focus on the command near the middle, called
locate.
The Linux locate command to find files
The locate command is a more of an
intermediate-level command that searches a database of path names
and returns a hit any time the argument shows up. So it can find
more than just commands, but files and directories too. We can use
locate to find commands using a trick,
because in Linux, commands are normally located in a directory called
bin.
paul@fullstack:~/notes$ whatis locate
locate (1) - find files by name
Step 3 - Learn Faster with Reference Materials
Let me clarify with a
Cheat Sheet I mentioned. I
put this together for this purpose, as it has short definitions for
100 commands, plus
links to videos and
web pages in our Linux Essentials Playlist on YouTube. And here are
commands in the Help section.
You will also find links to quizzes, wildcards, and what I wanted you
to see is a common directory structure for most Linux distributions.
Wherever you see bin, is where program binaries are stored. So here
is /bin, another called
/sbin and another pair of
/usr/bin and
/usr/sbin directories in the
/usr directory.
Two more points about locate. First,
for it to work a database must be created. For example, when I tried
locate on the same day as my
installation, it failed.
Second, security. Some administrators remove
locate on public-facing servers.
Step 4 - See the find Command in Action and Introduce which
The Linux find command to search for any type of file
Let's move on to the advanced command called
find, that allows you to search for
programs, or any type of file in a directory hierarchy. And rather than
searching a saved database, it proceeds through the directories below
where you point. The find command also
gives you the capability to use regular expressions, like wildcards
mentioned earlier, allowing for custom searches.
paul@fullstack:~/notes$ whatis find
find (1) - search for files in a directory hierarchy
paul@fullstack:~/notes$ ls
video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt
video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt
paul@fullstack:~/notes$ find /home -name 'video001*'
/home/paul/notes/video0012.txt
/home/paul/notes/video0011.txt
Let's try two, searching through recent
/notes. Here's the syntax, it goes
find, location
/home, category is
-name, and the expression is
video001* using the *
wildcard.
Second, we could do this, to find files larger than 500 bytes.
The which command to find which program Linux will run
Okay next is which. Let's do an
apropos editor, as
in text editor, and there are 15 on my distribution, and
nano is the one I suggest for
beginners.
paul@fullstack:~/notes$ apropos editor
editor (1) - Nano's ANOther editor, an enhanced free Pico clone
ex (1) - Vi IMproved, a programmers text editor
nano (1) - Nano's ANOther editor, an enhanced free Pico clone
pico (1) - Nano's ANOther editor, an enhanced free Pico clone
psed (1) - a stream editor
rnano (1) - Restricted mode for Nano's ANOther editor, an enhanced free Pico clone
rview (1) - Vi IMproved, a programmers text editor
rvim (1) - Vi IMproved, a programmers text editor
s2p (1) - a stream editor
sed (1) - stream editor for filtering and transforming text
select-editor (1) - select your default sensible-editor from all installed editors
sensible-editor (1) - sensible editing, paging, and web browsing
vi (1) - Vi IMproved, a programmers text editor
view (1) - Vi IMproved, a programmers text editor
vim (1) - Vi IMproved, a programmers text editor
paul@fullstack:~/notes$ whatis which
which (1) - locate a command
paul@fullstack:~/notes$ which nano
/usr/bin/nano
paul@fullstack:~/notes$ locate nano
/bin/nano
/usr/bin/nano
The reason I bring it up is because
which tells you which program Linux
runs. Wait, remember earlier we saw two
nano programs? I'm out of time here,
but will answer this question in the next tutorial.
Step 5 - Next up: Finding options and arguments for commands
So here's a picture of our stack and where we're headed, one step at
a time.
Client : HTML, CSS, JavaScript
Software : Python Scientific Stack
Data : PostgreSQL, MySQL
OS : Linux (command line), Debian
Next, we'll explore how to find help on using commands.
Have a nice day.
What's Next?
Explore our YouTube channel for other opportunities for free learning.
Subscribe at YouTube, follow @factorpad and join our no-spam email list
for updates.
To access all tutorials, click Outline.
To see how to navigate Linux, click Back.
Roses are red, violets are blue, yada yada yada, click Tip.
To learn how to find help on commands, click Next.