Update readme.md

Add "Go to table of contents"
This commit is contained in:
Talas
2021-10-10 15:21:44 +03:30
committed by GitHub
parent 7d43066fa0
commit 743eb1802c

View File

@@ -75,6 +75,8 @@ Copy `readme.txt` to the `documents` directory
```shell
$ cp readme.txt documents/
```
[Go to table of contents 🔼](#quick-links)
## duplicate a file
@@ -88,6 +90,8 @@ More advanced:
$ cp readme{,.bak}.txt
# Note: learn how the {} works with touch foo{1,2,3}.txt and see what happens.
```
[Go to table of contents 🔼](#quick-links)
## copy a directory
@@ -100,6 +104,8 @@ $ cp -a myMusic myMedia/
# or
$ cp -a myMusic/ myMedia/myMusic/
```
[Go to table of contents 🔼](#quick-links)
## duplicate a directory
@@ -110,6 +116,8 @@ $ cp -a myMusic/ myMedia/
# or if `myMedia` folder doesn't exist
$ cp -a myMusic myMedia/
```
[Go to table of contents 🔼](#quick-links)
## move a file
@@ -121,6 +129,8 @@ $ mv readme.txt documents/
**Always** use a trailing slash when moving files, [for this reason](http://unix.stackexchange.com/a/50533).
[Go to table of contents 🔼](#quick-links)
## rename a file
**STOP RIGHT CLICKING AND RENAME A FILE** :-1:
@@ -128,6 +138,8 @@ $ mv readme.txt documents/
```shell
$ mv readme.txt README.md
```
[Go to table of contents 🔼](#quick-links)
## move a directory
@@ -138,6 +150,8 @@ $ mv myMedia myMusic/
# or
$ mv myMedia/ myMusic/myMedia
```
[Go to table of contents 🔼](#quick-links)
## rename a directory
@@ -146,6 +160,8 @@ $ mv myMedia/ myMusic/myMedia
```shell
$ mv myMedia/ myMusic/
```
[Go to table of contents 🔼](#quick-links)
## merge directories
@@ -154,6 +170,8 @@ $ mv myMedia/ myMusic/
```shell
$ rsync -a /images/ /images2/ # note: may over-write files with the same name, so be careful!
```
[Go to table of contents 🔼](#quick-links)
## create a new file
@@ -164,6 +182,8 @@ $ touch 'new file' # updates the file's access and modification timestamp if
# or
$ > 'new file' # note: erases the content if it already exists
```
[Go to table of contents 🔼](#quick-links)
## create a new directory
@@ -174,6 +194,8 @@ $ mkdir 'untitled folder'
# or
$ mkdir -p 'path/may/not/exist/untitled folder'
```
[Go to table of contents 🔼](#quick-links)
## show file/directory size
@@ -182,6 +204,8 @@ $ mkdir -p 'path/may/not/exist/untitled folder'
```shell
$ du -sh node_modules/
```
[Go to table of contents 🔼](#quick-links)
## show file/directory info
@@ -191,6 +215,8 @@ $ du -sh node_modules/
$ stat -x readme.md # on macOS
$ stat readme.md # on Linux
```
[Go to table of contents 🔼](#quick-links)
## open a file with the default program
@@ -201,6 +227,8 @@ $ xdg-open file # on Linux
$ open file # on MacOS
$ start file # on Windows
```
[Go to table of contents 🔼](#quick-links)
## open a file in any application
@@ -209,6 +237,8 @@ $ start file # on Windows
```shell
$ open -a appName file
```
[Go to table of contents 🔼](#quick-links)
## zip a directory
@@ -217,6 +247,8 @@ $ open -a appName file
```shell
$ zip -r archive_name.zip folder_to_compress
```
[Go to table of contents 🔼](#quick-links)
## unzip a directory
@@ -225,6 +257,8 @@ $ zip -r archive_name.zip folder_to_compress
```shell
$ unzip archive_name.zip
```
[Go to table of contents 🔼](#quick-links)
## decompress files of any format
@@ -237,6 +271,8 @@ $ unar archive_name.rar
$ unar archive_name.ISO
$ unar archive_name.tar.gz
```
[Go to table of contents 🔼](#quick-links)
## peek files in a zip file
@@ -247,6 +283,8 @@ $ zipinfo archive_name.zip
# or
$ unzip -l archive_name.zip
```
[Go to table of contents 🔼](#quick-links)
## peek files in a compress file of any format
@@ -259,6 +297,8 @@ $ lsar -l archive_name.ISO
$ lsar -l archive_name.rar
$ lsar -l archive_name.tar.gz
```
[Go to table of contents 🔼](#quick-links)
## remove a file
@@ -270,6 +310,8 @@ $ 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.
[Go to table of contents 🔼](#quick-links)
## remove a directory
**STOP RIGHT CLICKING AND DELETE A DIRECTORY PERMANENTLY** :-1:
@@ -277,6 +319,8 @@ $ rm my_useless_file
```shell
$ rm -r my_useless_folder
```
[Go to table of contents 🔼](#quick-links)
## remove all files of certain criteria
@@ -286,6 +330,8 @@ find . -name "*.bak" -type f -delete
**IMPORTANT**: run `find . -name "*.bak" -type f` first to see exactly which files you will remove.
[Go to table of contents 🔼](#quick-links)
## list directory contents
**STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1:
@@ -295,6 +341,8 @@ $ ls my_folder # Simple
$ 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.
```
[Go to table of contents 🔼](#quick-links)
## tree view a directory and its subdirectories
@@ -306,6 +354,8 @@ $ 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.
# brew install tree
```
[Go to table of contents 🔼](#quick-links)
## find a stale file
@@ -316,6 +366,8 @@ Find all files modified more than 5 days ago
```shell
$ find my_folder -mtime +5
```
[Go to table of contents 🔼](#quick-links)
## show a calendar
@@ -331,6 +383,8 @@ Display selected month and year calendar
```shell
$ cal 11 2018
```
[Go to table of contents 🔼](#quick-links)
## find a future date
@@ -348,6 +402,8 @@ What about a week from now?
$ date -d "+7 days" # on Linux
$ date -j -v+7d # on MacOS
```
[Go to table of contents 🔼](#quick-links)
## use a calculator
@@ -356,6 +412,8 @@ $ date -j -v+7d # on MacOS
```shell
$ bc -l
```
[Go to table of contents 🔼](#quick-links)
## force quit a program
@@ -364,6 +422,8 @@ $ bc -l
```shell
$ killall -9 program_name
```
[Go to table of contents 🔼](#quick-links)
## check server response
@@ -373,6 +433,8 @@ $ killall -9 program_name
curl -i umair.surge.sh
# curl's -i (--include) option includes HTTP response headers in its output.
```
[Go to table of contents 🔼](#quick-links)
## view content of a file
@@ -383,6 +445,8 @@ $ cat apps/settings.py
# if the file is too big to fit on one page, you can use a 'pager' (less) which shows you one page at a time.
$ less apps/settings.py
```
[Go to table of contents 🔼](#quick-links)
## search for a text in a file
@@ -391,6 +455,8 @@ $ less apps/settings.py
```shell
$ grep -i "Query" file.txt
```
[Go to table of contents 🔼](#quick-links)
![grep](./grep.jpg)
@@ -402,6 +468,8 @@ $ grep -i "Query" file.txt
$ ripgrep -i "Query"
# brew install ripgrep
```
[Go to table of contents 🔼](#quick-links)
## view an image
@@ -411,6 +479,8 @@ $ ripgrep -i "Query"
$ imgcat image.png
# Note: requires iTerm2 terminal.
```
[Go to table of contents 🔼](#quick-links)
## show disk size
@@ -419,6 +489,8 @@ $ imgcat image.png
```shell
$ df -h
```
[Go to table of contents 🔼](#quick-links)
## check performance of your computer
@@ -427,6 +499,8 @@ $ df -h
```shell
$ top
```
[Go to table of contents 🔼](#quick-links)
## know whether your computer is under load, and whether it's due to memory or CPU
@@ -434,6 +508,8 @@ $ top
$ glances
# brew install glances
```
[Go to table of contents 🔼](#quick-links)
## poweroff or reboot your computer
@@ -445,18 +521,24 @@ sudo shutdown -h now
# reboot
sudo shutdown -r now
```
[Go to table of contents 🔼](#quick-links)
## locate USB drives
```shell
$ df
```
[Go to table of contents 🔼](#quick-links)
## unmount USB drives
```shell
$ sudo umount /dev/sdb1
```
[Go to table of contents 🔼](#quick-links)
## format USB drives
@@ -468,12 +550,16 @@ $ sudo mkfs.ntfs /dev/sdb1
# exFAT
$ sudo mkfs.exfat /dev/sdb1
```
[Go to table of contents 🔼](#quick-links)
## check USB format
```shell
sudo fsck /dev/sdb1
```
[Go to table of contents 🔼](#quick-links)
## run command on all files of a directory
@@ -482,11 +568,15 @@ sudo fsck /dev/sdb1
```shell
for FILE in *; do echo $FILE; done
```
[Go to table of contents 🔼](#quick-links)
## Quick tips
![CLI tips](./cli_tips.jpg)
[Go to table of contents 🔼](#quick-links)
## Hotkeys
```
@@ -513,7 +603,11 @@ Esc + B Same as Alt + B
Alt + . Paste the last word of the most recently command
Tab Auto-complete files and directory names
```
[Go to table of contents 🔼](#quick-links)
## I can't remember these cryptic commands
You can always google or `man` the commands you are not familiar with. Or, checkout [tldr](https://github.com/tldr-pages/tldr), a collection of simplified and community-driven man pages.
[Go to table of contents 🔼](#quick-links)