Hey there, I am Samrat Gupta aka Sm4rty, a Security Researcher and a Bug Bounty Hunter. In this Blog I will be sharing some of the common utilities of Linux which can be a very useful in Hacking/Bugbounty or in any general use and will surely save you a lot of time.
Let’s start without wasting any time.
1. GREP:
The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. The pattern that is searched in the file is referred to as the regular expression.
It has many practical use cases and is certainly one of the most used Linux commands.
Syntax of grep Command :
grep [options] pattern [files]
WHAT CAN WE DO WITH GREP?
1. Find Text in Files.
2. Find Filenames Using Extensions.
3. Find Patterns in Compressed Files.
4. Find URLs From Source Files
5. Search All Files in Directory and Subdirectories.
Further Reads:
https://www.makeuseof.com/grep-command-practical-examples/
https://www.geeksforgeeks.org/grep-command-in-unixlinux/
https://phoenixnap.com/kb/grep-command-linux-unix-examples
2. SED:
SED command in UNIX stands for stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. Primarily, it is used for text substitution; additionally, it can be used for other text manipulation operations like insert, delete, search, and more.
The SED command allows us to edit files without opening them. Regular expression support makes it a much more powerful text manipulation tools.
Syntax of sed Command :
sed OPTIONS... [SCRIPT] [INPUTFILE...]
WHAT CAN WE DO WITH SED?
1. Replacing or substituting string
2. Inserting and Appending Text
3. Using regular expressions — advanced substitution
4. Adding Blank lines/spaces
Further Reads:
https://www.javatpoint.com/linux-sed
https://www.linuxtechi.com/20-sed-command-examples-linux-users/
https://www.tecmint.com/linux-sed-command-tips-tricks/
3. AWK:
Awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators.
Awk is a utility that enables a programmer to write tiny but effective programs in the form of statements that define text patterns that are to be searched for in each line of a document and the action that is to be taken when a match is found within a line.
Syntax of awk Command :
awk options 'selection _criteria {action }' input-file > output-file
WHAT CAN WE DO WITH AWK?
1. Scans a file line by line
2. Splits each input line into fields
3. Compares input line/fields to pattern
4. Generate formatted reports.
Further Reads:
https://likegeeks.com/awk-command/
https://www.geeksforgeeks.org/awk-command-unixlinux-examples/
https://www.tutorialspoint.com/awk/awk_basic_examples.htm
4. FIND:
The Linux find command is one of the most important and frequently used command command-line utility in Unix-like operating systems. The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.
find command can be used in a variety of conditions like you can find files by permissions, users, groups, file types, date, size, and other possible criteria.
Syntax of find Command :
find [where to start searching from]
[expression determines what to find] [-options] [what to find]
Further Reads:
https://www.geeksforgeeks.org/find-command-in-linux-with-examples/
https://www.tecmint.com/35-practical-examples-of-linux-find-command/
https://www.linuxtechi.com/25-find-command-examples-for-linux-beginners/
5. ALIAS:
In Linux, an alias is a shortcut that references a command. An alias replaces a string that invokes a command in the Linux shell with another user-defined string.
Aliases are mostly used to replace long commands, improving efficiency and avoiding potential spelling errors. Aliases can also replace commands with additional options, making them easier to use.
Creating an alias Syntax:
alias name="value"
Create a Permanent Alias in Linux
To make an alias permanent, you need to add it to your shell configuration file. Depending on the type of shell you are using, use:
- Bash shell: ~/.bashrc
- Zsh shell: ~/.zshrc
Further Reads:
https://www.geeksforgeeks.org/alias-command-in-linux-with-examples/
https://phoenixnap.com/kb/linux-alias-command
https://www.tutorialspoint.com/unix_commands/alias.htm
6. UNIQ:
The uniq command in Linux is a command-line utility that reports or filters out the repeated lines in a file.
In simple words, uniq is the tool that helps to detect the adjacent duplicate lines and also deletes the duplicate lines. uniq filters out the adjacent matching lines from the input file(that is required as an argument) and writes the filtered data to the output file.
Syntax of uniq Command :
uniq [OPTION] [INPUT[OUTPUT]]
Further Reads:
https://www.geeksforgeeks.org/uniq-command-in-linux-with-examples/
https://www.redhat.com/sysadmin/uniq-command-lists
https://www.howtoforge.com/linux-uniq-command/
7. XARGS:
Xargs is a great command that reads streams of data from standard input, then generates and executes command lines; meaning it can take output of a command and passes it as argument of another command.
Some commands like grep can accept input as parameters, but some commands accepts arguments, this is place where xargs came into picture. There are several ways in which xargs is useful in daily usage of the command line.
Syntax of xargs Command:
xargs [options] [command]
Further Reads:
https://www.geeksforgeeks.org/xargs-command-unix/
https://www.tecmint.com/xargs-command-examples/
https://phoenixnap.com/kb/xargs-command
8. SORT:
The sort command is used in Linux to print the output of a file in given order. This command processes on your data (the content of the file or output of any command) and reorders it in the specified way, which helps us to read the data efficiently.
It is very useful in cases where large quantities of information are available and need to be arranged in alphabetical or ascending or descending numerical order.
Syntax of sort Command:
sort [OPTION]… [FILE]…
Further Reads:
https://www.redhat.com/sysadmin/sort-command-linux
https://www.geeksforgeeks.org/sort-command-linuxunix-examples/
https://linuxhint.com/sort-command-in-linux-with-examples/
9. DIFF:
diff stands for difference. This command is used to display the differences in the files by comparing the files line by line.diff
is a command-line utility that allows you to compare two files line by line. It can also compare the contents of directories.
The diff
command is most commonly used to create a patch containing the differences between one or more files that can be applied using the patch
command.
Syntax of diff command:
diff [OPTION]... FILESdiff file1 file2
//it will display the difference between two files.
Further Reads:
https://phoenixnap.com/kb/linux-diff
https://linuxize.com/post/diff-command-in-linux/
https://www.geeksforgeeks.org/diff-command-linux-examples/
10. CRON:
The cron system is a method to automatically run commands on a schedule. A scheduled job is called a cronjob, and it’s created in a file called a crontab. It’s the easiest and oldest way for a computer user to automate their computer.
To create a cronjob, you edit your crontab
using the -e
option:
$ crontab -e
The standard form for a crontab line is as follows:
a b c d e /directory/command output
So, the parts of a cron command are:
1. The first five fields a b c d e specify the time/date and recurrence of job.
2. In the second section, the /directory/command specifies the location and script you want to run.
3. The final segment output is optional. It defines how the system notifies the user of the job completion.
Further Reads:
https://opensource.com/article/21/7/cron-linux
https://www.geeksforgeeks.org/crontab-in-linux-with-examples/
https://phoenixnap.com/kb/set-up-cron-job-linux
Thanks for Reading. Any Suggestions are always welcomed!!
If you haven’t Subscribed yet, Please Do Subscribe. You can Buy me a coffee and Follow me on Twitter.