Unix Shell (Terminal)
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
- ls
- List current files and folders in directory
- ls -al
- List everything
- pwd
- Prints the current working directory
- cd <directory>
- Move to a specified directory eg “cd .. ” will take you one level up
- ifconfig
- Shows details on current network interfaces
- touch <file>
- Create <file>
- nano <file>
- Opens <file>in the nano text editor
- vim <file>
- Opens <file>in the vim text editor
- mkdir <dir>
- Creates the folder specified in <dir>
- sudo <cmd>
- executes the command <cmd>with sudo privileges
- raspi-config
- Opens up the Raspberry Pi Configuration Tool. Must be run as administrator
- man <command>
- Opens the manual for a particular command
- ssh
- Creates an SSH session.
- scp
- Secure copy.
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.
- Open .bash_profile:
nano ~/.bash_profile
- Add a line for the alias:
alias temp="vcgencmd measure_temp"
- Save and close the file
- Reload .bash_profile:
source ~/.bash_profile