You-Dont-Need-GUI/readme.md
2020-02-25 15:10:19 -08:00

9.1 KiB
Raw Blame History

You Don't Need GUI

Join the community on Spectrum

It's for noobs :)

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

However, they often require more resources, are less powerful and hard to automate via scripting.

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.

  1. copy a file
  2. duplicate a file
  3. copy a folder
  4. duplicate a folder
  5. move a file
  6. rename a file
  7. move a folder
  8. rename a folder
  9. merge folders
  10. create a new file
  11. create a new folder
  12. show file/folder size
  13. show file/folder info
  14. open a file with the default program
  15. zip a folder
  16. unzip a folder
  17. peek files in a zip file
  18. remove a file
  19. remove a folder
  20. list folder contents
  21. tree view a folder and its subfolders
  22. find a stale file
  23. show a calendar
  24. find a future date
  25. use a calculator
  26. force quit a program
  27. check server response
  28. view content of a file
  29. search for a text
  30. view an image
  31. show disk size
  32. check performance of your computer
  33. Quick tips
  34. Hotkeys
  35. I can't remember these cryptic commands

copy a file

STOP DRAG AND DROPING A FILE, OR CMD/CTRL + C, CMD/CTRL + V A FILE 👎

Copy readme.txt to the documents folder

$ cp readme.txt documents/

duplicate a file

STOP RIGHT CLICKING AND DUPLICATE A FILE 👎

$ cp readme.txt readme.bak.txt

More advanced:

$ cp readme{,.bak}.txt
# Note: learn how the {} works with touch foo{1,2,3}.txt and see what happens.

copy a folder

STOP DRAG AND DROPING A FOLDER, OR CMD/CTRL + C, CMD/CTRL + V A FOLDER 👎

Copy myMusic folder to the myMedia folder

$ cp -a myMusic myMedia/
# or
$ cp -a myMusic/ myMedia/myMusic/

duplicate a folder

STOP RIGHT CLICKING AND DUPLICATE A FOLDER 👎

$ cp -a myMusic/ myMedia/
# or if `myMedia` folder doesn't exist
$ cp -a myMusic myMedia/

move a file

STOP DRAG AND DROPING A FILE, OR CMD/CTRL + X, CMD/CTRL + V A FILE 👎

$ mv readme.txt documents/

Always use a trailing slash when moving files, for this reason.

rename a file

STOP RIGHT CLICKING AND RENAME A FILE 👎

$ mv readme.txt README.md

move a folder

STOP DRAG AND DROPING A FOLDER, OR CMD/CTRL + X, CMD/CTRL + V A FOLDER 👎

$ mv myMedia myMusic/
# or
$ mv myMedia/ myMusic/myMedia

rename a folder

STOP RIGHT CLICKING AND RENAME A FOLDER 👎

$ mv myMedia/ myMusic/

merge folders

STOP DRAG AND DROPING TO MERGE FOLDERS 👎

$ rsync -a /images/ /images2/	# note: may over-write files with the same name, so be careful!

create a new file

STOP RIGHT CLICKING AND CREATE A NEW FILE 👎

$ touch 'new file'    # updates the file's access and modification timestamp if it already exists
# or
$ > 'new file'        # note: erases the content if it already exists

create a new folder

STOP RIGHT CLICKING AND CREATE A NEW FOLDER 👎

$ mkdir 'untitled folder'
# or
$ mkdir -p 'path/may/not/exist/untitled\ folder'

show file/folder size

STOP RIGHT CLICKING AND SHOW FILE/FOLDER INFO 👎

$ du -sh node_modules/

show file/folder info

STOP RIGHT CLICKING AND SHOW FILE/FOLDER INFO 👎

$ stat -x readme.md   # on macOS
$ stat readme.md      # on Linux

open a file with the default program

STOP DOUBLE CLICKING ON A FILE 👎

$ xdg-open file   # on Linux
$ open file       # on MacOS

zip a folder

STOP RIGHT CLICKING AND COMPRESS FOLDER 👎

$ zip -r archive_name.zip folder_to_compress

unzip a folder

STOP RIGHT CLICKING AND UNCOMPRESS FOLDER 👎

$ unzip archive_name.zip

peek files in a zip file

STOP USING WinRAR 👎

$ zipinfo archive_name.zip
# or
$ unzip -l archive_name.zip

remove a file

STOP RIGHT CLICKING AND DELETE A FILE PERMANENTLY 👎

$ 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.

remove a folder

STOP RIGHT CLICKING AND DELETE A FOLDER PERMANENTLY 👎

$ rm -r my_useless_folder

list folder contents

STOP OPENING YOUR FINDER OR FILE EXPLORER 👎

$ 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.

tree view a folder and its subfolders

STOP OPENING YOUR FINDER OR FILE EXPLORER 👎

$ tree                                                        # on Linux
$ 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.

find a stale file

STOP USING YOUR FILE EXPLORER TO FIND A FILE 👎

Find all files modified more than 5 days ago

$ find my_folder -mtime +5

show a calendar

STOP LOOKING UP WHAT THIS MONTH LOOKS LIKE BY CALENDAR WIDGETS 👎

Display a text calendar

$ cal

Display selected month and year calendar

$ cal 11 2018

find a future date

STOP USING WEBAPPS TO CALCULATE FUTURE DATES 👎

What is todays date?

$ date +%m/%d/%Y

What about a week from now?

$ date -d "+7 days"                                           # on Linux
$ date -j -v+7d                                               # on MacOS

use a calculator

STOP USING CALCULATOR WIDGET 👎

$ bc

force quit a program

STOP CTRL + ALT + DELETE and choose the program to kill 👎

$ killall program_name

check server response

STOP OPENING A BROWSER 👎

curl -i umair.surge.sh
# curl's -i (--include) option includes HTTP response headers in its output.

view content of a file

STOP DOUBLE CLICKING A FILE 👎

$ 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.
$ cat apps/settings.py | less

search for a text

STOP CMD/CTRL + F IN A FOLDER 👎

$ grep -i "Query" file.txt

grep

view an image

STOP USING PREVIEW 👎

$ imgcat image.png
# Note: requires iTerm2 terminal.

show disk size

STOP RIGHT CLICKING DISK ICON OR OPENING DISK UTILITY 👎

$ df -h

check performance of your computer

STOP OPENING YOUR ACTIVITY MONITOR OR TASK MANAGER 👎

$ top

Quick tips

CLI tips

Hotkeys

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
Ctrl + L  Clears the Screen, similar to the clear command
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
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
Esc + T   Swap the last two words before the cursor
Alt + F   Move cursor forward one word on the current line
Alt + B   Move cursor backward one word on the current line
Tab       Auto-complete files and folder names

I can't remember these cryptic commands

You can always google or man the commands you are not familiar with. Or, checkout tldr, a collection of simplified and community-driven man pages.