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 )
2021-06-23 15:45:17 +08:00
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 )
2020-02-25 15:39:53 -08:00
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 )
2020-02-25 15:39:53 -08:00
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 )
2020-02-25 15:39:53 -08:00
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 )
2021-10-02 18:05:24 +10:00
1. [open a file in any application ](#open-a-file-in-any-application )
2020-02-25 15:39:53 -08:00
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 )
2020-02-25 15:39:53 -08:00
1. [remove a directory ](#remove-a-directory )
2021-10-10 19:12:13 +11:00
1. [remove all files of certain criteria ](#remove-all-files-of-certain-criteria )
2020-02-25 15:39:53 -08:00
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 )
2018-11-06 14:00:32 +05:30
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 )
2021-08-10 14:39:55 +10:00
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 )
2022-12-14 22:22:14 +11:00
1. [check cpu usage, processes and RAM ](#check-cpu-usage-processes-and-ram )
2021-08-10 14:39:55 +10:00
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 )
2021-10-02 17:45:36 +10:00
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 )
2021-10-10 19:03:26 +11:00
1. [run command on all files of a directory ](#run-command-on-all-files-of-a-directory )
2022-12-14 22:22:14 +11:00
1. [check network connectivity to a remote address and port ](#check-network-connectivity-to-a-remote-address-and-port )
1. [check DNS config of a domain ](#check-dns-config-of-a-domain )
1. [check the ownership and registration of a domain ](#check-the-ownership-and-registration-of-a-domain )
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
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 20:22:03 +10:00
2020-02-25 15:39:53 -08: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
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08:00
## duplicate a directory
2016-09-17 20:16:35 +10:00
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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
```
2016-11-15 19:55:34 -03:00
**Always** use a trailing slash when moving files, [for this reason ](http://unix.stackexchange.com/a/50533 ).
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-10-16 00:13:32 +02:00
2020-02-25 15:39:53 -08: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
2017-01-11 15:08:13 +11:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2017-01-11 15:08:13 +11:00
2020-02-25 15:39:53 -08:00
## rename a directory
2017-01-11 15:08:13 +11:00
2020-02-25 15:39:53 -08:00
**STOP RIGHT CLICKING AND RENAME A DIRECTORY** :-1:
2017-01-11 15:08:13 +11:00
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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-11-13 21:39:19 -02:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08:00
## create a new directory
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08: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
2021-04-09 10:26:38 -05:00
$ mkdir -p 'path/may/not/exist/untitled folder'
2016-09-17 18:54:40 +10:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08:00
## show file/directory size
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2020-02-01 10:06:51 +11:00
2020-02-25 15:39:53 -08:00
## show file/directory info
2020-02-01 10:06:51 +11:00
2020-02-25 15:39:53 -08: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
2016-11-11 14:24:09 +05:30
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-11-11 14:24:09 +05:30
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2021-10-02 18:05:24 +10:00
## open a file in any application
**STOP RIGHT CLICKING AND OPEN WITH** :-1:
```shell
$ open -a appName file
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-02 18:05:24 +10:00
2020-02-25 15:39:53 -08:00
## zip a directory
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08:00
## unzip a directory
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08: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 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-10 16:02:25 +08:00
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 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-10 16:02:25 +08:00
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
2021-10-10 19:13:46 +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
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2020-02-25 15:39:53 -08:00
## remove a directory
2016-09-17 18:54:40 +10:00
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-09-17 18:54:40 +10:00
2021-10-10 19:12:13 +11:00
## remove all files of certain criteria
```shell
2021-10-20 23:56:51 +01:00
$ find . -name "*.bak" -type f -delete
2021-10-10 19:12:13 +11:00
```
**IMPORTANT**: run `find . -name "*.bak" -type f` first to see exactly which files you will remove.
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2017-06-07 14:48:44 +10:00
2020-02-25 15:39:53 -08: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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2017-06-07 14:48:44 +10:00
2017-11-17 17:35:58 +11:00
## find a stale file
2016-11-11 16:54:08 -06:00
2017-11-17 16:59:51 +11:00
**STOP USING YOUR FILE EXPLORER TO FIND A FILE** :-1:
2016-11-11 16:54:08 -06:00
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
2016-11-11 16:54:08 -06:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-11-11 16:54:08 -06:00
2017-11-17 17:35:58 +11:00
## show a calendar
2016-11-11 16:54:08 -06:00
2017-11-17 16:59:51 +11:00
**STOP LOOKING UP WHAT THIS MONTH LOOKS LIKE BY CALENDAR WIDGETS** :-1:
2016-11-11 16:54:08 -06:00
2016-11-11 17:43:17 -06:00
Display a text calendar
2016-11-11 16:54:08 -06:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ cal
2016-11-11 16:54:08 -06:00
```
2018-10-02 21:12:45 -03:00
Display selected month and year calendar
```shell
2020-02-25 14:58:51 -08:00
$ cal 11 2018
2018-10-02 21:12:45 -03:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-11-11 16:54:08 -06:00
2017-11-17 17:35:58 +11:00
## find a future date
2016-11-11 17:43:17 -06:00
2017-11-17 16:59:51 +11:00
**STOP USING WEBAPPS TO CALCULATE FUTURE DATES** :-1:
2016-11-11 17:43:17 -06:00
2023-02-03 13:30:44 +08:00
What is today's date?
2016-11-11 17:43:17 -06:00
2017-06-07 14:48:44 +10:00
```shell
2020-02-25 14:58:51 -08:00
$ date +%m/%d/%Y
2016-11-11 17:43:17 -06:00
```
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
2016-11-11 17:43:17 -06:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2016-11-11 17:43:17 -06:00
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
add -l to bc
-l makes bc works with float numbers, which are expected behavior for most users:
```
~ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3/2
1
~ bc -l
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3/2
1.50000000000000000000
```
2021-04-08 21:37:16 -07:00
$ bc -l
2016-11-27 21:51:42 +11:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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
2021-04-08 21:21:52 -07:00
$ killall -9 program_name
2017-02-24 15:58:28 +11:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2017-02-24 15:58:28 +11:00
2018-11-06 14:00:32 +05:30
## check server response
2018-11-22 15:06:08 +11:00
**STOP OPENING A BROWSER** :-1:
2018-11-06 14:00:32 +05:30
```shell
2021-10-20 23:56:51 +01:00
$ curl -i umair.surge.sh
2020-02-25 14:56:06 -08:00
# curl's -i (--include) option includes HTTP response headers in its output.
2018-11-06 14:00:32 +05:30
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2018-11-06 14:00:32 +05:30
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
2020-10-03 11:09:17 +08:00
# 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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2018-11-06 13:29:41 +05:30
2021-08-10 14:39:55 +10:00
## search for a text in a file
2018-10-25 11:58:42 +05:30
2021-08-10 14:39:55 +10:00
**STOP CMD/CTRL + F IN A FILE** :-1:
2018-10-25 11:58:42 +05:30
```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-10-10 15:27:06 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-08-10 14:42:47 +10:00
## search in all files in current working directory, quickly (entire disk in less than 15 minutes)
2021-08-10 14:39:55 +10:00
**STOP CMD/CTRL + F IN A DIRECTORY** :-1:
2020-09-30 13:47:10 -04:00
```shell
$ ripgrep -i "Query"
2021-08-10 14:39:55 +10:00
# brew install ripgrep
2020-09-30 13:47:10 -04:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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-10-25 11:58:42 +05:30
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2018-10-25 11:58:42 +05:30
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
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2018-12-13 01:19:58 +11:00
2022-12-14 22:22:14 +11:00
## check cpu usage, processes and RAM
2018-12-13 16:04:49 +11:00
**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
```
2022-12-14 22:22:14 +11:00
if you want some more details:
```shell
$ htop
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2018-12-13 16:04:49 +11:00
2021-08-10 14:39:55 +10: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
2021-08-10 14:39:55 +10:00
# brew install glances
2020-09-30 13:47:10 -04:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2020-09-30 13:47:10 -04:00
2021-10-02 17:45:36 +10:00
## poweroff or reboot your computer
2021-08-10 14:39:55 +10:00
2023-02-03 13:30:44 +08:00
This can be useful when you're patching a server that is accessed via SSH and you don't have a GUI.
2021-08-10 14:39:55 +10:00
```shell
# poweroff
2021-10-20 23:56:51 +01:00
$ sudo shutdown -h now
2021-08-10 14:39:55 +10:00
# reboot
2021-10-20 23:56:51 +01:00
$ sudo shutdown -r now
2021-08-10 14:39:55 +10:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2020-09-30 13:47:10 -04:00
2021-10-02 17:45:36 +10:00
## locate USB drives
```shell
$ df
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-02 17:45:36 +10:00
## unmount USB drives
```shell
$ sudo umount /dev/sdb1
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-02 17:45:36 +10:00
## format USB drives
```shell
# FAT32
$ sudo mkfs.vfat /dev/sdb1
# NTFS
$ sudo mkfs.ntfs /dev/sdb1
# exFAT
$ sudo mkfs.exfat /dev/sdb1
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-02 17:45:36 +10:00
## check USB format
```shell
2021-10-20 23:56:51 +01:00
$ sudo fsck /dev/sdb1
2021-10-02 17:45:36 +10:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2021-10-02 17:45:36 +10:00
2021-10-10 19:03:26 +11:00
## run command on all files of a directory
**STOP CLICKING THE FILES ONE BY ONE** :-1:
```shell
2021-10-20 23:56:51 +01:00
$ for FILE in *; do echo $FILE; done
2021-10-10 19:03:26 +11:00
```
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2022-12-14 22:22:14 +11:00
## check network connectivity to a remote address and port
**STOP USING NETWORK UTILITY**
```shell
$ nc -vz www.google.com 443
$ nc -vz 1.1.1.1 53
```
[Go to table of contents 🔼 ](#quick-links )
## check DNS config of a domain
**STOP USING NETWORK UTILITY**
```shell
$ dig www.google.com
```
[Go to table of contents 🔼 ](#quick-links )
## check the ownership and registration of a domain
**STOP USING NETWORK UTILITY AND THE WEBSITE OF DOMAIN REGISTRATION PROVIDERS**
```shell
$ whois www.google.com
```
[Go to table of contents 🔼 ](#quick-links )
2021-10-10 19:03:26 +11:00
2018-11-14 11:20:28 +11:00
## Quick tips
![CLI tips ](./cli_tips.jpg )
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
2018-11-14 11:59:53 +11:00
## Hotkeys
2023-12-05 20:59:55 +01:00
| Hotkey | Description |
|----------|-------------|
| < kbd > Ctrl< / kbd > +< kbd > A< / kbd > | Go to the beginning of the line you are currently typing on |
| < kbd > Ctrl< / kbd > +< kbd > E< / kbd > | Go to the end of the line you are currently typing on |
| < kbd > Ctrl< / kbd > +< kbd > L< / kbd > | Clears the Screen, similar to the clear command |
| < kbd > Ctrl< / kbd > +< kbd > U< / kbd > | Clears the line before the cursor position. If you are at the end of the line, clears the entire line. |
| < kbd > Ctrl< / kbd > +< kbd > H< / kbd > | Same as backspace |
| < kbd > Ctrl< / kbd > +< kbd > R< / kbd > | Lets you search through previously used commands |
| < kbd > Ctrl< / kbd > +< kbd > C< / kbd > | Kill whatever you are running |
| < kbd > Ctrl< / kbd > +< kbd > D< / kbd > | Exit the current shell |
| < kbd > Ctrl< / kbd > +< kbd > Z< / kbd > | Puts whatever you are running into a suspended background process. fg restores it. |
| < kbd > Ctrl< / kbd > +< kbd > W< / kbd > | Delete the word before the cursor |
| < kbd > Ctrl< / kbd > +< kbd > K< / kbd > | Clear the line after the cursor |
| < kbd > Ctrl< / kbd > +< kbd > T< / kbd > | Swap the last two characters before the cursor |
| < kbd > Ctrl< / kbd > +< kbd > F< / kbd > | Move cursor forward one character |
| < kbd > Ctrl< / kbd > +< kbd > B< / kbd > | Move cursor backward one character |
| < kbd > Esc< / kbd > +< kbd > T< / kbd > | Swap the last two words before the cursor |
| < kbd > Alt< / kbd > +< kbd > T< / kbd > | Same as < kbd > Esc< / kbd > + < kbd > T< / kbd > |
| < kbd > Alt< / kbd > +< kbd > F< / kbd > | Move cursor forward one word on the current line |
| < kbd > Alt< / kbd > +< kbd > B< / kbd > | Move cursor backward one word on the current line |
| < kbd > Esc< / kbd > +< kbd > F< / kbd > | Same as < kbd > Alt< / kbd > + < kbd > F< / kbd > |
| < kbd > Esc< / kbd > +< kbd > B< / kbd > | Same as < kbd > Alt< / kbd > + < kbd > B< / kbd > |
| < kbd > Alt< / kbd > +< kbd > .< / kbd > | Paste the last word of the most recently command |
| < kbd > Tab< / kbd > | Auto-complete files and directory names |
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )
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.
2021-10-10 15:21:44 +03:30
[Go to table of contents 🔼 ](#quick-links )