You-Dont-Need-GUI/readme.md

502 lines
12 KiB
Markdown
Raw Normal View History

2016-09-17 18:54:40 +10:00
# You Don't Need GUI
2019-11-15 09:42:20 +11:00
[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/you-dont-need/GUI)
2021-08-13 10:32:36 +08:00
[中文版请看这里](./readme-zh_CN.md)
2016-09-17 18:54:40 +10:00
<details>
It's for noobs :)
</details>
2017-04-08 10:59:32 +10:00
<br />
2016-09-17 18:54:40 +10:00
Graphical user interfaces are super friendly to computer users. They were introduced in reaction to the perceived steep learning curve of command-line interfaces (CLIs).
![Xerox Star 8010 workstations](./Xerox_Star_8010_workstations.jpg)
2016-09-18 17:39:18 +10:00
However, they often require more resources, are less powerful and hard to automate via scripting.
2016-09-17 18:54:40 +10:00
2018-04-28 14:44:29 +09:30
As a computer expert, we want to be more efficient and do our jobs better. We know that command words may not be easily discoverable or mnemonic, so we try to list some common tasks that you might be tempted to do in GUI.
2016-09-17 18:54:40 +10:00
2016-09-18 10:42:02 +10:00
## Quick links
2017-11-17 17:35:58 +11:00
1. [copy a file](#copy-a-file)
1. [duplicate a file](#duplicate-a-file)
1. [copy a directory](#copy-a-directory)
1. [duplicate a directory](#duplicate-a-directory)
2017-11-17 17:35:58 +11:00
1. [move a file](#move-a-file)
1. [rename a file](#rename-a-file)
1. [move a directory](#move-a-directory)
1. [rename a directory](#rename-a-directory)
1. [merge directories](#merge-directories)
2017-11-17 17:35:58 +11:00
1. [create a new file](#create-a-new-file)
1. [create a new directory](#create-a-new-directory)
1. [show file/directory size](#show-filedirectory-size)
1. [show file/directory info](#show-filedirectory-info)
2017-11-17 17:35:58 +11:00
1. [open a file with the default program](#open-a-file-with-the-default-program)
1. [open a file in any application](#open-a-file-in-any-application)
1. [zip a directory](#zip-a-directory)
1. [unzip a directory](#unzip-a-directory)
2020-02-01 10:16:23 +11:00
1. [peek files in a zip file](#peek-files-in-a-zip-file)
2017-11-17 17:35:58 +11:00
1. [remove a file](#remove-a-file)
1. [remove a directory](#remove-a-directory)
1. [list directory contents](#list-directory-contents)
1. [tree view a directory and its subdirectories](#tree-view-a-directory-and-its-subdirectories)
2017-11-17 17:35:58 +11:00
1. [find a stale file](#find-a-stale-file)
1. [show a calendar](#show-a-calendar)
1. [find a future date](#find-a-future-date)
1. [use a calculator](#use-a-calculator)
2017-11-17 17:37:29 +11:00
1. [force quit a program](#force-quit-a-program)
1. [check server response](#check-server-response)
2018-11-06 13:29:41 +05:30
1. [view content of a file](#view-content-of-a-file)
1. [search for a text in a file](#search-for-a-text-in-a-file)
2021-08-10 14:42:47 +10:00
1. [search in all files in current working directory, quickly (entire disk in less than 15 minutes)](#search-in-all-files-in-current-working-directory-quickly-entire-disk-in-less-than-15-minutes)
2018-11-19 15:12:07 +11:00
1. [view an image](#view-an-image)
2018-12-13 01:19:58 +11:00
1. [show disk size](#show-disk-size)
2018-12-13 16:04:49 +11:00
1. [check performance of your computer](#check-performance-of-your-computer)
1. [know whether your computer is under load, and whether it's due to memory or CPU](#know-whether-your-computer-is-under-load-and-whether-its-due-to-memory-or-cpu)
1. [poweroff or reboot your computer](#poweroff-or-reboot-your-computer)
1. [locate USB drives](#locate-usb-drives)
1. [unmount USB drives](#unmount-usb-drives)
1. [format USB drives](#format-usb-drives)
1. [check USB format](#check-usb-format)
2018-11-14 11:20:28 +11:00
1. [Quick tips](#quick-tips)
2018-11-14 11:59:53 +11:00
1. [Hotkeys](#hotkeys)
2020-02-16 11:53:08 +11:00
1. [I can't remember these cryptic commands](#i-cant-remember-these-cryptic-commands)
2017-11-17 17:35:58 +11:00
## copy a file
2016-09-17 18:54:40 +10:00
2020-10-31 09:56:36 -04:00
**STOP DRAG AND DROPPING A FILE, OR CMD/CTRL + C, CMD/CTRL + V A FILE** :-1:
2016-09-17 18:54:40 +10:00
Copy `readme.txt` to the `documents` directory
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ cp readme.txt documents/
2016-09-17 18:54:40 +10:00
```
2017-11-17 17:35:58 +11:00
## duplicate a file
2016-09-17 20:22:03 +10:00
2018-11-22 15:06:08 +11:00
**STOP RIGHT CLICKING AND DUPLICATE A FILE** :-1:
2016-09-17 20:22:03 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ cp readme.txt readme.bak.txt
2016-09-17 20:22:03 +10:00
```
2020-02-23 15:21:35 -08:00
More advanced:
```shell
2020-02-25 14:58:51 -08:00
$ cp readme{,.bak}.txt
# Note: learn how the {} works with touch foo{1,2,3}.txt and see what happens.
2020-02-23 15:21:35 -08:00
```
2016-09-17 20:22:03 +10:00
## copy a directory
2016-09-17 18:54:40 +10:00
2020-10-31 09:56:36 -04:00
**STOP DRAG AND DROPPING A DIRECTORY, OR CMD/CTRL + C, CMD/CTRL + V A DIRECTORY** :-1:
2016-09-17 18:54:40 +10:00
Copy `myMusic` directory to the `myMedia` directory
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ cp -a myMusic myMedia/
2017-01-11 15:52:28 +11:00
# or
2020-02-25 14:58:51 -08:00
$ cp -a myMusic/ myMedia/myMusic/
2016-09-17 18:54:40 +10:00
```
## duplicate a directory
2016-09-17 20:16:35 +10:00
**STOP RIGHT CLICKING AND DUPLICATE A DIRECTORY** :-1:
2016-09-17 20:16:35 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ cp -a myMusic/ myMedia/
2017-01-11 15:56:51 +11:00
# or if `myMedia` folder doesn't exist
2020-02-25 14:58:51 -08:00
$ cp -a myMusic myMedia/
2016-09-17 20:16:35 +10:00
```
2017-11-17 17:35:58 +11:00
## move a file
2016-09-17 18:54:40 +10:00
2020-10-31 09:56:36 -04:00
**STOP DRAG AND DROPPING A FILE, OR CMD/CTRL + X, CMD/CTRL + V A FILE** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ mv readme.txt documents/
2016-09-17 18:54:40 +10:00
```
**Always** use a trailing slash when moving files, [for this reason](http://unix.stackexchange.com/a/50533).
2017-11-17 17:35:58 +11:00
## rename a file
2016-10-16 00:13:32 +02:00
2018-11-22 15:06:08 +11:00
**STOP RIGHT CLICKING AND RENAME A FILE** :-1:
2016-10-16 00:13:32 +02:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ mv readme.txt README.md
2016-10-16 00:13:32 +02:00
```
## move a directory
2016-09-17 18:54:40 +10:00
2020-10-31 09:56:36 -04:00
**STOP DRAG AND DROPPING A DIRECTORY, OR CMD/CTRL + X, CMD/CTRL + V A DIRECTORY** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ mv myMedia myMusic/
2017-01-11 15:52:28 +11:00
# or
2020-02-25 14:58:51 -08:00
$ mv myMedia/ myMusic/myMedia
```
## rename a directory
**STOP RIGHT CLICKING AND RENAME A DIRECTORY** :-1:
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ mv myMedia/ myMusic/
2016-09-17 18:54:40 +10:00
```
## merge directories
2017-02-25 08:26:01 +11:00
2020-10-31 09:56:36 -04:00
**STOP DRAG AND DROPPING TO MERGE DIRECTORIES** :-1:
2017-02-25 08:26:01 +11:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ rsync -a /images/ /images2/ # note: may over-write files with the same name, so be careful!
2017-02-25 08:26:01 +11:00
```
2017-11-17 17:35:58 +11:00
## create a new file
2016-09-17 18:54:40 +10:00
2018-11-22 15:06:08 +11:00
**STOP RIGHT CLICKING AND CREATE A NEW FILE** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ touch 'new file' # updates the file's access and modification timestamp if it already exists
2017-06-07 14:48:44 +10:00
# or
2020-02-25 14:58:51 -08:00
$ > 'new file' # note: erases the content if it already exists
```
2016-09-17 18:54:40 +10:00
## create a new directory
2016-09-17 18:54:40 +10:00
**STOP RIGHT CLICKING AND CREATE A NEW DIRECTORY** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ mkdir 'untitled folder'
2017-06-07 14:48:44 +10:00
# or
$ mkdir -p 'path/may/not/exist/untitled folder'
2016-09-17 18:54:40 +10:00
```
## show file/directory size
2016-09-17 18:54:40 +10:00
**STOP RIGHT CLICKING AND SHOW FILE/directory INFO** :-1:
2016-09-17 18:54:40 +10:00
2020-02-01 10:06:51 +11:00
```shell
2020-02-25 14:58:51 -08:00
$ du -sh node_modules/
2020-02-01 10:06:51 +11:00
```
## show file/directory info
2020-02-01 10:06:51 +11:00
**STOP RIGHT CLICKING AND SHOW FILE/DIRECTORY INFO** :-1:
2020-02-01 10:06:51 +11:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ stat -x readme.md # on macOS
$ stat readme.md # on Linux
```
2017-11-17 17:35:58 +11:00
## open a file with the default program
2016-09-17 18:54:40 +10:00
2018-11-22 15:06:08 +11:00
**STOP DOUBLE CLICKING ON A FILE** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ xdg-open file # on Linux
$ open file # on MacOS
2021-04-09 10:15:10 +02:00
$ start file # on Windows
2016-09-17 18:54:40 +10:00
```
## open a file in any application
**STOP RIGHT CLICKING AND OPEN WITH** :-1:
```shell
$ open -a appName file
```
## zip a directory
2016-09-17 18:54:40 +10:00
**STOP RIGHT CLICKING AND COMPRESS DIRECTORY** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ zip -r archive_name.zip folder_to_compress
2016-09-17 18:54:40 +10:00
```
## unzip a directory
2016-09-17 18:54:40 +10:00
**STOP RIGHT CLICKING AND UNCOMPRESS DIRECTORY** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ unzip archive_name.zip
2016-09-17 18:54:40 +10:00
```
2021-10-10 16:02:25 +08:00
## decompress files of any format
**STOP RIGHT CLICKING AND UNCOMPRESS DIRECTORY** :-1:
```shell
$ unar archive_name.zip
$ unar archive_name.7z
$ unar archive_name.rar
$ unar archive_name.ISO
$ unar archive_name.tar.gz
```
2020-02-01 10:16:23 +11:00
## peek files in a zip file
**STOP USING WinRAR** :-1:
```shell
2020-02-25 14:58:51 -08:00
$ zipinfo archive_name.zip
2020-02-01 10:19:54 +11:00
# or
2020-02-25 14:58:51 -08:00
$ unzip -l archive_name.zip
2020-02-01 10:16:23 +11:00
```
2021-10-10 16:02:25 +08:00
## peek files in a compress file of any format
**STOP USING WinRAR** :-1:
```shell
$ lsar -l archive_name.zip
$ lsar -l archive_name.7z
$ lsar -l archive_name.ISO
$ lsar -l archive_name.rar
$ lsar -l archive_name.tar.gz
```
2017-11-17 17:35:58 +11:00
## remove a file
2016-09-17 18:54:40 +10:00
2018-11-22 15:06:08 +11:00
**STOP RIGHT CLICKING AND DELETE A FILE PERMANENTLY** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ rm my_useless_file
2016-09-17 18:54:40 +10:00
```
2017-06-07 14:48:44 +10:00
2016-11-15 11:46:09 +11:00
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.
2016-09-17 18:54:40 +10:00
## remove a directory
2016-09-17 18:54:40 +10:00
**STOP RIGHT CLICKING AND DELETE A DIRECTORY PERMANENTLY** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ rm -r my_useless_folder
2016-09-17 18:54:40 +10:00
```
## list directory contents
2016-09-17 18:54:40 +10:00
2017-11-17 16:59:51 +11:00
**STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1:
2016-09-17 18:54:40 +10:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ 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.
2016-09-17 18:54:40 +10:00
```
2017-06-07 14:48:44 +10:00
## tree view a directory and its subdirectories
2016-09-17 18:54:40 +10:00
2017-11-17 16:59:51 +11:00
**STOP OPENING YOUR FINDER OR FILE EXPLORER** :-1:
2016-11-12 00:20:38 +00:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ tree # on Linux
$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' # on MacOS
2020-02-23 15:38:01 -08:00
# Note: install homebrew (https://brew.sh) to be able to use (some) Linux utilities such as tree.
2020-04-20 14:20:26 +10:00
# brew install tree
2016-11-12 00:20:38 +00:00
```
2017-06-07 14:48:44 +10:00
2017-11-17 17:35:58 +11:00
## find a stale file
2017-11-17 16:59:51 +11:00
**STOP USING YOUR FILE EXPLORER TO FIND A FILE** :-1:
Find all files modified more than 5 days ago
2017-06-07 14:48:44 +10:00
```shell
2021-04-09 10:30:20 -05:00
$ find my_folder -mtime +5
```
2017-11-17 17:35:58 +11:00
## show a calendar
2017-11-17 16:59:51 +11:00
**STOP LOOKING UP WHAT THIS MONTH LOOKS LIKE BY CALENDAR WIDGETS** :-1:
Display a text calendar
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ cal
```
Display selected month and year calendar
```shell
2020-02-25 14:58:51 -08:00
$ cal 11 2018
```
2017-11-17 17:35:58 +11:00
## find a future date
2017-11-17 16:59:51 +11:00
**STOP USING WEBAPPS TO CALCULATE FUTURE DATES** :-1:
What is todays date?
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ date +%m/%d/%Y
```
What about a week from now?
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ date -d "+7 days" # on Linux
$ date -j -v+7d # on MacOS
```
2017-11-17 17:35:58 +11:00
## use a calculator
2016-11-27 21:51:42 +11:00
2017-11-17 16:59:51 +11:00
**STOP USING CALCULATOR WIDGET** :-1:
2016-11-27 21:51:42 +11:00
2017-06-07 14:48:44 +10:00
```shell
$ bc -l
2016-11-27 21:51:42 +11:00
```
2017-11-17 17:35:58 +11:00
## force quit a program
2017-02-24 15:58:28 +11:00
2018-11-28 15:50:50 +11:00
**STOP CTRL + ALT + DELETE and choose the program to kill** :-1:
2017-02-24 15:58:28 +11:00
2017-06-07 14:48:44 +10:00
```shell
$ killall -9 program_name
2017-02-24 15:58:28 +11:00
```
## check server response
2018-11-22 15:06:08 +11:00
**STOP OPENING A BROWSER** :-1:
```shell
curl -i umair.surge.sh
# curl's -i (--include) option includes HTTP response headers in its output.
```
2018-11-06 13:29:41 +05:30
## view content of a file
2018-11-22 15:06:08 +11:00
**STOP DOUBLE CLICKING A FILE** :-1:
2018-11-06 13:29:41 +05:30
```shell
2020-02-25 14:58:51 -08:00
$ 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
2018-11-06 13:29:41 +05:30
```
## search for a text in a file
**STOP CMD/CTRL + F IN A FILE** :-1:
```shell
2020-02-25 14:58:51 -08:00
$ grep -i "Query" file.txt
2018-11-19 15:12:07 +11:00
```
2019-11-12 13:47:46 +11:00
![grep](./grep.jpg)
2021-08-10 14:42:47 +10:00
## search in all files in current working directory, quickly (entire disk in less than 15 minutes)
**STOP CMD/CTRL + F IN A DIRECTORY** :-1:
2020-09-30 13:47:10 -04:00
```shell
$ ripgrep -i "Query"
# brew install ripgrep
2020-09-30 13:47:10 -04:00
```
2018-11-19 15:12:07 +11:00
## view an image
**STOP USING PREVIEW** :-1:
```shell
2020-02-25 14:58:51 -08:00
$ imgcat image.png
2020-02-23 15:23:35 -08:00
# Note: requires iTerm2 terminal.
```
2018-12-13 01:19:58 +11:00
## show disk size
**STOP RIGHT CLICKING DISK ICON OR OPENING DISK UTILITY** :-1:
```shell
2020-02-25 14:58:51 -08:00
$ df -h
2018-12-13 01:19:58 +11:00
```
2018-12-13 16:04:49 +11:00
## check performance of your computer
**STOP OPENING YOUR ACTIVITY MONITOR OR TASK MANAGER** :-1:
```shell
2020-02-25 14:58:51 -08:00
$ top
2018-12-13 16:04:49 +11:00
```
## know whether your computer is under load, and whether it's due to memory or CPU
2020-09-30 13:47:10 -04:00
```shell
$ glances
# brew install glances
2020-09-30 13:47:10 -04:00
```
## poweroff or reboot your computer
This can be useful when you're patching a server that is acessed via SSH and you don't have a GUI.
```shell
# poweroff
sudo shutdown -h now
# reboot
sudo shutdown -r now
```
2020-09-30 13:47:10 -04:00
## locate USB drives
```shell
$ df
```
## unmount USB drives
```shell
$ sudo umount /dev/sdb1
```
## format USB drives
```shell
# FAT32
$ sudo mkfs.vfat /dev/sdb1
# NTFS
$ sudo mkfs.ntfs /dev/sdb1
# exFAT
$ sudo mkfs.exfat /dev/sdb1
```
## check USB format
```shell
sudo fsck /dev/sdb1
```
2018-11-14 11:20:28 +11:00
## Quick tips
![CLI tips](./cli_tips.jpg)
2018-11-14 11:59:53 +11:00
## Hotkeys
```
2018-11-19 15:07:28 +11:00
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
2018-11-14 11:59:53 +11:00
Ctrl + L Clears the Screen, similar to the clear command
2018-11-19 15:07:28 +11:00
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Lets you search through previously used commands
2018-11-19 15:07:28 +11:00
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Ctrl + F Move cursor forward one character
Ctrl + B Move cursor backward one character
2018-11-19 15:07:28 +11:00
Esc + T Swap the last two words before the cursor
Alt + T Same as Esc + T
2018-11-19 15:07:28 +11:00
Alt + F Move cursor forward one word on the current line
Alt + B Move cursor backward one word on the current line
Esc + F Same as Alt + F
Esc + B Same as Alt + B
Alt + . Paste the last word of the most recently command
Tab Auto-complete files and directory names
2018-11-14 11:59:53 +11:00
```
2020-02-16 11:52:35 +11:00
## I can't remember these cryptic commands
2018-11-14 11:59:53 +11:00
2020-02-16 11:52:35 +11:00
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.