working with a SHELL
Tags: bash, udacity, bertelsmanncloudscholarship
Published: 2020-02-18 11:39:46

---
title:working with a SHELL
published: true
description: notes from my udacity cloud pre-course
tags: bash, udacity, bertelsmann-cloud-scholarship
---

A shell is simply the outermost layer of an operating system. It's designed to provide a way for you to interact with the tools and services that your operating system provides. There are two types: **graphic shell** and **text shell**
*windows start menu*, *mac finder* are graphic shells where you interact with the operating system through things like windows and buttons. They are also called the GUI or Graphical User Interface.
Bash shell is a text shell used by unix systems by default (linux and mac). Its also called command line interface or CLI. Text shells allows ou to enter text commands to perform tasks instead of clicking on buttons

*echo*
to print something on the cli
![echo](https://dev-to-uploads.s3.amazonaws.com/i/wdhnwwa0lji3mvn6ia1u.png)<figcaption>echo</figcaption>


**variables**

to get the value assigned to a variable
![get the value assigned to a variable](https://dev-to-uploads.s3.amazonaws.com/i/jouk6hw9z9v6fxf3ajvs.png)<figcaption>get the value assigned to a variable</figcaption>
notice there's no spaces around '=' because bash deplays an error *x command not found*
In e.g Python, we could optionally include those spaces or not, and it worked fine either way. But in BASH, x=100 and x = 100 mean different things.

**navigating directories**
*ls* to list the content of the current directory in a shell
*ls name-of-direcotry* to list the content of another directory
*cd* change directory
*cd ..* go back one directory
*;* lets yo run two commands in one line
*ls ..* list the contents of parent directory
*pwd* print working directory
*..* parent directory
*.* current directory
*~* home directory


unix uses forward slash '/' to separate directories while windows cmd uses backslash '\' (wastemen)

**absolute v relative path**
*relative*
when you specify a path relative to the current location 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/up32d4pbqz6znu1nvrno.png)<figcaption>relative</figcaption>
*absolute*
when the path specified starts from the home directory or 'c' directory in windows
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3zod8jxllll8kb119hj7.png)<figcaption>absolute</figcaption>

**options**
options or flags turn on extra behaviour or extra features.

*ls -l*  -l stands for *long* .longer more detailed

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0aul6stpo2jbstbmlrbg.png)<figcaption>ls -l</figcaption>

*.pdf* all pdfs in a directory

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/awnuujh7rrilodzkqp6f.png)<figcaption>ls *.pdf*</figcaption>

*ls *poem* * lists all files whose names containes the word poem

**organising your files**
*mkdir* make a new directory
*mv* move file: **mv** *name of file* *destination you want it to go* eg **mv** *.epub /Documents/Books*

*bash commands cant be undone?* : they can but I pray I never have to is all I'm saying on this.

**downloading files from the web: curl**
*curl* to download files. *c url* ==> *see url*
*curl 'url'*
If you add the -L option to curl, it will first follow any redirects, and then download the file from wherever the redirects ultimately go.
*curl -L 'url'* displays source code to the actual url homepage to the terminal
*curl -o 'file name' -L 'url'* to save the source code to a file

**viewing files**
*cat* displays the full content of the file
*less* shows less of the file at once. you can use the arrow keys to navigate, 'q' to **quit**, '/' to **search**, 'b' or *up* arrow to **scroll up**, *spacebar* or *down* arrow to **scroll down**
*/zebra* searches for the word 'zebra'

**removing things**
*rm* remove file. deletes permanently. *-i* flag prompts you for every file you want to remove. 
*rmdir* remove directory. it only removes an empty directory