Unix Shell (Terminal)

From UCT EE Wiki
Revision as of 10:55, 4 September 2020 by CRNKEE002 (talk | contribs) (→‎Useful Commands)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Being able to use the Unix Shell and terminal commands is an invaluable skill, and a requirement for this course. Follow this software carpentry link for more learning resources.

Useful Commands

Command Description
ls List current files and folders in directory
ls -al List details about everything
pwd Print current (working) directory
cd <directory> Move into the specified directory
cd .. Move up one directory
ifconfig Shows details on current network interfaces (requires package net-tools to be installed)
touch <file> Creates a file. For example "touch.txt" will create a file in the directory you are in.
nano <file> Opens the specified file in nano, a text editor
mkdir <directory> Creates a directory
sudo <command> Executes <command> with super user privilages
man <command> Opens the user manual relating to the specified command


An example output of running some commands in the shell on a Raspberry Pi 3b+

Aliases

Sometimes you may want to run long or complex commands. In this scenario, it can be useful to create an alias. This allows you to rename a command (or chain of commands) to an easier to type or remember command. An alias is a sort of shortcut, and it can be temporary or permanent.

For example, the command vcgencmd measure_temp on a Raspberry Pi will return the core temperature. However, this can be a tricky command to remember. So, let's create an alias. For a temporary alias, you can just enter in alias temp="vcgencmd measure_temp" on the command line. This will allow you to type "temp" and get the temperature. However, this alias will expire when you end your session (log out). To create a permanent alias, the following is required.

  1. Open .bash_profile: nano ~/.bash_profile
  2. Add a line for the alias: alias temp="vcgencmd measure_temp"
  3. Save and close the file
  4. Reload .bash_profile: source ~/.bash_profile