Below are the description/usage of 10 most used linux commands:
- grep command:- Its name comes from the ed command g/re/p (globally search a regular expression and print).
The grep command is used to search text or searches the given file for lines containing a match to the given strings or words. By default, grep displays the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. grep is considered as one of the most useful commands on Unix and other Linux operating systems.
Usage:-- Find count of matching word
Example: grep -c "queue" sanj_ms1.log
this will find the number of occurence of queue word in the file sanj_ms1.log - Showing particular number of lines from the file after the matching
word
Example: grep -C 2 "queue" sanj_ms1.log or grep --context="2" "queue" sanj_ms1.log - Different varient of grep command
- pgrep is command to give the process id for a supplied process arugment
> pgrep -lf java - grep -i is do case insensetive search:-
This is also a basic usage of the grep. This searches for the given string/pattern case insensitively. So it matches all the words such as “the”, “THE” and “The” case insensitively as shown below.grep -i "string" FILE
here -l is for name of the process and -f is for full search any command line which containing the process name specified - zgrep is used on compressed files to search for particular string within the zip file
> zgrep -iw "less" newtestfile.txt.gz
$ grep -i less test-file.txt This particular command will search for exact word less
>zgrep -i "less" newtestfile.txt.gz
zless - file perusal filter for crt viewing of compressed text
$ grep -i less test-file.txt
zless - file perusal filter for crt viewing of compressed text
in this command its searching for all lines which contains less or word containing less.
- Find count of matching word
- SCP command:- scp or secure copy is a method of transferring file to remote machine or transfer of file between two remote machine it uses SSH as protocol
For examples: we can refer to : http://www.hypexr.org/linux_scp_help.php - Find command:-
Example 1:
find /path/to/files* -mtime +5 -exec rm {} \;- the first argument is the path to the files
- second arugment -mtime is used to specify the number of days old that file is +5 will fetch files which are 5 days older
- the third arugment -exec allow to pass commands like rm {} \; is required to end the command
Find files ignoring case
find -iname *.txt
Example 3:
Find files as per the sizefind . -size +1000c -exec ls -l {} \; - # netstat -tulpn | grep --color :80
- To extract a tarball to a specific directory
untar -xvf filename.tar -C /tmp/dirname (it will unzip to particular directory)
Bash find files between two dates:find . -type f -newermt 2010-10-07 ! -newermt 2014-10-08Returns a list of files that have timestamps after 2010-10-07 and before 2014-10-08Bash find files from 15 minutes ago until now:find . -type f -mmin -15Returns a list of files that have timestamps after 15 minutes ago but before now.Bash find files between two timestamps:find . -type f -newermt "2014-10-08 10:17:00" ! -newermt "2014-10-08 10:53:00"Returns files with timestamps between2014-10-08 10:17:00and2014-10-08 10:53:00