Podcast
Questions and Answers
What is the main purpose of the fgrep command?
What is the main purpose of the fgrep command?
What is the difference between fgrep and find commands?
What is the difference between fgrep and find commands?
What happens when you turn on the fgrep 'recursive' option?
What happens when you turn on the fgrep 'recursive' option?
What command can be used to find pathnames by anything other than name?
What command can be used to find pathnames by anything other than name?
Signup and view all the answers
What is the default directory used by the find command if no start directory is specified?
What is the default directory used by the find command if no start directory is specified?
Signup and view all the answers
What is the purpose of the [startdir...] in the find command?
What is the purpose of the [startdir...] in the find command?
Signup and view all the answers
What is the command to use when the pathname has existed for some time and is saved in the right database?
What is the command to use when the pathname has existed for some time and is saved in the right database?
Signup and view all the answers
What is the general syntax of the find command?
What is the general syntax of the find command?
Signup and view all the answers
What is the purpose of using the -ls expression in the find command?
What is the purpose of using the -ls expression in the find command?
Signup and view all the answers
What is the default action of the find command if no action is specified?
What is the default action of the find command if no action is specified?
Signup and view all the answers
What does the -type f expression do in the find command?
What does the -type f expression do in the find command?
Signup and view all the answers
What is the purpose of using the -maxdepth option in the find command?
What is the purpose of using the -maxdepth option in the find command?
Signup and view all the answers
What does the -user option do in the find command?
What does the -user option do in the find command?
Signup and view all the answers
What is the purpose of using the -size option in the find command?
What is the purpose of using the -size option in the find command?
Signup and view all the answers
What is the purpose of piping the output of find to fgrep?
What is the purpose of piping the output of find to fgrep?
Signup and view all the answers
What is the purpose of using the ! symbol in the find command?
What is the purpose of using the ! symbol in the find command?
Signup and view all the answers
What is the purpose of using quotations around a pattern in the find command?
What is the purpose of using quotations around a pattern in the find command?
Signup and view all the answers
What is the purpose of using the -perm option in the find command?
What is the purpose of using the -perm option in the find command?
Signup and view all the answers
What is the default behavior of the find command if no expression is specified?
What is the default behavior of the find command if no expression is specified?
Signup and view all the answers
What is the purpose of the -name expression in the find command?
What is the purpose of the -name expression in the find command?
Signup and view all the answers
What does the -size +100M expression mean in the find command?
What does the -size +100M expression mean in the find command?
Signup and view all the answers
What is the effect of using a leading minus in the -size expression?
What is the effect of using a leading minus in the -size expression?
Signup and view all the answers
What does the -mtime +30 expression mean in the find command?
What does the -mtime +30 expression mean in the find command?
Signup and view all the answers
What is the purpose of the -user expression in the find command?
What is the purpose of the -user expression in the find command?
Signup and view all the answers
What is the effect of using multiple expressions in the find command?
What is the effect of using multiple expressions in the find command?
Signup and view all the answers
What is the purpose of the -print expression in the find command?
What is the purpose of the -print expression in the find command?
Signup and view all the answers
What happens when you use the -size 0 expression in the find command?
What happens when you use the -size 0 expression in the find command?
Signup and view all the answers
What is the purpose of redirecting the error output to /dev/null in the find command?
What is the purpose of redirecting the error output to /dev/null in the find command?
Signup and view all the answers
What is the output of the command 'find /usr/bin | wc -l'?
What is the output of the command 'find /usr/bin | wc -l'?
Signup and view all the answers
What does the command 'find /usr/bin | fgrep 'sh'' do?
What does the command 'find /usr/bin | fgrep 'sh'' do?
Signup and view all the answers
What is the difference between 'fgrep' and 'grep'?
What is the difference between 'fgrep' and 'grep'?
Signup and view all the answers
What is the output of the command 'find /usr/bin | grep 'sh$''?
What is the output of the command 'find /usr/bin | grep 'sh$''?
Signup and view all the answers
Why should you not run 'find /' on a shared computer?
Why should you not run 'find /' on a shared computer?
Signup and view all the answers
What is the purpose of the 'locate' or 'slocate' commands?
What is the purpose of the 'locate' or 'slocate' commands?
Signup and view all the answers
Why are the 'locate' or 'slocate' commands much faster than 'find'?
Why are the 'locate' or 'slocate' commands much faster than 'find'?
Signup and view all the answers
When is 'find' the only command that can find a pathname?
When is 'find' the only command that can find a pathname?
Signup and view all the answers
What is the primary function of shell redirection?
What is the primary function of shell redirection?
Signup and view all the answers
What symbol is used to redirect standard output to a file?
What symbol is used to redirect standard output to a file?
Signup and view all the answers
What is the effect of using >> instead of > in output redirection?
What is the effect of using >> instead of > in output redirection?
Signup and view all the answers
What happens when you redirect both stdout and stderr to the same file?
What happens when you redirect both stdout and stderr to the same file?
Signup and view all the answers
What is the purpose of using 2>&1 in output redirection?
What is the purpose of using 2>&1 in output redirection?
Signup and view all the answers
What is the default behavior of commands when no file names are given?
What is the default behavior of commands when no file names are given?
Signup and view all the answers
What is the purpose of using ' in input redirection?
What is the purpose of using ' in input redirection?
Signup and view all the answers
What is the rule for output redirection when a space is used before the > symbol?
What is the rule for output redirection when a space is used before the > symbol?
Signup and view all the answers
Study Notes
Searching for Files
- To search for files, use the
find
command, which finds files by name, unlikefgrep
, which looks for text inside files. -
find
can search for files by name, size, owner, modification date, and more.
Five Common Ways to Use the find
Command
-
find [startdir…] -print
: finds all pathnames under the specified directory. -
find [startdir…] -name ‘basename’ -print
: finds pathnames with a specific basename. -
find [startdir…] -user ‘userid’ -print
: finds pathnames owned by a specific user. -
find [startdir…] -mtime -30 -print
: finds pathnames modified within the last 30 days. -
find [startdir…] -size +100M -print
: finds pathnames with a size greater than 100MB.
Using Multiple Expressions with find
- You can use multiple expressions with
find
to narrow down the search results. - The pathnames found must meet all the conditions of the expressions used.
Showing Detailed Output with -ls
- The
-ls
expression withfind
displays detailed attribute information about the pathnames. - This is similar to using
ls -dils
on the displayed names.
Examples of Using find
-
find /usr/bin -name '*sh'
: finds pathnames under/usr/bin
ending withsh
. -
find /usr/bin -type f -size +2M
: finds pathnames under/usr/bin
with a size greater than 2MB. -
find /tmp -maxdepth 1 -user student -type d
: finds directories under/tmp
owned by thestudent
user.
Using fgrep
on the Output of find
- You can pipe the output of
find
tofgrep
to search for specific patterns in the pathname output. -
find /usr/bin | fgrep 'sh'
: finds pathnames under/usr/bin
containing the stringsh
.
Finding Files Using locate
or slocate
- The
locate
orslocate
commands search a saved database of pathnames for quick lookup. - These commands are faster than
find
for searching for files that have been indexed in the database.
Introduction to Redirection
- Shell redirection allows changing where commands read input and send output, applying to all commands run by the shell.
Redirection of Input and Output
- Input and output can be redirected to or from a file using '' or to or from a program using '|'.
- Redirection allows changing input/output streams of commands.
Output Redirection
- Commands produce standard output and standard error, which can be redirected separately.
- Standard output can be redirected to a file or another command using '>'.
- Standard error is output in case of an error and can be redirected using '2>'.
- '2>' redirects standard error to a file.
Output Redirection Syntax with >
- '>' symbol indicates output redirection to a file, truncating it if it exists.
- Space before '>' is required, and the space after is optional.
- Output redirection is done before running the command.
Rules for Output Redirection
- Redirection only affects visible output.
- Redirection goes to one place.
- By default, only standard output is redirected.
Appending to Files using >>
- '>>' appends output to a file instead of truncating it.
- Used to append output to a file without overwriting existing content.
Additional Notes on Redirection
- Avoid redirecting both stdout and stderr to the same file to prevent overwriting.
- '2>&1' redirects both stdout and stderr safely into a single file.
Input Redirection
- Commands read input from files or standard input (stdin) if no file names are given.
- Redirection using '<' symbol allows reading input from a file.
- Input redirection allows changing input streams of commands.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Learn about the find command in Linux, its uses and options. Understand how to search for files by name, size, owner, and modification date.