Teaching Cyber Security (Part 6)

in cybersecurity •  7 years ago 

This is the 6th post of a series for teaching cyber-security in a coding-club. Read [part 5].

If you are teaching this course you can clone the files and directories to follow along. The files can be found here: https://github.com/alphydan/hacker-tools-m1-u1

Navigating directories using the Shell?

Bash provides a widely used command called cd or change directories command that allows the user to navigate through directories.

In order to see how it works, perform the following:

  1. Click on the terminal window
  2. Type ls to list the current directory contents, return key
  3. Type cd dir1 to enter the dir1 directory, return key
  4. Type ls to list the dir1 directory contents, return key

If you open the dir1 folder, it should match the contents you got from the ls command.

That's it, you've learned how to enter a directory in bash scripting.

brain to remember Command: cd

Definition:
The cd command or change directories command allows you to go inside a directory by adding its name as an argument:

cd name_of_directory

At the top of this page, you entered a directory using cd dir1. Can you guess how to get back to the main workspace directory?

Remember the double dots?

When we executed the ls -a command, we noticed a set of single and double dots: . ..

As we previously mentioned these dots are utilities that bash uses to help navigate the file system.

Going back one directory level

Having entered the dir1 directory in the previous section, we may then want to get back out of it:

  1. Execute the pwd command to confirm we are on the dir1 directory
  2. Execute the ls -a command to confirm that we indeed have single and double dots available
  3. Execute cd .. to exit the current directory and go back 1 directory (to the parent directory)
  4. Execute pwd to confirm that we are back on the /home/user/workspace/ directory

question-45px.png Testing your knowledge:

Can you confirm that you are at /home/user/workspace/ or the equivalent directory in your computer? Can you then change directory inside dir1 and exit again?

Reading files

Reading the content of files

Once you enter a server, how can you read what is inside a file if you don't have a screen?

Lets do that:

  1. Execute cd dir1 on the shell to move to the dir1 directory.

  2. What is inside the directory? let's find out: execute ls

You should see

file1.txt

The end of the file .txt tells us that it's a text file. But how do we read them? For that we use cats!

cat_reads.jpg:

brain to remember Command: cat or 'Concatenate'

Definition: The cat command shows the content of text files.
To Concatenate means to put one thing next to another. In the Shell it means to print the contents of the file next to each other on the shell output. Let's try it:

  1. move to the dir1 directory using cd dir1
  2. print a list of the files using ls
  3. print the content of the file with cat file1.txt

Your terminal should have printed a bunch of numbers. file1.txt actually contains a list of prime numbers (which are very important in cyber-security).

What about making files?

Once you get into the server, you will have to prove that you were in there. A way to do so is to leave a file behind. Let's create a file.

  1. Move to the dir1 directory
  2. Make sure we are inside dir1 with the pwd command
  3. Execute: touch file123.txt

brain to remember Command: touch

Definition: if any file does not exist, the touch command will create one for you.

Additionaly, the touch command needs an argument, in this case, the argument is the name of the file to be created, don't forget the file extension:

touch file.extension


What is a file extension? File extensions are also known as file formats. You may be familiar with .doc, .docx, .xls or .xlsx for Microsoft Word and Microsoft Excel respectively. In most cases file extensions determine the program that should or can read the file.

End of Unit 1

So far we've learned 6 bash commands:

  • whoami
  • pwd to print working directory
  • ls and the options ls -a, ls -l
    (Go ahead and try 3 options at once in the terminal: ls -alh : which means: list --all --list --human-readable)
  • cd to change directory
  • touch somefile.txt to create some file.
  • cat somefile.txt to see the content of the file

and finally some navigation tricks like cd .. to move up a directory level or cd ~ to move back to the home folder.

We know that the command line interface, CLI for short, is also known as the shell or command terminal as well. Bash in the other hand, runs inside the terminal and is in charge of recognizing, interpreting and executing the text commands written in the shell.

So now you know how to interact with a server through the shell. But how do we get in?
server_in_holland.jpg

More about that in the next unit.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @alphydan! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!