Hack Like a Pro: Linux Basics for the Aspiring Hacker, Part 2 (Creating Directories & Files)

Linux Basics for the Aspiring Hacker, Part 2 (Creating Directories & Files)

In my first tutorial on Linux basics, I discussed the importance of hackers using Linux and the structure of the directory system. We also looked briefly at the cd command. In this second Linux guide, I'll spend a bit more time with changing directories, listing directories, creating files and directories, and finally, getting help.

Let's open up BackTrack and getting started learning more Linux for the aspiring hacker.

Step 1: Change Directory (Cd)

We can change directories in multiple ways with cd. As I showed you in my previous article, we can use cd .. to move up one level in the directory tree. We can also move directly to the root directory by typing cd / or move to our home directory by cd ~.

More often, we will use cd to move to a directory by using the absolute path of the directory. This mean that we write out the entire path of the directory we want to move to after cd. We can also move to the directory by using the relative path of the directory. This means that we don't need to write the entire path, but simply use the path that we're currently in and append to it. Let's look at some examples.

Let's say we're in our root user directory in BackTrack and we want to move to the aircrack-ng directory (we'll be doing some aircrack tutorials soon). We can simply type:

  • bt > cd /pentest/wireless/aircrack-ng

This will take us directly to the aircrack-ng directory.

Now let's say we want to go to the scripts sub-directory within aircrack-ng. We could type out the full path to the sub-directory, but it's much simpler to type the relative path from where we are. We know we are /pentest/wireless/aircrack-ng, so type:

  • bt > cd scripts

And that takes us to the scripts sub-directory within aircrack-ng or /pentest/wireless/aircrack-ng/scripts.

Once again, it's critical to emphasize that Linux is case sensitive, so typing the directory without the proper case will result in the error message, "no such file or directory".

Step 2: Listing Command (Ls)

Once of most used and important commands in Linux is ls or list. This command is used to list the contents of a directory or sub-directory so that we can see the contents. It's very similar to the dir command in Windows. So let's use it in the aircrack-ng directory;

  • bt > ls

We can see that Linux listed all the files and directories within the aircrack-ng directory. Linux allows us to modify its commands by using switches; these are usually letters preceded by the dash (-). With ls, it's helpful to use two of theses switches, -a and -l.

The -a switch means all, so when we use it, Linux will list all files and directories, even those that are hidden. When we use the -l switch, it gives us a long listing, meaning it gives us info on the security permissions, the size, the owner, the group of the file or directory, when it was created, etc.

Let's type:

  • bt > ls -la

We'll examine more closely the security permissions in a later tutorial, but you must know that you need execute (x) permission on any file you want to execute. So, if you download a new tool, you must make certain that you have execute permission on it.

Step 3: Create a File (Touch)

The create a file in Linux, it's a bit different from Windows. In Linux, we use the touch command. So, let's create a new file called newfile:

  • bt > touch newfile

Now we can check to see if that file exists by doing a directory listing:

  • bt > ls -la

We can see that new file has been created!

Step 4: Create a Directory (Mkdir)

Similar to Windows, we can create a directory by using the make directory command (mkdir). Let's now make a new directory.

  • bt > mkdir newdirectory

Now type ls and we can see that a new directory has been created .

Step 5: Getting Help (Man)

Linux has a very useful utility called man. Man is the manual for nearly every command. If you should forget what a command does, simply type man and the name of the command and it will display the manual with all the info you need about that command, its switches, and arguments. For instance, type:

  • bt > man touch

With most commands, you can also use either the -h switch or the --help switch after the command to obtain "help" about a particular command. In the case of "touch", we must use the --help to obtain help on the touch command.

  • bt > touch --help

And that's it for this brief tutorial on Linux for aspiring hackers. Make sure to check out the first part if you haven't already.

I'll be going more into depth in my next tutorial, so keep coming back!

Penguin photo by mdid

Just updated your iPhone to iOS 18? You'll find a ton of hot new features for some of your most-used Apple apps. Dive in and see for yourself:

49 Comments

good one,the best i was finding

hey occupy the web, ive been having a problem with my metasploit. when ever i get a host pc or anything and i try to use an attack or exploit it gives me an error

"loading stdapi. try command again"
ive updated metasploit and restarted and tried on a new host but same thing, any help here?

Guillermo:

Couple questions. What OS are you hosting Metasploit on? Second, does this message after you have successfully exploited the system? Third, it sounds like you have exploited the system, have a meterpreter and then you try to run commands on it?

OTW

first im useing metasploit on kali
seccond yes after the system has downloaded the meterpreter
im using a reverse java tcp to exploit it
then after selecting something like take screen shot i get the error

Guillermo:

Metasploit's meterpreter will throw that error when the command you are trying to use is not available within that payload. Try using a different payload such as reverse_tcp.

OTW

Backtrack os is no longer supported so should i download kali linux os??

It work Kali linux plz tell

ACP:

I did not understand your question. Please try asking it again.

OTW

When I comand this show

The directory is different in Kali.

what bro

Thanx Bro

Great beginner's tutorial, thanks! I can't wait to read through all the lessons and finally migrate from Windows to Linux.

As a beginner, Directory paths is one of the most difficult road blocks for me. I guess there is not choice but memorize the paths? In a GUI environment one can just click around and visually find any file even if you're not sure where it may be, but in Linux you really need to know where things are and type such path huh?

Excuse my naive comment, but I'd really appreciate any insight/feedback from you and other users .

Thanks again,

thanks a lot for spending time making this kind of tuto for noobs :) very helpful !

Hey OTW,why is mine different?What did I do wrong?Thanks by the way.

This tutorial was written with BackTrack and you are using Kali. The file and directories are in different locations between these two distributions.

Thanks OTW,and by the way me being in Malaysia just means that our time is different,for example the time i'm writing this post is 1.16PM in the afternoon however in the USA it is 12.17AM in the morning.So due to timing differences my reply might be late just to let you know.Peace Out.

Thank you OTW, I am enjoying your tutorial more than that of the Linux Foundation. I have found that I learn best by 1. lecture, 2. reinforce by doing , 3. drive it home by teaching others. Your smaller chunks make it easier for me read the section, then go back and do. I doubt that I will get to the 3rd stage with this, I teach A+, Net + and Security + at the college but they don't do Linux. I was hoping as one of the other part time instructors was going to teach 802.11 pen testing using Ubuntu, but the class was canceled.

Whenever i try to do something it says 'No space left on devices' and if i do df -i it says rootfs Inodes 1884160 Iused 1884160, any help? same for /dev/disk/by-uuid/bf0d668c-8dc9-4efb-86a2-79b1113f0cc0

Sounds like your device is full.

solved by reinstalling thanks anyway!

I know the problem now, i wanted to try the commend crunch out but i failed and now my /root file is full of text files, but when i try to remove 1, linux goes black and freeze. Do you know how to fix?

hye
Im using kali linux not Bt..
then i cant open
root@kali:~# cd /
root@kali:/# pwd
/
root@kali:/# cd /pentest/wireless/aircrack-ng
bash: cd: /pentest/wireless/aircrack-ng: No such file or directory

I have the same problem as him. I'm guessing this is either because I'm running Kali instead of BT, or because I'm running it on a Live USB version.

Hi OTW I just started reading your linux basics tutorial (It is great btw) but I am having the same issue as a few people with kali linux and it not being a directory. Ive went to your 4th installment in the series like you had said and i used the find command to search for aircrack-ng and a few things came up. I just dont know which one I need to use. I am using kali on a Live USB btw i hope that shouldnt be an issue

When you get the message that it is "not a directory or file" that is because of;

  1. You spelled it wrong
  2. Linux is case sensitive and you used the wrong case
  3. The file you are looking for is not in that directory.

In the specific case of aircrack-ng, you only need to type it at the command line like this;

aircrack-ng

and it will bring up the help screen.

OTW

I don't have Linux :'( are their any other programs like it for windows 8? Or should I just dual boot???

You should run Kali as dual boot or in a virtual machine.

alright thanks man, I'm trying to find flaws in servers and attack to get files, like some light forums or self made websites to get information or data like usernames and pass, do you have any idea ontop I should start that out?

Yes, to start out, install Kali Linux. Then, study Linux by going through all the lessons in this Linux series. Next, read my article on "How to Use Null Byte to Study to Become a Professional Hacker".

Thanks man your amazing :D

I wish this site had a way to link articles as a series. Its very cumbersome to go to the next installation of an article series. I feel like I need to bookmark each article individually.

Very good note! I'm adding it to our list of possible new site features, and hopefully we'll figure out a way to get this implemented.

That would be great, Justin!

Several readers have asked the same thing.

Yes! That would be great. Some sort of "go to next article/ previous article" feature would be great. Going to someone's profile page and just diving into any series they have put out, it would greatly make that easier. Don't get me wrong, I love this site. So much relevant content its ridiculous.

I agree a goto/net article would be beneficial, i usually start reading about wireless hacking htne end up on meterpreter and then back to understanding linux.. and looping...

When I type cd/ it says not such file ordurectory I am with kai llinux virtual box and I am very new to this please help.i coud go /cd Documents and It respon me I am i,but cd .. not works Also can't go to cd/pentest/wireless/aircrack-ng it says not a directory why

I creatd new file in Documents called new file,but cant list it wth ls-la -bash.Only coud with ls and it show me new di restory and the new file...

type cd (space)/
not cd/

such an old post but still useful

I see the top directory. But Cali did not want to try to open. I read the lesson 4, but without success. Run the Internet stupid. I can't understand. I ask for your attention. Thank you.

If I install backtrack on VM box ,do i need to install separately kali linux on VM box also for using linux all advantages and tools for hacking????

What should I install on VM box Bactrack or kali linux for hacking?

Hi, is it possible u could make a tutorial on Kali Linux, because I really would like to become an WHITEHAT hacker and its just that im using Kali Linux and i cant exactly learn the commands. If you already have tutorials on Kali Linux could you please send me the link? Thanks, Jenny.

very good again!

ty,
keep going!

Share Your Thoughts

  • Hot
  • Latest