0% found this document useful (0 votes)
30 views

Fundamentals 0f Cyber Security Labs - SEM1 - LAB4

The document discusses various file types and commands in Kali Linux. It describes the three basic file types - regular files, directories, and special files. It then provides details on basic commands for file handling and navigation in Kali Linux such as date, cal, cd, cp, whoami, ls, cat, mkdir, rm, mv, uname, uptime, users, less, more, vi, free, sort, and history.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Fundamentals 0f Cyber Security Labs - SEM1 - LAB4

The document discusses various file types and commands in Kali Linux. It describes the three basic file types - regular files, directories, and special files. It then provides details on basic commands for file handling and navigation in Kali Linux such as date, cal, cd, cp, whoami, ls, cat, mkdir, rm, mv, uname, uptime, users, less, more, vi, free, sort, and history.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Practical-4

Perform Basic Linux commands for file handling.


Kali Linux command is a powerful penetration testing
distribution by offensive security. It is available in 32-bit, 64-
bit and ARM flavors. With the help of the Kali Linux features, we can easily
create custom complex images. Kali Linux offers various certifications such
as OSCP, OSWE, OSEP, OSWP, OSEE, and KLCP. The testing tools of
the Kali Linux commands can be categorized into information gathering,
password attacks, vulnerability assessment, web applications,
exploitation tools, sniffing and spoofing, maintaining access,
system services and reporting tools.

Kali Linux comprises various tools that can be used for wireless attacks,
hardware hacking, forensics, stress testing, and reverse
engineering. A USB disk, hard disk, or Live DVD can be used to install
it. Network services are HTTP, MYSQL, and SSH. These are quite useful
when using the Kali Linux commands.

Kali Linux operates on some android devices. Its predecessor


is Backtrack which was carried over to Kali via Live Boot. The system
becomes easy to use once the users get the command over it.

In Kali Linux, most of the operations are performed on files. And to handle
these files Kali Linux has directories also known as folders which are
maintained in a tree-like structure. Though, these directories are also a type
of file themselves. Kali Linux has 3 basic types of files:
1. Regular Files: It is the common file type in Linux. it includes files
like – text files, images, binary files, etc. Such files can be created using the
touch command. They consist of the majority of files in the Linux/UNIX
system. The regular file contains ASCII or Human Readable text,
executable program binaries, program data, and much more.
2. Directories: Windows call these directories as folders. These are the
files that store the list of file names and the related information. The root
directory(/) is the base of the system, /home/ is the default location for
user’s home directories, /bin for Essential User Binaries, /boot – Static
Boot Files, etc. We could create new directories with mkdir command.
3. Special Files: Represents a real physical device such as a printer
which is used for IO operations. Device or special files are used for device
Input/Output(I/O) on UNIX and Linux systems. You can see them in a file
system as an ordinary directory or file.
In Unix systems, there are two types of special files for each device, i.e.
character special files and block special files. For more details, read the
article Unix file system.
4.
You can read more about the Linux File Management.
Kali Linux – File Hierarchy Structure

Kali Linux follows a specific File hierarchy structure which is just a way of
organizing files, filesystems, directories, installed packages, and external
devices connected to the system. It basically sets a standard or a base for
defining the directory structure.

In Kali Linux File Hierarchy Structure the base or the main directory which
contains all the directories is the root directory depicted by a “/”.
Kali Linux Basic Commands

The following is the list of Kali Linux basic commands:

1. Date Command
2. Cal Command
3. Cd command
4. Cp command
5. Whoami Command
6. Ls command
7. cat command
8. mkdir command
9. rm command
10. mv command
11. Uname command
12. Uptime command
13. Users Command
14. Less command
15. More command
16. Vi Command
17. Free Command
18. Sort Command
19. History Command
20.Pwd Command

1. Date Command

In Kali Linux, the 'date' command is used to display the system


date and time. In order to display the date, we have to use the following
command:

Syntax:

# date
2. Cal Command

The cal command displays the current month's formatted calendar on


our terminal screen. If we require a more advanced version of cal, we can
install the ncal package on our Linux machine, which displays the calendar
vertically and provides additional options.

Syntax

# Cal

3. Cd Command

The 'cd' command is also called chdir (Change Directory). We used this
command to change or switch the current working directory.

4. cp Command

In Kali Linux, the 'cp' command is used to copy files or a group of files or
directories that create an exact image of a file on a disk with a different file
name.
5. whoami Command

The 'whoami' command is used to print the effective user ID whereas


the who command prints information regarding users who are presently
logged in.

The "w" command can also be used to view who is logged on and what they
are doing.

6. Ls Command

One of the most useful commands in Kali Linux is the 'ls' command.
The ls command lists the directory contents of files and directories. With the
help of the ls command, we can easily list out every hidden file of a directory
with the -a attribute, and for more detailed output, we can use the -l attribute.

Syntax

# ls -al
7. Cat Command

The 'cat' (concatenate) command is one of Kali Linux's most commonly used
commands, permitting us to create single or many files, concatenate files and
redirect, view contain of file output in terminal or files.

Usually, we use the cat command to display the content of a file.

Syntax

# cat filename
8. mkdir Command

The 'mkdir' command is used to create directories. For example, if we


wish to create a directory named 'Penetration testing' under
the 'Documents' directory, then we have to open a terminal and enter the
below command:

1. cd Documents
2. mkdir Penetration testing

9. rm Command

In Kali Linux, the 'rm' command is used to delete files. It can be used to
delete directories when we use them recursively.

The removal process separates a file name form its associated data in a file
system and identifies that space in the storage device as available for future
writes. In other words, when we erase a file. the data inside it remains
unchanged, but it is no longer linked to a filename.
10. mv Command

With the help of the 'mv' command, we can move or renames files and
directories on our file system.

11. uname Command

The 'uname' command displays the current system's information. We


can view system information about our Linux environment with the uname
command in Linux. With the uname -a command, we can learn more about
our system, including Kernel Name, Node Name, Kernel Release,
Kernel Version, Hardware Platform, Processor, and Operating
System.

Syntax

# uname
12. uptime Command

The 'uptime' command displays the amount of time the system has been
running. Uptime's basic usage is simple: simply type the name of the
command and click Enter.

Use the -p command-line option if we merely want to know how long the
system has been up for and in a more human-readable format.

Syntax

# uptime

13. users Command

The 'users' command is used to display the login names of users logged in
on the system.

Syntax

# users

14. less Command

In Kali Linux, the 'less' command is used to view files instead of opening the
file. The less command is a more powerful variant of the "more" command
which is used to show information one page at a time to the terminal.
We can view any text file with the help of the "less" command simply by
typing the following command into a terminal window:

Syntax:

# less /etc/passwd

15. more Command

The "more" command permits us to show output in the terminal one page at
a time. This is particularly beneficial when using a command that requires a
lot of scrolling, such as the 'ls' command or the 'du' commands.

The 'more' command works with any applications that output to the screen.
A good way to test this is to type the following command into a terminal
window:
Syntax:

# moreetc/passwd

16. vi Command

The 'vi' editor is a screen editor that comes with practically


every UNIX system. The command mode and the insert mode are the
two most common nodes in vi.

In order to start entering text in an empty file, we have to first switch from the
command mode to the insert mode. To accomplish this, start typing the letter i.
When we start typing, anything then the type will be entered into the file.

Type some short lines, then press Return at the end of each. Vi does not use
word wrap like other word processors. It will break a line at the screen' edge.
If we make a mistake, we can undo it by pressing the Backspace key. If the
Backspace key on our computer is not working, then try the ctrl + h key
combination.
17. free Command

In Kali Linux, the 'free' command provides us the useful information about
the amount of RAM available on a Linux machine. It also displays the entire
amount of physical memory used and available space, as well as swap
memory with kernel buffers.

Syntax:

# free

If we use the free command with the -t option, it would list the total line at
the end.
18. sort Command

Using the 'sort' command, we can sort the content of the text file, line by line.
Sort is a standard command-line program which prints the lines of its input or
concentration of all files listed in its argument list in sorted order.

Syntax:

# sort file name

We can reverse the order of any file's contents by using the -r sort.

Syntax

# sort -r
19. history Command

The 'history' command is one of Kali Linux's most commonly used


commands. The history command in the bash shell saves a history of
commands entered that can be used to repeat commands.

We can run the history command by itself, and it will just print the current
user's bash history on the screen, as shown below:

Syntax:

# history

20. Pwd Command

In Kali Linux, the 'Pwd' command is used to print working directory. It


gives us information about the directory we are now in. This is especially
useful if we need to access the directory while in the middle of a complicated
process.
Managing and Working with Files in Kali Linux

1. To List the Files. In Kali Linux, we use ls command to list files and
directories. To use this enter the following command in the terminal.
ls

Output: This command will print all the file and directories in the current
directory.

2. To create a new file. In Kali Linux, we use touch command to create a new
file. To use this enter the following command in the terminal.
touch filename.extension
Output:This command will create a new file named filename.extension.

3. To display the content of a file. In Kali Linux, we use cat command to


display the contents of a file. To use this enter the following command in the
terminal.
cat filename.extension

Output:This command will print the content of the filename.extension file.

4. To copy files. In Kali Linux, we use cp command to copy files and


directories. To use this enter the following command in the terminal.
cp old/location/of/file /new/location/of/file

Output:This command will copy file form old location to new location.

5. To move files. In Kali Linux, we use mv command to move files and


directories. To use this enter the following command in the terminal.
mv old/location/of/file /new/location/of/file
Output:This command will move the file form old location to new location.

6. To rename a file. In Kali Linux, we use mv command to rename files and


directories. To use this enter the following command in the terminal.
mv filename.extension new_name.extension

Output:This command will rename the file from filename.extension to


new_name.extension.

7. To delete a file. In Kali Linux, we use rm command to delete files and


directories. To use this enter the following command in the terminal.
rm filename.extension

Output:This command will remove/delete the filename.extension from the


current directory.
8. To edit a file. In Kali Linux, we use nano command to edit files. To use
this enter the following command in the terminal.
nano filename.extension

Output:This command will open an editor to write to file and after


completing the same press ctrl+o to save the file.

You might also like