Basic Bash

Before this reading, follow this link and complete the experiential learning exercise “Terminus”.

In Terminus, you performed spells, interacted with items, and traveled to different locations. These are all translatable to Bash, with the spells as commands, items as files, and locations as directories.

Basic Bash commands

When a command takes in a file/directory name as an argument, you can write out a path instead of only file names in your current working directory. For example, if you are in ~, you can cd Desktop/JohnHeadland/Personal_Profile/ instead of doing cd Desktop, cd JohnHeadland, and then cd Personal_Profile.

Remember that case sensitivity matters! CD is not the same as cd. The same goes for file/directory names. “documents” is not the same as “Documents”.

Bash syntax

Syntax is the structure any language must follow. Even Bash has a general syntax its commands follow (although some commands have their own):

command -option [argument]

The command is the command that Bash executes. For example, cd, touch, mkdir

The option is written after a dash -. It allows you to undergo different ways of executing the command. For example, ls -a (the a option lists all files, including hidden ones whose names begin with a dot, .). You can use multiple options at once by directly appending them, a la: pacman -Syu (this uses the -S, -y, and -u options all at once).

The argument is whatever you’re passing into the command. For example, cd Desktop passes in the Desktop argument to be cd’d into.

Use spaces to separate commands, options, and arguments. Do NOT use spaces otherwise, such as for file or directory names, as they will be read as separate arguments. For example, touch My file will not create a single file called “My file”, it will touch two separate files named “My” and “file”.

The manual

If you don’t know how to use a command, read the manual for that command by typing in man command, where command is the name of the command you would like to read about. It tells you the syntax for that command with its possible options (and what they do) and what to pass in for arguments. If you try using a command and something doesn’t work, or you have a question, read the manual.

Autocompletion

When typing in arguments, you can use autocompletion with the Tab key. After typing in a unique amount of characters, if you press Tab, it automatically fills out the rest of the name for you! For example, if you’re in ~ and type in cd Doc and press Tab, the shell will automatically fill out the rest for you as cd Documents.


A quick crash course on file system navigation


Click here for the experiential learning exercise that puts what you’ve just learned into practice.

Click here to do the final experiential learning exercise of the module, “Treasure Hunt”, before moving on to Module 3, “Basic HTML”.