Introduction to Bash!
Learning Bash Terms and Basic Commands
Terms to learn
Command : A String the user inputs into the shell that runs a program
Directory (dir) : A file that contains refences to other files. You can pretty much call this a folder
Current Working dir : The dir that you are currently working in
Home Dir : An enviorment variable ( We will talk about enviormental var later) that represents a user base dir
Root Dir : A dir of the highest level
Commands learned in this lesson
pwd - prints the working directory. Tells you where are you at in the shell
whoami - tells you what user you are
ls - list the contents of the directory
cd <directory> - change directory
touch <filename> - creates a new file
mkdir <directoryname> - created a new dir
cat <filename> - displays the contents of a file
First Exercise, getting familiar with bash
First we will go to the online terminal Alice and Bob provided yesterday: TERMINAL
- Use
pwd
and note what dir you are in - Use
whoami
to see what user you are - Use
ls
to see what is in that dir - NOTE: You should see a combination of dir and files if not don’t worry we can take care of that shortly
- Use
mkdir bash
to created a new dir named bash - Type
ls
so you know see you have created a new dir named bash - Now we want to change our current working dir to bash try
cd bash
Note you can replacebash
with any dir if you want to go somewhere else - User
pwd
again to see if you are in the bash dir - Notice how there is a more dir attached to bash. Something like
User/bash
this is known as your absolute path./User
is the parent dir of/bash
. You might not see ‘User’, but in other bash terminals you will - Let’s go back to our parent dir. Try
cd ..
to change dir to the parent - Again use
pwd
(last time I promise) to verify you are back to the parent - Now that you know how to move around lets go back into the bash dir
- Let’s try making a new file type
touch newFile
to make a file called newFile - Use
ls
to see if the new files were created
Amazing! You have now learned how to create directories and files within a bash terminal!
Navigate the terminal to find flags!
Begin by entering the following commands in the home directory of the terminal…
git clone https://github.com/alexarnell/Bash_Tutorial.git
- Next go into the ‘Bash_Tutorial’ directory to start hunting for flags
Once you find a flag, input it in the answer box on Learnification.fun under the module Week of Cyber Day 2! Good Luck!
Total Number of Flags: 5
One More Flag!
Now that you can get around your shell we are going to teach you how to use some tools in your shell. In this lesson we what to create a directory and learn how to search files
Commands learned in this lesson
echo <string> - displays a line of text/string that is passed as an argument
rm <filename> - removes files
rm -R <directory name> - removes directories
grep <string> <filename> - searches a file for a particular string,
and displays all lines that contain that string
pid - prints the process ID of the shell
kill <pid> - kills a running process
clear - clears the terminal screen of text
Steps
- Use
pwd
and note what dir you are in - Use
echo
with a string as an argument to see how the command works - Use
mkdir
to create a directory named “Trash” - After creating the Trash directory, since it is infact trash, use
rm -R
to remove the directory - NOTE: Once you remove a file or directory, it is near impossible to get it back, so be careful!
- Find the file named “names.txt” and use the
cat
command to see the contents of the text file - Alot of names right? now since the file is taking up a large amount of our screen space, use
clear
so the names are removed from the screen. - Now there is a Flag hidden within “names.txt” yet instead of going through the 20,000 lines of code that the file contains, use
grep
to try and find the Flag!
Put the Flag in theanswer box on Learnification.fun under the module Week of Cyber Day 2
You Have Completed the Bash Lessons!
You can now consider yourself a bash specialist. Take this badge and put it on your website. If you use your skills, you can inspect the page and find the URL used to generate this image!