Skip to content

Instantly share code, notes, and snippets.

@melaniehoff
Last active February 2, 2023 02:07
Show Gist options
  • Save melaniehoff/32b14210b7ea6f605f625eabdf8b3968 to your computer and use it in GitHub Desktop.
Save melaniehoff/32b14210b7ea6f605f625eabdf8b3968 to your computer and use it in GitHub Desktop.
Bash & Terminal Commands (For Folder Poetry)

🎲 Bash & Terminal commands

Command Description
cd change directory
cd .. change directory one level back
ls list contents of directory
pwd print working directory
mkdir foldername create a folder named foldername
touch dandelion.txt create a file named dandelion.txt
echo "woof woof" > kitty.txt creates a text file called kitty.txt that contains the words, "woof woof"
cat filename.txt print contents of file
atom filename.txt Opens file in atom (this is why we installed the shell commands!)
source ~/.bash_profile (macOS) restart your terminal config file
source ~/.bashrc (Windows) restart your terminal config file
rm -rf filename.txt . remove a file or folder this way (BE CAREFUL TO NOT DELETE ANYTHING UNINTENDED
mv filename.txt newfilename.txt rename a file
open . (macOS) open the current folder in Finder
explorer . (Windows) open the current folder in Explorer
open filename.txt (macOS) opens file in Text Edit
notepad.exe filename.txt (Windows) opens file in Notepad
cp filename.txt filename2.txt copy file
say "hello, what is poetic computation?" (macOS) speak out loud
https://superuser.com/questions/223913/os-x-say-command-for-windows (Windows) speak text out loud
man cd show the manual for 'cd'. Press q to quit
curl wttr.in check the weather in our local locations!β›…οΈπŸŒ§πŸŒˆ

Keyboard Terminal Shortcuts

Command Description
Up + Down Arrow keys scroll through history
Tab Key autocomplete
CMD + CTRL + SPACE Emoji Keyboard (Mac OS) πŸ’πŸ¦‹πŸ’ŒπŸ₯¬

Editing a text file

command Description
echo "woof woof" > kitty.txt creates a text file called kitty.txt that contains the words, "woof woof"
nano textfile.txt open file in the nano text editor
CTRL + X , y , ENTER exit and save changes

Editing your Bash config file

  • In these steps, we are using terminal and nano to open and edit a file called ~./bash_profile
  • In steps 2-4, the lines of code are meant to be pasted into nano when editing the ~./bash_profile
  • In the other steps, the commands are entered in terminal

The ~./bash_profile or ~./bashrc is a configuration file for the terminal.

First make sure you are running bash instead of zsh by running this command: chsh -s /bin/bash

  • Macs: nano ~/.bash_profile

    • This command will open your ~./bash_profile in nano
  • Windows: nano ~/.bashrc

    • This command will open your ~./bashrc in nano

In steps 2 and 3 we will paste the following aliases AKA shortcuts in nano that will help us visualize our folder poem structures.

  1. export PS1="πŸ‹ \w\n\u$ "

    • This will customize your Bash prompt. Feel free to change the emoji. (skip if you use zshell)
    • Explanation: \w shows your full file path so you'll always know where you are in the terminal, \n creates a new line in your bash prompt. \u shows your computer username, and $ symoolizes the end of a bash prompt.
  2. alias oldtree="find . -not -path '*/\.*' -print | sed -e 's;[^/]*/;|;g;s;|; |;g'"

    • (if you have homebrew installed enter brew install tree in another terminal window instead)
    • this will add a command you can use that will tree your poems in a more lo-fi way than the tree command we installed with homebrew
  3. alias treefile="find . -not -path '*/\.*' | xargs -I {} bash -c 'f={}; echo \$f | sed -e \"s;[^/]*/;|;g;s;|; |;g\"; if [[ \$f == *.txt ]]; then echo; cat \$f; echo; echo; fi'"

    • this will add a command you can use that will tree out the contents of your text files along with the folder structure.
  4. Reboot your terminal

Mac:source ~/.bash_profile Windows: source ~/.bashrc

OR close and reopen terminal : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment