An Ethical Hackers Guide: Part 8 - Getting Familiar with The Linux Terminal

in #steemstem6 years ago (edited)

Hello Steemstemers, Utopians, Future Hackers and Crackers :]

Cliche_Hacker_and_Binary_Code_(26614834084) (1).jpg

Wikimedia Commons

Hey everyone, hope you're all having a kicking day :) Cerulean here, with the next part in my Ethical Hacking Guides, unfortunately today I have a bit of bad news! I spent a good few hours writing this post, then lost it all by accident, so I will do my best to recreate it, but I am sure it may seem a bit off at times. Thankfully I have all of my images saved, so I will give it my all. If you notice I've missed something please let me know :)


The Linux Terminal

term1.PNG

Screenshot

The Linux Terminal, is the command line to the system. When sitting at a command line, you have the most power over a computer's functionality. You could destroy the system with the wrong command. For those interested, this will strictly be a guide covering the basics of the terminal. It will not include very much bash.

The first thing we will need to do if following along with these guides, is power on our Kali VMs. We will not be needing our Whonix machines running, or really an internet connection of any kind. All of the commands and tools we will be using today require no online access. This will be strictly system administration.

The Terminal: Simple Navigation

The terminal, much like the file explorer in windows, is always working in a location(directory) of your computer. There are many situations where you will need to navigate yourself throughout the system. Some of these tools/commands include 'cd', 'pwd', and 'ls'. I will now go on to demonstrate the different tools/commands mentioned.

CD: Change Directory

term3.PNG

Screenshot

The 'cd' command, can be used to change the current working directory of your terminal. Much like moving from your desktop folder, to your pictures folder in the file explorer, your terminal can do the same thing. This comes in particularly handy when needing to manage files from the command line. Code follows.

cd Documents
cd
cd Desktop

As you can see from the example, and the image above, the user first changes directory into documents, using the 'cd' command, then returns home to the root folder, simply by issuing a blank 'cd', with no direction. After this, the user changes directory to the Desktop, just to further enforce the example.

PWD: Print Working Directory

term4.PNG

Screenshot

The 'pwd' command, standing for Print Working Directory, can be used to display the directory that the terminal is currently situated in, at time of execution. Often times when running through a terminal, you may find yourself lost. A quick 'pwd' will always let you know exactly where you are. Small example follows

cd Pictures
pwd

As you can see, our terminal responds immediately that our absolute path is 'root/Pictures'. Again, this will come in handy much more often the more comfortable you find yourself using the terminal.

LS: List, and Command Line Arguments

term5.PNG

Screenshot

The 'ls' command, is a particularly handy one. This is the command, used to display the contents of the directory to the user. In the above image, the user executes the 'ls' command, and is displayed the entire contents of the '/root' folder. This will be quite handy when trying to access strangely spelled files.

Another way to use commands like this one, is by adding command line arguments to the execution of a command. Command Line Arguments, are predetermined values, that modify how the tool is to be executed. I will show a small example using the 'ls' command.

term6.PNG

Screenshot

If you notice, in the above example, we are still in the /root directory, however this time we executed the command 'ls -l'. The '-l', standing for long, gives much more information about the directories contents, like file permissions, ownership and more. These concepts are important to Linux, but not to this guide, so we will not be discussing them further. Code follows below.

ls -l

The Terminal: Simple File Manipulation

Now that we have learned all of those different commands, I have even more for you to remember! Haha just as navigation had its own set of commands, file manipulation has a good group of tools as well. In this guide, we will be discussing the 'touch', 'cat', 'echo', 'mkdir', and 'cp' commands.

Touch: Create a blank file


term7.PNG

Screenshot

Touch, is a tool that is used for editing access times, something that we will not be doing very often in these guides. However, like many other Linux tools, the 'touch' command, when told to access a file that does not exist, will automatically create it. We can take advantage of this fact to create a blank file rather simply. Code follows below.

cd Documents
touch newfile
ls

In the above example, the user first uses the 'cd' command to change the terminals working directory to Documents. after this, we use 'touch' to create a file called 'newfile'. Finally, the user confirms the files existence, using the 'ls' command. There are not many other use cases for this command here. Now lets add some content to our file!

Cat, & Echo: File Reading/Writing

term8.PNG

Screenshot

Cat, standing for concatenate, is a handy tool used to read text from files, and write them to standard output. Echo is used strictly for writing. This is quite useful, as your terminal has now become a rather simple text editor. This is also quite useful in programming. Example follows below.

ls
echo "This is an empty file." > newfile
cat newfile

In the above examples, the user first displays the Documents directories contents. After this, we use the 'echo' command to write some text to our newly created file. Finally, we use the 'cat' command to confirm that the text has been written properly. This too has many use cases across the system, from programming to just general administration. (The '>' in the echo command, means to overwrite. To simple add to a file, use '>>' instead.)

CP: Create a Copy of a File or Directory

term9.PNG

Screenshot

ls
cp newfile newfile1
ls

The 'cp' command can be used to create an exact copy of a file, or directory. This may seem like a strange version of copy/paste, however in time you will see how this can be considered easier in ways. In the above examples, the user first displays directory contents using the 'ls' command, then uses 'cp' to create a copy of the file 'newfile', called 'newfile1'.

Mkdir: Create a New Directory

term10.PNG

Screenshot

The 'mkdir' command is what is used when a user wants to create a new directory, rather than file. This is quite a simple command, no different than clicking 'new folder' on windows, however I will still provide a brief demonstration. In the following example, the user first navigates to the Desktop directory, and there, we use the 'mkdir' command to create a new directory called 'New Folder'.

cd Desktop
mkdir 'New Folder'

The Terminal: Moving, Removing, & Renaming Files & Directories

Allright, so you have learned a nice set of commands for navigation, a good set for file manipulation, and lastly, lets go over the different ways to move, delete, or rename a file or directory. The tools, or commands used for these operations, include 'rm', 'rmdir', and 'mv'.

RM: Deleting a File or Directory

ter1.PNG

Screenshot

In the above example, the user first displays the directories contests with the 'ls' command, then uses 'touch' to create a file for us to delete, once again proving its existence using 'ls'. Once we have created a file, we can now carry on do delete it.

ls
touch newfile
ls

rm newfile
ls

In the next two lines, the user first uses the 'rm' command, so as to destroy the target file 'newfile', and then confirms that it has been erased, using the 'ls' command yet again. (If one wanted to delete a directory using the 'rm' command, rather than a file, they would need to add the -r argument, like such:

rm -r 'New Folder'

MV: Moving a File or Directory

ter2.PNG

Screenshot

The 'mv' command, is used quite simply to move a file, or sub-directory from one directory to another. In the above example, the user first creates a new file using the 'touch' command. After this, using 'ls' the file contents of the Documents directory are displayed to the user. Code follows.

touch newfile
ls /root/Documents
mv newfile /root/Documents/
ls /root/Documents.

In the third line, we use the 'mv' command, to move the file 'newfile' into our Documents directory. Finally, we confirm that the file has been moved using 'ls' on our Documents directory. This command in particular is quite useful, especially when scripting.

MV: Renaming a File or Directory

ter3.PNG

Screenshot

Funny enough, as the 'mv' command can be used to move a file or directory from one location to another, it can also be used to rename a file. In the above example, the user first creates a new file using 'touch', 'echo's some text into it, then confirms the text entry using 'cat', and confirms the files existence using 'ls'. These steps are taken to visualize that it is the exact same file being renamed, and not just a new blank file. code follows.

touch newfile
echo "Hello" > Newfile
cat newfile
ls

mv newfile newfile1
cat newfile1
ls

In the final three lines, the 'mv' command is used to rename 'newfile' to 'newfile1'. After that, we ensure that the file has not changed, using 'cat'. A final 'ls', shows us that there is no longer a file called 'newfile', only the newly renamed 'newfile1'.

Conclusion

ter4.PNG

Screenshot

Well guys, as always this has been a blast. I mean, writing this out twice wasn't all that exciting, but the first round was pretty good :P I hope this was informative, helpful, and enjoyable, and I can't wait for the next one. If you are enjoying using the Linux Terminal, and have further interest, as I do not have any resources for this yet, I strongly suggest you look into Bash Programming.

Happy Hunting,
Cerulean


An Ethical Hackers Guide: Part 1 - White-Hat, Grey-Hat, and Black-Hat. Who are you?
An Ethical Hackers Guide: Part 2 - Script Kiddie Password Recovery
An Ethical Hackers Guide: Part 3 - Virtual Machines, and Kali Linux - CrackBox Setup
An Ethical Hackers Guide: Part 4 - Basic Terminology, & Definitions
An Ethical Hackers Guide: Part 5 - Methodology and Tools
An Ethical Hackers Guide: Part 6 - Update, Upgrade, Nmap, and Metasploit!
An Ethical Hackers Guide: Part 7 - Whonix-Tor Gateway. Anonymize Your Network Traffic

Sort:  

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 2 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.

I upvoted your contribution because to my mind your post is at least 16 SBD worth and should receive 88 votes. It's now up to the lovely Steemit community to make this come true.

I am TrufflePig, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!

Have a nice day and sincerely yours,
trufflepig
TrufflePig

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.027
BTC 60003.48
ETH 2309.22
USDT 1.00
SBD 2.49