And cheat sheet!
https://docs.google.com/presentation/d/1OXMbABYQYuiq8tqymXsbSQiFyhNJblwqEb-XeWrXqjk/edit?usp=sharing
Given an example bash command:
root@hal9000:/tmp$ ls --all -lh /home
The following parts mean the following things:
-
root
is the username. -
hal900
is the "hostname" (the computer you are on). -
/tmp
is the current directory. -
ls
is an example executable (seels
). -
--all
is a long option. -
-lh
is a collection of short options, in this casel
andh
. -
/home
is a parameter, in this case, a directory thatls
will be run on.
Learn how a given program works.
eg.
man ls
Will tell you everything about how ls
works.
Change the current directory you are in!
cd ..
can be used to go to the parent directory.
List everything in a given directory.
eg.
ls /home
Will list everything in the /home
directory.
Remove the given file!
eg.
rm my_file.txt
Will delete my_file.txt
!
Don't forget that you can use the -r
option to
delete a directory!
Make a directory
eg.
mkdir my_directory
Will make a directory called my_directory
!
Make a file
eg.
touch my_file.txt
Will make a file called my_file.txt
!
You could then edit it with nano
, for example!
This program can be used to securely connect to a remote shell, on another computer. Even across the internet!
eg. If you are a Cambridge student, you get access to your own space on University machines!
ssh crsid@linux.ds.cam.ac.uk
Print all the arguments as text!
eg.
echo this is some text
View the contents of a given file.
eg.
cat my_file.txt
To show the contents of my_file.txt
.
A helpful little text editor.
Use Ctrl+X to quit!
eg.
nano my_file.txt
To edit my_file.txt
.
Search within the file contents.
eg.
grep toby my_file.txt
This example will find all lines in my_file.txt
containing the word toby
.
This is really good for finding things in program logs!
Change user.
eg.
su doctor_strange
Try to change to the user 'doctor strange'
Perform commands which need elevated privileges!
eg.
sudo apt install blender
Will install blender (on Debian and Ubuntu).
Lot's of executable programs in bash (and other terminals) will take options which are prepended by a -
or --
. These are useful if you want programs to do slightly different things that the designers of the program have added to them. In order to see what options a program will take, you can always use man
eg. --all
, these options are written out as English words and are very readable, but may require a lot of typing.
eg. -a
, these options are quick and easy to type, but remembering what they are can be a bit tricky sometimes. However, a nice feature is that you can list a bunch of them together. Eg. -la
means, "Do option -a
AND option l
". However,
this is by convention, and some programs will require options to be separate parameters, even in short form.
Close the current program!
Alternatives are Ctrl+D, Ctrl+Z, quit(), and exit()! Unfortunately, what will work varies by program. :'(
Copy the selected piece of text!
Paste the piece of text in the clipboard!
Choose a recent command.
Autocomplete what you currently have.
-
/etc
(system configuration files) -
/tmp
(temporary storage area) -
/home
(home directories) -
/usr/bin
(most programs live here)
Lots of programs read things in from something known as the "standard input". Furthermore, many programs will give output to something known as the "standard output" or "standard error", which in the most common case will be your shell.
However, you can chain programs together, by "piping" their outputs to the inputs of other programs. (Imagine trying to do this with graphical programs!)
Here are some of the operators you can use for piping:
The most common one - this operator will take the output of the command to the left of it, and feed it to the input of the command to its right.
eg.
cat my_file.txt | grep hello | grep goodbye
This examples will cause the output of cat my_file.txt
to flow to the input of grep hello
whos output will go to grep goodbye
. The effect of this is that we will see ever line in the file my_file.txt
that has both hello
and goodbye
in it.
Write the standard output of the command on the left to the file on the right.
Append the standard output of the command on the left to the file in the right.
Send the contents of the file on the right to the input of the command on the left.
Go to http://overthewire.org/wargames/bandit/ Level 0: ssh bandit0@bandit.labs.overthewire.org (password: bandit0)
For practice, have a look there!
What is covered here is exceptionally brief, please look here for some of the topics mentioned briefly in the presentation which weren't elaborated on!