0% found this document useful (0 votes)
3K views16 pages

Termux The Hacker Inside You

The document discusses various Linux commands that can be used in Termux, an Android terminal emulator. It begins with basic commands like mkdir, touch, vim and cat. Then it covers more advanced commands such as less, head, tail and grep. The document provides explanations and examples of how to use these commands.

Uploaded by

nishasharmat415
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views16 pages

Termux The Hacker Inside You

The document discusses various Linux commands that can be used in Termux, an Android terminal emulator. It begins with basic commands like mkdir, touch, vim and cat. Then it covers more advanced commands such as less, head, tail and grep. The document provides explanations and examples of how to use these commands.

Uploaded by

nishasharmat415
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Hi there. I am Prince Kumar Devvrat a junior mechanical engineer.

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.

FIGURE 1.1 CLI


The image labelled 1.1 depicts the Windows Subsystem for Linux (WSL).

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.

FIGURE 1.2 F-DROID


Download F-DROID and install it. Allow unknown sources if needed. Now
open the app and search for Termux.

FIGURE 1.3 F-DROID Termux

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:

 ‘pkg’ refers to ‘package’.


 The meanings of ‘upgrade’ and ‘update’ are self-explanatory.
 The ‘&&’ operator indicates that the second command should execute
only if the first command succeeds."

5|
2.Basics commands

In the initial chapter, we discussed how to download the latest version of


Termux and update its package list. In this chapter, we will explore basic
commands in Termux and learn how to use them effectively.
The first command in the list is ‘mkdir’, which is used to create a folder or
folders. Simply type ‘mkdir foldername’, and it will create a folder in
the current working directory.

FIGURE 2.1 mkdir and ls

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.

FIGURE 2.3 vim text editor


After completing your edits in the file, you’ll want to save it. To do so, press
the Escape key (ESC), which will return you to command mode. Now,
type ‘:wq’ and press Enter to save your changes. The cat command is
primarily used to view the contents of a file. While it can also be employed to
create files, in this lesson, we will focus solely on viewing content. To view
the contents of a file, simply run
 cat filename

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

FIGURE 2.5 pwd


To verify this, we can run the ‘pwd’ command, which stands for ‘present
working directory’. You’ll notice that we are currently inside ‘folder1’.
Whenever you encounter difficulties using a specific command, you can
run ‘CMD name --help’ or ‘man CMD name’. Nearly all commands include
a help option that provides information on how to use that particular
command.

FIGURE 2.6 help


If ‘man’ is not installed on your Termux, you can install it by running the
following command.
 pkg install man
And again, if you are prompted with a yes/no question, simply press ‘y’ to
grant the necessary permission.

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.

FIGURE 2.7 echo


 cal
cal is a command used to display the calendar in the terminal. By default, it
shows the current month, but you can provide a specific year to view the
entire year.

FIGURE 2.8 cal

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.

FIGURE 2.9 uname -a


figlet is a command used to display stylized text, as shown in pic 2.10. We’ll
explore its uses further later.

FIGURE 2.10 figlet


rmdir is used to remove an empty directory. However, if you want to delete a
directory that contains files or other content, you can use the rm -rf
directoryname command. the whoami command displays the current user.

10 |
3.Advance commands

In our previous chapter, we explored basic commands in Termux. Now, let’s


dive into more advanced commands and their practical applications. It’s time
to flex your Linux muscles and take your skills to the next level! Let’s begin
this exciting journey.
Before we delve into more complex topics, let’s begin by exploring some
fundamental terminology.
stdin stands for standard input. By default, it takes input from the keyboard.
stdout stands for standard output. It refers to the stream of data produced by
the command line. When a program sends its output, it is usually directed
to stdout.
stderr stands for standard error. When a process encounters an error, it
usually sends the error message to stderr.
In Termux, the dot (.) represents the current directory, while two dots (..)
represent the parent directory.
‘|’ The pipe symbol (|) in Linux is used to redirect the output of one command
to the input of another command.
A regular expression (regex) is a sequence of characters used to define
patterns in text. These patterns are employed for searching, replacing, and
validating strings.
 less and more
Both less and more are used to read large files one page or one screen at a
time. However, less is faster than more because it doesn’t load the entire file
at once. Therefore, if you need to read a large file, it’s recommended to
use less.To exit less, simply press ‘q’. Use the spacebar to move forward one
page, and you can also navigate using the arrow keys.
 less filename
 head and tail

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.

FIGURE 3.1 head

FIGURE 3.2 tail


grep, which stands for “Global Regular Expression Print,” is a powerful
command-line utility primarily used in Unix-like operating systems. Its
purpose is to search for lines within files or standard input that match a
specified regular expression pattern. Once it identifies these matching lines, it
outputs them to the program’s standard output.
 grep [options…] pattern filename

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

FIGURE 3.3 grep


We can use this command in another way: cat text.txt | grep "night". The result
will be the same. As you may recall, we discussed piping in Linux, where the
output of one command serves as the input for another command. In this case,
it sends the output of the cat command to the input of the grep command.
Now we are searching for the word ‘and’ as shown in the picture 3.4 . The line
currently contains only the lowercase ‘and,’ but we want to return all
occurrences of ‘and,’ regardless of whether they are lowercase or uppercase.
To achieve this, we can use the -i option, which instructs the search to ignore
case.

FIGURE 3.4 grep ignore case

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.

FIGURE 3.5 caret and dollar


 The dot (.) is used to match any character.
FIGURE 3.6 dot

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.

FIGURE 3.7 grep square bracket


The expression ‘[ae]nd’ will match the words ‘and’ and ‘end’.
The expression is limitless, and it depends on you how you construct it to
accomplish your desired task. You’ll encounter more complex expressions as
we delve into building our own Bash script.

 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.

FIGURE 3.8 cut bytes


Alternatively, you can define a range like this: cut -b 1-3 filename. If you omit
the last byte number, it will refer to the last byte. The -c option is used to

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.

FIGURE 3.9 awk

16 |

You might also like