Bash (Bourne Again SHell) is used as the GNU shell, and is what you will most commonly use when you open a terminal.
You can use bash to navigate and modify your computer’s file system, execute programs, control jobs, and as a scripting language (so basically you can do everything).
Importantly, you can do many things in bash that are impossible to do just using your standard file system graphical browers. Also importantly, when you access remote machines, you will have no other choice than to use bash.
Here is basic use, which will assume you have opened a terminal. Comments follow a pound symbol (#). Open up a terminal and follow along.
pwd # print working directoryshould print your working directory. Usually this will start out as /home/user where user is your user name
whoami # prints your user namemkdir test # makes a directory called testls # lists files and directoriesYou will likely see a variety of files if you execute this in your home directory
cd test # changes working directory to testNow, if you execute pwd, you should see something like home/user/test. If you execute ls, you shouldn’t see anything (because there is nothing in test)
touch a.txt # creates empty file a.txtNow, try ls - what do you see?
mv a.txt b.txt # moves a.txt to b.txtNow what do you see with ls?
cp b.txt c.txt # makes a copy of b.txt and calls it c.txtNow what do you see with ls?
rm c.txt # deletes c.txttry using ls again.
echo 'print("hello world!")' >> hello.py # prints text to file hello.pytry using ls again.
Let’s see what is in hello.py
cat hello.py # prints contents of hello.pyAssuming you have python installed, you can run hello.py as a python script
python hello.pyThis should print hello world! to the terminal.
cd .. # goes up one directory levelNow if you pwd, you should be back at /home/user
rm -r test # removes test folder recursivelyWhat happens if you try cd test?
exit # closes terminal