44 Questions
5 Views
3.5 Stars

CEST-CE Term_2 GNU/LINUX (Week 3)

Learn about the find command in Linux, its uses and options. Understand how to search for files by name, size, owner, and modification date.

Created by
@LuxuryAbundance
1/44
Find out if you were right!
Create an account to continue playing and access all the benefits such as generating your own quizzes, flashcards and much more!
Quiz Team

Access to a Library of 520,000+ Quizzes & Flashcards

Explore diverse subjects like math, history, science, literature and more in our expanding catalog.

Questions and Answers

What is the main purpose of the fgrep command?

To search for patterns or text inside files

What is the difference between fgrep and find commands?

Fgrep searches for text inside files, while find searches for file names

What happens when you turn on the fgrep 'recursive' option?

It searches the contents of an entire directory tree of files

What command can be used to find pathnames by anything other than name?

<p>find</p> Signup and view all the answers

What is the default directory used by the find command if no start directory is specified?

<p>Current directory</p> Signup and view all the answers

What is the purpose of the [startdir...] in the find command?

<p>To specify the directory to start the search from</p> 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?

<p>locate</p> Signup and view all the answers

What is the general syntax of the find command?

<p>find [options...] [startdir...] [expression]</p> Signup and view all the answers

What is the purpose of using the -ls expression in the find command?

<p>To display detailed attribute information about the pathnames</p> Signup and view all the answers

What is the default action of the find command if no action is specified?

<p>Print pathnames</p> Signup and view all the answers

What does the -type f expression do in the find command?

<p>Shows only files</p> Signup and view all the answers

What is the purpose of using the -maxdepth option in the find command?

<p>To limit the search to a specified depth</p> Signup and view all the answers

What does the -user option do in the find command?

<p>Searches for files owned by a specific user</p> Signup and view all the answers

What is the purpose of using the -size option in the find command?

<p>To search for files with a specific size</p> Signup and view all the answers

What is the purpose of piping the output of find to fgrep?

<p>To use regular expression pattern matching</p> Signup and view all the answers

What is the purpose of using the ! symbol in the find command?

<p>To negate the condition that follows</p> Signup and view all the answers

What is the purpose of using quotations around a pattern in the find command?

<p>To protect the pattern from shell expansion</p> Signup and view all the answers

What is the purpose of using the -perm option in the find command?

<p>To search for files with a specific permission</p> Signup and view all the answers

What is the default behavior of the find command if no expression is specified?

<p>It finds all pathnames in the specified starting directories.</p> Signup and view all the answers

What is the purpose of the -name expression in the find command?

<p>To specify a pattern for the basename of the pathnames.</p> Signup and view all the answers

What does the -size +100M expression mean in the find command?

<p>Find pathnames with a size greater than 100M.</p> Signup and view all the answers

What is the effect of using a leading minus in the -size expression?

<p>It means to find pathnames with a size less than or equal to the specified size.</p> Signup and view all the answers

What does the -mtime +30 expression mean in the find command?

<p>Find pathnames modified more than 30 days ago.</p> Signup and view all the answers

What is the purpose of the -user expression in the find command?

<p>To specify the userid of the owner of the pathnames.</p> Signup and view all the answers

What is the effect of using multiple expressions in the find command?

<p>The pathnames found must meet all of the conditions of the expressions used.</p> Signup and view all the answers

What is the purpose of the -print expression in the find command?

<p>To print the pathnames that match the expressions.</p> Signup and view all the answers

What happens when you use the -size 0 expression in the find command?

<p>It finds pathnames that are empty (zero size).</p> Signup and view all the answers

What is the purpose of redirecting the error output to /dev/null in the find command?

<p>To suppress permission errors.</p> Signup and view all the answers

What is the output of the command 'find /usr/bin | wc -l'?

<p>1618</p> Signup and view all the answers

What does the command 'find /usr/bin | fgrep 'sh'' do?

<p>List only pathnames containing 'sh'</p> Signup and view all the answers

What is the difference between 'fgrep' and 'grep'?

<p>Fgrep is safer than grep</p> Signup and view all the answers

What is the output of the command 'find /usr/bin | grep 'sh$''?

<p>/usr/bin/bash /usr/bin/nettle-hash /usr/bin/sh /usr/bin/lesspipe.sh /usr/bin/xrefresh</p> Signup and view all the answers

Why should you not run 'find /' on a shared computer?

<p>It generates many error messages about permissions</p> Signup and view all the answers

What is the purpose of the 'locate' or 'slocate' commands?

<p>To quickly search a saved database of pathnames</p> Signup and view all the answers

Why are the 'locate' or 'slocate' commands much faster than 'find'?

<p>They search a saved database of pathnames</p> Signup and view all the answers

When is 'find' the only command that can find a pathname?

<p>When the pathname is new and not in the locate database</p> Signup and view all the answers

What is the primary function of shell redirection?

<p>To change where commands read input and send output</p> Signup and view all the answers

What symbol is used to redirect standard output to a file?

<p>&gt;</p> Signup and view all the answers

What is the effect of using >> instead of > in output redirection?

<p>It appends output to a file instead of truncating it</p> Signup and view all the answers

What happens when you redirect both stdout and stderr to the same file?

<p>The output may be overwritten or mixed up</p> Signup and view all the answers

What is the purpose of using 2>&1 in output redirection?

<p>To redirect both stdout and stderr safely into a single file</p> Signup and view all the answers

What is the default behavior of commands when no file names are given?

<p>They read input from standard input (stdin)</p> Signup and view all the answers

What is the purpose of using ' in input redirection?

<p>To redirect input from a file</p> Signup and view all the answers

What is the rule for output redirection when a space is used before the > symbol?

<p>The space is required</p> Signup and view all the answers

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Study Notes

Searching for Files

  • To search for files, use the find command, which finds files by name, unlike fgrep, 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 with find 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 with sh.
  • 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 the student user.

Using fgrep on the Output of find

  • You can pipe the output of find to fgrep to search for specific patterns in the pathname output.
  • find /usr/bin | fgrep 'sh': finds pathnames under /usr/bin containing the string sh.

Finding Files Using locate or slocate

  • The locate or slocate 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.

Trusted by students at

More Quizzes Like This

Linux Directory and File Commands Quiz
10 questions
Linux File System Commands
7 questions

Linux File System Commands

RewardingCerium9132 avatar
RewardingCerium9132
Use Quizgecko on...
Browser
Browser