1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
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
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
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
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
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
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
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
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
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)
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
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
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