Getting started with bash

By Kam Leung

cd - When you need to cd to your previous folder


workspace > cd papercups
papercups > cd -
workspace >

cd !$ When you need to cd to the last argument of the previous command

workspace > ls papercups            Procfile            compile        elixir_buildpack.config     index.html          priv           config              docker-compose.yml      erl_crash.dump          lib             rel         _build              deps                  mix.exs             scripts
Dockerfile          app.json            dev.Dockerfile        mix.lock            test
LICENSE             assets          docs            phoenix_static_buildpack.config
workspace > cd !$
cd papercups
papercups >

mdfind (Mac only) - Search your entire mac for filename or content with that string instantly since macos automatically indexes your files see for more details

papercups > mdfind papercups.png
papercups >

pbcopy (Mac only) copys content in to your paste buffer

pbpaste (Mac only) output the contents of your paste buffer

Two for one example:

papercups > echo "Papercups Papercups Papercups" | pbcopy
papercups > pbpaste
Papercups Papercups Papercups

wc -l Gets line count of file

papercups > ls             deps                  mix.lock      _build              dev.Dockerfile          docs                phoenix_static_buildpack.config         app.json        echo            priv
Dockerfile          assets         elixir_buildpack.config     index.html          rel
LICENSE             compile             docker-compose.yml      erl_crash.dump          lib             scripts
Procfile            config        file.txt            mix.exs             test
papercups > wc -l
papercups >

sort sorts a file by line

uniq removes duplicate adjacent lines. I like to combine it with sort to dedupe a file.

grep use it to find files but I mostly use it as a way to filter when working with files

awk gets specific columns of a file

| Pipes output of one command in to the input of another command

I got a little lazy at this point and figure the best way to show case these commands is to chain them together. I was putting this post together when I wanted to see what are some of my common bash commands so I wrote some bash commands that looks through my bash history and gets filters out my git and echo commands.

history | awk -F' ' '{print $2, $3}' | sort | uniq | grep -v 'git\|echo'

history | awk -F' ' '{print $2, $3}' | sort | uniq | grep -v 'git\|echo'
cat file.txt
cat results.
cat results.csv
cd -
cd ..
cd ../docs/
cd ../
cd ../
cd papercups
code .
code index.html
cp results.csv
less results.csv
ls papercups
ls results.csv
mdfind papercups
mdfind papercups.png
mix phx.server
npm install
npm run
open index.html
papercups >
pbcopy |
pbpaste |
rm results.csv
rm results.txt
source .env
stty sane
tail -f
tail results.csv
tail results.txt
touch results.csv
ts-node inspect
ts-node inspeect
vim results.
vim results.csv
vim yc_companies.csv
wc -l
which node

Papercups is an open source customer support tool and an alternative to Intercom and Zendesk

GitHub repo:

Related Posts:

Elxir gen server explained