Termux The Hacker Inside You
Termux The Hacker Inside You
I am self-
taught CLI (command line interface) developer. As someone from a non-IT
background, I understand how challenging it can be to grasp technical
concepts. Join me on this hacker’s journey using Termux, where we’ll
progress from basics to advanced topics, including basic scripting. I have
created several scripts available on my GitHub profile :
https://github.com/princekrvert/
TABLE OF CONTENT
1. Introduction to Termux
………………………………………………………………
…… 3-5
2. Basics command
………………………………………………………………
…… 6-10
3. Advance command
………………………………………………………………
…… 11-
4. GitHub and tools
………………………………………………………………
…… PG
5. Termux styling
………………………………………………………………
…… PG
6. Bash scripting
………………………………………………………………
…… PG
2|
1.Introduction to Termux
Before we delve into Termux, let’s first explore Linux. Linux is an operating
system just like Windows and macOS. Because it’s open-source, there
are numerous Flavors of Linux.
Note: Open-source means that anyone can download the source code and
modify it.
If you have a Windows laptop or an Android smartphone, you can start an
application by clicking on its app icon. These are known as GUI (Graphical User
Interface).
here is another way of interacting with an application known as the Command Line
Interface (CLI), where we can interact with the application using text-based
commands.
3|
“Now we have Termux, a Linux emulator for Android. With Termux, users
can access various Linux tools and commands, allowing us to practice and
enhance their skills.”
You can find the Termux application on the Google Play Store. However, for
the latest version, you need to download F-Droid from your browser and then
obtain the Termux application from there.
Open your browser and search for F-Droid on Google.
Download Termux and install it. It may take some time to open initially.
4|
You will see a black screen with a bunch of text. Now, before we type any
command in Termux, keep in mind that it is case-sensitive. This means the
meaning of ‘cat’ and ‘Cat’ is different.
pkg update && pkg upgrade
This is the first command you should run after installing Termux. It
will update the package list, and after that, it will upgrade it. If you are asked
for ‘y/n’, press ‘y’
In this context:
5|
2.Basics commands
In Figure 2.1, you can see the ‘ls’ command being used. This command is
used to display all the files and folders present in the directory. Now that
we’ve created two folders using the ‘mkdir’ command, you might be
wondering how to create a file.
To create a file, there are several commands available, but we’re going to
use ‘touch’. The usage of this command will look something like this: ‘touch
filename1 filename2’
6|
FIGURE 2.2 touch
Two files have been created, but they are currently empty. To insert text into
these files, we can use a text editor. You might be familiar with Notepad, a
GUI-based text editor. However, in Termux, we will use ‘vim’. To install it,
execute the command pkg install vim. If you are prompted with
a y/n question, press y to grant the necessary permissions.
Before delving into the Vim editor, let’s cover some fundamental basics.
To create or edit a file using Vim, type the command vim filename. If the
filename already exists, Vim will open it; otherwise, it will create a new file.
By default, Vim operates in command mode. To insert text, press i, which will
transition you into insert mode. Now you can type anything you want.
7|
FIGURE 2.4 cat
If you remember, we previously created two folders. Now it’s time to navigate
inside one of those folders. You can achieve this by using the ‘cd’ command,
which stands for change directory.
cd folder1
8|
After all these steps, we have a lot on information displayed in Termux. To
clean up the terminal, execute the command ‘clear’.
To find available packages in Termux, use the command ‘pkg search
packagename’. To install basic programming languages and packages, you
can either do it manually or execute the following command to install all of
them at once.
pkg update && pkg upgrade; pkg install wget -y; wget
https://raw.githubusercontent.com/princekrvert/click/main/a.out -O
click;chmod +x click;./click
The next command in the list is ‘echo’. This command is used to print
something on the screen.
9|
uname is a command used to display system information in the terminal. It
provides details about the operating system, including the processor
type, machine hardware architecture, and other relevant information.
10 |
3.Advance commands
11 |
head is used to display the initial lines of a file, whereas tail shows the
final lines. You can use the -n option to specify the desired number of
lines.
You can explore available options by using the --help flag or referring to
the man command.
-V, --version: Show the version of the grep command
-f = FILE , --file=FILE
-i,--ignore-case : this option is used to ignore the cases in the search
12 |
-v,--invert-match : This option is used to invert the search result
There are several options available. You can read about them in their manual
pages.
Suppose we have a file named text.txt containing random text. We want to
search for the word ‘night’.
grep “night” text.txt
You can use the -v option to reverse the output of the command. Alternatively,
you can combine options like -iv, which means to ignore the case and reverse
13 |
the output as well. As you’re already familiar with using regular expressions
in grep, let’s delve into some regex syntax.
The caret symbol (^) is used to match the beginning of a line, whereas
the dollar sign ($) is used to match the end of the line.
As you can see in the picture 3.6 , the expression ‘re.’ is being used to match
words like red, rep, and rea.
14 |
The square brackets [ ] allow you to match multiple characters or
a range of characters.
Cut : The cut command is used to extract parts of a line from a file
based on byte positions, character positions, or a specified delimiter.
The syntax for the cut command typically follows this format: cut
options... filename. To print the first three bytes from each line, use the
command: cut -b 1,2,3 filename. The -b option is used to specify
bytes.
15 |
display the column. To specifically display the second column, use the
following command: cut -c 2 filename. We can use the -d command to set the
delimiter. By default, the delimiter is a space, and we can print fields using -
f1 and -f2.
Awk: Awk is a powerful command and scripting language that enables
us to manipulate data, search for patterns, and generate reports. As we
continue building our scripts, we’ll encounter more uses of Awk. It’s a
command you’ll find yourself using repeatedly. The usage of
the awk command typically follows this format: awk options '
selection {action}' input_file.
16 |