CEST-CE Term_2 GNU/LINUX (Week 3)

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the main purpose of the fgrep command?

  • To generate a list of all pathnames
  • To find files by name
  • To find pathnames by anything other than name
  • To search for patterns or text inside files (correct)

What is the difference between fgrep and find commands?

  • Fgrep is used for recursive search, while find is used for a single directory
  • Fgrep is faster than find for searching files
  • Fgrep searches for text inside files, while find searches for file names (correct)
  • Fgrep finds files by name, while find searches for text inside files

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

  • It finds the names of files by anything other than name
  • It searches for file names in all subdirectories
  • It generates a list of all pathnames
  • It searches the contents of an entire directory tree of files (correct)

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

<p>find (B)</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 (C)</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 (A)</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 (C)</p> Signup and view all the answers

What is the general syntax of the find command?

<p>find [options...] [startdir...] [expression] (A)</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 (C)</p> Signup and view all the answers

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

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

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

<p>Shows only files (A)</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 (D)</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 (B)</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 (A)</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 (A)</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 (D)</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 (A)</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 (A)</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. (C)</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. (B)</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. (C)</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. (B)</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. (C)</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. (D)</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. (C)</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. (B)</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). (D)</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. (A)</p> Signup and view all the answers

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

<p>1618 (D)</p> Signup and view all the answers

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

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

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

<p>Fgrep is safer than grep (D)</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 (C)</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 (B)</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 (B)</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 (D)</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 (C)</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 (A)</p> Signup and view all the answers

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

<p>&gt; (C)</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 (C)</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 (B)</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 (D)</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) (B)</p> Signup and view all the answers

What is the purpose of using ' in input redirection?

<p>To redirect input from a file (D)</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 (A)</p> Signup and view all the answers

Flashcards are hidden until you start studying

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.

Studying That Suits You

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

Quiz Team

Related Documents

Week 3 (not filtered).docx

More Like This

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

Linux File System Commands

RewardingCerium9132 avatar
RewardingCerium9132
Linux Directory and File Commands Lab
10 questions
Use Quizgecko on...
Browser
Browser