Difference between revisions of "Unix Shell (Terminal)"

From UCT EE Wiki
Jump to navigation Jump to search
 
Line 5: Line 5:
 
= Useful Commands =
 
= 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.
 
  
[[File:CMDOutput.png|frame|none|An example output of running some commands in the shell]]
+
{| class="wikitable"
 +
|- style="font-weight:bold;"
 +
! 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
 +
|}
 +
 
 +
 
 +
[[File:CMDOutput.png|frame|none|An example output of running some commands in the shell on a Raspberry Pi 3b+]]
  
 
= Aliases =  
 
= Aliases =  

Latest revision as of 10:55, 4 September 2020

Overview[edit]

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[edit]

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[edit]

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