Difference between revisions of "Unix Shell (Terminal)"
m (CRNKEE002 moved page Unix Shell to Unix Shell (Terminal): Elaboration & Easier search) |
|||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
= Useful Commands = | = Useful Commands = | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | {| 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]] | + | |
+ | [[File:CMDOutput.png|frame|none|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 <code>vcgencmd measure_temp</code> 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 <code>alias temp="vcgencmd measure_temp"</code> 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: <code>nano ~/.bash_profile</code> | ||
+ | # Add a line for the alias: <code>alias temp="vcgencmd measure_temp"</code> | ||
+ | # Save and close the file | ||
+ | # Reload .bash_profile: <code>source ~/.bash_profile</code> |
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 |
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.
- 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