Merge pull request #42 from ashleyharvey/issue-27

Prepend shell prompts.
This commit is contained in:
Robert Chang
2020-02-26 10:13:20 +11:00
committed by GitHub

View File

@@ -61,7 +61,7 @@ As a computer expert, we want to be more efficient and do our jobs better. We kn
Copy `readme.txt` to the `documents` folder Copy `readme.txt` to the `documents` folder
```shell ```shell
cp readme.txt documents/ $ cp readme.txt documents/
``` ```
## duplicate a file ## duplicate a file
@@ -69,13 +69,12 @@ cp readme.txt documents/
**STOP RIGHT CLICKING AND DUPLICATE A FILE** :-1: **STOP RIGHT CLICKING AND DUPLICATE A FILE** :-1:
```shell ```shell
cp readme.txt readme.bak.txt $ cp readme.txt readme.bak.txt
``` ```
More advanced: More advanced:
```shell ```shell
cp readme{,.bak}.txt $ cp readme{,.bak}.txt
# Note: learn how the {} works with touch foo{1,2,3}.txt and # Note: learn how the {} works with touch foo{1,2,3}.txt and see what happens.
see what happens.
``` ```
## copy a folder ## copy a folder
@@ -85,9 +84,9 @@ see what happens.
Copy `myMusic` folder to the `myMedia` folder Copy `myMusic` folder to the `myMedia` folder
```shell ```shell
cp -a myMusic myMedia/ $ cp -a myMusic myMedia/
# or # or
cp -a myMusic/ myMedia/myMusic/ $ cp -a myMusic/ myMedia/myMusic/
``` ```
## duplicate a folder ## duplicate a folder
@@ -95,9 +94,9 @@ cp -a myMusic/ myMedia/myMusic/
**STOP RIGHT CLICKING AND DUPLICATE A FOLDER** :-1: **STOP RIGHT CLICKING AND DUPLICATE A FOLDER** :-1:
```shell ```shell
cp -a myMusic/ myMedia/ $ cp -a myMusic/ myMedia/
# or if `myMedia` folder doesn't exist # or if `myMedia` folder doesn't exist
cp -a myMusic myMedia/ $ cp -a myMusic myMedia/
``` ```
## move a file ## move a file
@@ -105,7 +104,7 @@ cp -a myMusic myMedia/
**STOP DRAG AND DROPING A FILE, OR CMD/CTRL + X, CMD/CTRL + V A FILE** :-1: **STOP DRAG AND DROPING A FILE, OR CMD/CTRL + X, CMD/CTRL + V A FILE** :-1:
```shell ```shell
mv readme.txt documents/ $ mv readme.txt documents/
``` ```
**Always** use a trailing slash when moving files, [for this reason](http://unix.stackexchange.com/a/50533). **Always** use a trailing slash when moving files, [for this reason](http://unix.stackexchange.com/a/50533).
@@ -115,7 +114,7 @@ mv readme.txt documents/
**STOP RIGHT CLICKING AND RENAME A FILE** :-1: **STOP RIGHT CLICKING AND RENAME A FILE** :-1:
```shell ```shell
mv readme.txt README.md $ mv readme.txt README.md
``` ```
## move a folder ## move a folder
@@ -123,9 +122,9 @@ mv readme.txt README.md
**STOP DRAG AND DROPING A FOLDER, OR CMD/CTRL + X, CMD/CTRL + V A FOLDER** :-1: **STOP DRAG AND DROPING A FOLDER, OR CMD/CTRL + X, CMD/CTRL + V A FOLDER** :-1:
```shell ```shell
mv myMedia myMusic/ $ mv myMedia myMusic/
# or # or
mv myMedia/ myMusic/myMedia $ mv myMedia/ myMusic/myMedia
``` ```
## rename a folder ## rename a folder
@@ -133,7 +132,7 @@ mv myMedia/ myMusic/myMedia
**STOP RIGHT CLICKING AND RENAME A FOLDER** :-1: **STOP RIGHT CLICKING AND RENAME A FOLDER** :-1:
```shell ```shell
mv myMedia/ myMusic/ $ mv myMedia/ myMusic/
``` ```
## merge folders ## merge folders
@@ -141,7 +140,7 @@ mv myMedia/ myMusic/
**STOP DRAG AND DROPING TO MERGE FOLDERS** :-1: **STOP DRAG AND DROPING TO MERGE FOLDERS** :-1:
```shell ```shell
rsync -a /images/ /images2/ # note: may over-write files with the same name, so be careful! $ rsync -a /images/ /images2/ # note: may over-write files with the same name, so be careful!
``` ```
## create a new file ## create a new file
@@ -149,9 +148,9 @@ rsync -a /images/ /images2/ # note: may over-write files with the same name, so
**STOP RIGHT CLICKING AND CREATE A NEW FILE** :-1: **STOP RIGHT CLICKING AND CREATE A NEW FILE** :-1:
```shell ```shell
touch 'new file' # updates the file's access and modification timestamp if it already exists $ touch 'new file' # updates the file's access and modification timestamp if it already exists
# or # or
> 'new file' # note: erases the content if it already exists $ > 'new file' # note: erases the content if it already exists
``` ```
## create a new folder ## create a new folder
@@ -159,9 +158,9 @@ touch 'new file' # updates the file's access and modification timestamp if it
**STOP RIGHT CLICKING AND CREATE A NEW FOLDER** :-1: **STOP RIGHT CLICKING AND CREATE A NEW FOLDER** :-1:
```shell ```shell
mkdir 'untitled folder' $ mkdir 'untitled folder'
# or # or
mkdir -p 'path/may/not/exist/untitled\ folder' $ mkdir -p 'path/may/not/exist/untitled\ folder'
``` ```
## show file/folder size ## show file/folder size
@@ -169,7 +168,7 @@ mkdir -p 'path/may/not/exist/untitled\ folder'
**STOP RIGHT CLICKING AND SHOW FILE/FOLDER INFO** :-1: **STOP RIGHT CLICKING AND SHOW FILE/FOLDER INFO** :-1:
```shell ```shell
du -sh node_modules/ $ du -sh node_modules/
``` ```
## show file/folder info ## show file/folder info
@@ -177,8 +176,8 @@ du -sh node_modules/
**STOP RIGHT CLICKING AND SHOW FILE/FOLDER INFO** :-1: **STOP RIGHT CLICKING AND SHOW FILE/FOLDER INFO** :-1:
```shell ```shell
stat -x readme.md # on macOS $ stat -x readme.md # on macOS
stat readme.md # on Linux $ stat readme.md # on Linux
``` ```
## open a file with the default program ## open a file with the default program
@@ -186,8 +185,8 @@ stat readme.md # on Linux
**STOP DOUBLE CLICKING ON A FILE** :-1: **STOP DOUBLE CLICKING ON A FILE** :-1:
```shell ```shell
xdg-open file # on Linux $ xdg-open file # on Linux
open file # on MacOS $ open file # on MacOS
``` ```
## zip a folder ## zip a folder
@@ -195,7 +194,7 @@ open file # on MacOS
**STOP RIGHT CLICKING AND COMPRESS FOLDER** :-1: **STOP RIGHT CLICKING AND COMPRESS FOLDER** :-1:
```shell ```shell
zip -r archive_name.zip folder_to_compress $ zip -r archive_name.zip folder_to_compress
``` ```
## unzip a folder ## unzip a folder
@@ -203,7 +202,7 @@ zip -r archive_name.zip folder_to_compress
**STOP RIGHT CLICKING AND UNCOMPRESS FOLDER** :-1: **STOP RIGHT CLICKING AND UNCOMPRESS FOLDER** :-1:
```shell ```shell
unzip archive_name.zip $ unzip archive_name.zip
``` ```
## peek files in a zip file ## peek files in a zip file
@@ -211,9 +210,9 @@ unzip archive_name.zip
**STOP USING WinRAR** :-1: **STOP USING WinRAR** :-1:
```shell ```shell
zipinfo archive_name.zip $ zipinfo archive_name.zip
# or # or
unzip -l archive_name.zip $ unzip -l archive_name.zip
``` ```
## remove a file ## remove a file
@@ -221,7 +220,7 @@ unzip -l archive_name.zip
**STOP RIGHT CLICKING AND DELETE A FILE PERMANENTLY** :-1: **STOP RIGHT CLICKING AND DELETE A FILE PERMANENTLY** :-1:
```shell ```shell
rm my_useless_file $ rm my_useless_file
``` ```
IMPORTANT: The rm command deletes my_useless_file permanently, which is equivalent to move my_useless_file to Recycle Bin and hit Empty Recycle Bin. IMPORTANT: The rm command deletes my_useless_file permanently, which is equivalent to move my_useless_file to Recycle Bin and hit Empty Recycle Bin.
@@ -231,7 +230,7 @@ IMPORTANT: The rm command deletes my_useless_file permanently, which is equivale
**STOP RIGHT CLICKING AND DELETE A FOLDER PERMANENTLY** :-1: **STOP RIGHT CLICKING AND DELETE A FOLDER PERMANENTLY** :-1:
```shell ```shell
rm -r my_useless_folder $ rm -r my_useless_folder
``` ```
## list folder contents ## list folder contents
@@ -239,9 +238,9 @@ rm -r my_useless_folder
**STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1: **STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1:
```shell ```shell
ls my_folder # Simple $ ls my_folder # Simple
ls -la my_folder # -l: show in list format. -a: show all files, including hidden. -la combines those options. $ ls -la my_folder # -l: show in list format. -a: show all files, including hidden. -la combines those options.
ls -alrth my_folder # -r: reverse output. -t: sort by time (modified). -h: output human-readable sizes. $ ls -alrth my_folder # -r: reverse output. -t: sort by time (modified). -h: output human-readable sizes.
``` ```
## tree view a folder and its subfolders ## tree view a folder and its subfolders
@@ -249,8 +248,8 @@ ls -alrth my_folder # -r: reverse output. -t: sort by time (modified). -h: outpu
**STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1: **STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1:
```shell ```shell
tree # on Linux $ tree # on Linux
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' # on MacOS $ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' # on MacOS
# Note: install homebrew (https://brew.sh) to be able to use (some) Linux utilities such as tree. # Note: install homebrew (https://brew.sh) to be able to use (some) Linux utilities such as tree.
``` ```
@@ -261,7 +260,7 @@ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' # on MacOS
Find all files modified more than 5 days ago Find all files modified more than 5 days ago
```shell ```shell
find my_folder -mtime +5 $ find my_folder -mtime +5
``` ```
## show a calendar ## show a calendar
@@ -271,12 +270,12 @@ find my_folder -mtime +5
Display a text calendar Display a text calendar
```shell ```shell
cal $ cal
``` ```
Display selected month and year calendar Display selected month and year calendar
```shell ```shell
cal 11 2018 $ cal 11 2018
``` ```
## find a future date ## find a future date
@@ -286,14 +285,14 @@ cal 11 2018
What is todays date? What is todays date?
```shell ```shell
date +%m/%d/%Y $ date +%m/%d/%Y
``` ```
What about a week from now? What about a week from now?
```shell ```shell
date -d "+7 days" # on Linux $ date -d "+7 days" # on Linux
date -j -v+7d # on MacOS $ date -j -v+7d # on MacOS
``` ```
## use a calculator ## use a calculator
@@ -301,7 +300,7 @@ date -j -v+7d # on MacOS
**STOP USING CALCULATOR WIDGET** :-1: **STOP USING CALCULATOR WIDGET** :-1:
```shell ```shell
bc $ bc
``` ```
## force quit a program ## force quit a program
@@ -309,7 +308,7 @@ bc
**STOP CTRL + ALT + DELETE and choose the program to kill** :-1: **STOP CTRL + ALT + DELETE and choose the program to kill** :-1:
```shell ```shell
killall program_name $ killall program_name
``` ```
## check server response ## check server response
@@ -326,9 +325,9 @@ curl -i umair.surge.sh
**STOP DOUBLE CLICKING A FILE** :-1: **STOP DOUBLE CLICKING A FILE** :-1:
```shell ```shell
cat apps/settings.py $ cat apps/settings.py
# if the file is too big to fit on one page, you can send it to a 'pager' (less) which shows you one page at a time. # if the file is too big to fit on one page, you can send it to a 'pager' (less) which shows you one page at a time.
cat apps/settings.py | less $ cat apps/settings.py | less
``` ```
## search for a text ## search for a text
@@ -336,7 +335,7 @@ cat apps/settings.py | less
**STOP CMD/CTRL + F IN A FOLDER** :-1: **STOP CMD/CTRL + F IN A FOLDER** :-1:
```shell ```shell
grep -i "Query" file.txt $ grep -i "Query" file.txt
``` ```
![grep](./grep.jpg) ![grep](./grep.jpg)
@@ -346,7 +345,7 @@ grep -i "Query" file.txt
**STOP USING PREVIEW** :-1: **STOP USING PREVIEW** :-1:
```shell ```shell
imgcat image.png $ imgcat image.png
# Note: requires iTerm2 terminal. # Note: requires iTerm2 terminal.
``` ```
@@ -355,7 +354,7 @@ imgcat image.png
**STOP RIGHT CLICKING DISK ICON OR OPENING DISK UTILITY** :-1: **STOP RIGHT CLICKING DISK ICON OR OPENING DISK UTILITY** :-1:
```shell ```shell
df -h $ df -h
``` ```
## check performance of your computer ## check performance of your computer
@@ -363,7 +362,7 @@ df -h
**STOP OPENING YOUR ACTIVITY MONITOR OR TASK MANAGER** :-1: **STOP OPENING YOUR ACTIVITY MONITOR OR TASK MANAGER** :-1:
```shell ```shell
top $ top
``` ```
## Quick tips ## Quick tips