Locating and searching file locations

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

find command

  • Type find and specify where the search will be conducted

  • ex. find /home -name “files.txt” , this will look for the file in the /home and all subdirectories of /home

  • use -name to specify the file

  • An output would look like this /home/rtracy/files.txt

2
New cards

The locate command

  • Need to install locate on the system

  • Then create an index of all files in the file system, index is called locatedb and stored in the /bar/log directory

  • Update happens by default daily, when file system changes, an update will be made to the index

3
New cards

the locate command

  • Run locate command and specify the file you want to find

  • This command searches the index for the text string in a file name

  • use /etc/updatedb.conf to configure the behavior of the updatedb utility

4
New cards

Find v locate

  • The find command looks through every directory in the path that was specified

  • The locate command first builds an index of all files in the system, so when a search is run, it looks at its index, this is more efficient

5
New cards

The which command

  • Used to display the full path to a particular shell command or utility

  • ex. to find where the ls command resides in the file system use, which ls

6
New cards

The whereis command

  • Also used to find files, locate several pieces of information about a file, like source code, binary executable file, and manual page

  • ex. whereis ls, this shows the executable location and the man pages for that command’s location

7
New cards

The grep command

  • Used to search for a specific text string

  • Search for a message, or a specific directive within a configuration file

  • ex. grep firewalld /var/log/boot.log , this will search for the text firewalld within a file named boot.log located in the /var/log directory

8
New cards

grep command options

  • -i ignores case when searching for the test

  • -l (L) option displays only the names of the files that contain the matching text

  • -n displays matching line numbers

  • -r searches recursively through all subdirectories of the specified path

9
New cards

egrep command and regular expressions

  • When searching for more complex patterns such as files using regular expressions instead of a text string

  • Regular and metacharacters (Stuff* —> Stuffing, Stuff1, Stuffy)

10
New cards

fgrep command

  • Stands for fixing string grep, which is used to search for matching lines of text in the file being searched using direct string comparisons

  • Same as running grep with -F option

11
New cards

sed command

  • Can capture a text stream and then modify it, you can search through the text stream for certain words to replace with different words

  • ex. customers file has phone numbers and the area codes of 801 need to be changed to 435 —> sed -i s/801/435/g customers

12
New cards

awk command

  • An enhanced and more powerful version of sed, used to perform more complex stream editing

  • Treats a file as if it were a database, and each line is a record, and space between each word creates a new field, name them as $1, $2, etc

  • ex. customer file to print all the last names in the file —→ cat customers | awk ‘{print $2}’ , since all the last names are the second word in the file