##What is Bash?
Bash is a Unix shell used to interact with your operating system. It was created in 1989, making it 26 this year. What’s with the funny name? It stands for Bourne-again shell. It’s not a reference to Jason Bourne, but rather the Bourne Shell, a shell from 1977. It can do everything you can do with a GUI and more. You can copy files, create new folders (directories), search for files and search for information within files. You can also do all of this on other computers remotely from your computer.
It can also delete everything on your computer. Don’t type
rm -rf , it will delete everything on your computer
##Navigating in Bash
First off, open up Terminal. You’ll see a black window with white text, or perhaps different colors. Point is it will be nearly empty aside from a prompt. This is the bash prompt. The prompt itself might be a
$ or perhaps something else. Type
pwd this means print working directory. It will tell you where in the directory you are in the form of a path. Your path probably looks something like this
Users/NAME where NAME represents your username. The
/ symbol seperates different levels of the path
Users/John/websites/Scarf/Home is 5 levels. To navigate through the file structure using Bash we use
cd, change directory and the location of where we want to go.
~, called tilde, refers to your home directory.
.shows where you are right now in the file system, your current directory.
..brings you up a directory so if we’re currently in
Users/John/websites/Scarf/Homeand we type
cd ..now we’re in
Not sure what’s in your current directory? We can type
ls to list the files and folders in our current directory.
pwd are great for figuring out where you are and what else is there with you if you ever get lost in the file structure.
###More about paths
There are two kinds of paths: absolute paths and relative paths. Absolute paths start with
/ and begin at the root of your system, the highest folder in the hierarchy of folders. Relative paths are paths relative to your current location and do not start with
touchcreates new files. For example,
openopens the file using the default program for that file type
catas in concatenate displays a files contents inside the command prompt.
- tab completion, it’s incredibly useful. Hit tab to complete file names for example
cd g+ tab would return
cd giantreallylongfilenameif that file existed in that particular directory.
Flags are like modifiers. You can tack them onto a command and alter it slightly, they start with
-. For example, you can add on the
h flags to
ls (remember that means list) or all three together like this
ls -lah. This command would list all information in a human readable format. It’s the same as
ls -l -a -h but much easier to type.
Now that we know about flags, we can learn about hidden files. They start with
. and you need to use the
-a flag to see them.
Piping is really fascinating. You can use it to send the output of one command into another. For example
ls | head -3 will run the
ls command to list all the files in a directory. However, the output of
ls is being directed into
head -3 so only the first 3 results will display.