theme: Sketchnote
- You use the command line at work
- It keeps popping up in everything I do
- You use it to bootstrap your code projects
- Automating tasks you do frequently. Repeatability!
- Anthony seems like a cool guy I wonder what he has to say
- I want to understand how this expensive laptop I bought really works
The command line is incredibly expressive and powerful. It can help you be more productive and automate mundane tasks.
- standard unix bash commands
- chaining, pipes and output redirection
- alias, shell functions, and your first shell script
- scripting with javascript
- cron,
.bashrc
, and.bash_profile
- homebrew - the package manager for OSX
Mac's run Unix. Developers love Unix. Unix is awesome. You can be awesome.
cd - change directory
ls - list files
pwd - current working directory
cp - copy
mv - move
mkdir - make directory
rm - remove
cat - concatenate
^ We won't cover these because I expect you already know these elementary commands. And if you don't know them now might be a good time to leave. J/K but you can follow along with the examples and pick up some practice with these too.
say
history
head / tail
curl
time
watch
grep
find
xargs
ssh
$ command --option option_argument x (y z ...)
http://www.linuxjournal.com/content/downloading-entire-web-site-wget
$ wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains blankslate.io \
--no-parent \
blankslate.io
Simple command to make terminal say something.
say why cant we be friends
Extra credit:
say --voice ?
say --voice "Bad News" The light you see at the end of the tunnel is the
headlamp of a fast approaching train.
history
echo goodbye world
history
!-2
history
head camp.txt
head -n50 camp.txt
tail camp.txt
Extra Credit:
tail -f camp.txt
echo foo >> camp.txt
curl http://www.simonmarqvard.com/wp-json/wp/v2/posts
curl -o post.html http://www.buoydontfloat.com/10x-command-line-fu/
curl -I https://ideas.ted.com
curl wttr.in
open -a "Google Chrome" http://nytimes.com
curl -XPOST slack webhook
# copy a cURL command from chrome inspector
http://www.linuxjournal.com/content/downloading-entire-web-site-wget
$ wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains blankslate.io \
--no-parent \
blankslate.io
false || echo "Oops, fail"
# => Oops fail
true || echo "Will not be printed"
# =>
true && echo "Things went well"
# => Things went well
false ; echo "This will always run"
# => This will always run
<
# The < will take and send the input from the file on the right to the
program on the left.
>
# The > takes the output of the command on the left, then writes it
to the file on the right.
>>
# The >> takes the output of the command on the left, then appends it
to the file on the right.
|
# The | takes the output from the command on the left, and "pipes" it to
the command on the right.
"pipe" the output of one command into the input of a second command
cat ~/.bash_history | grep say | tail -n20
# Examples
*/1 * * * * say 'super duper'
# Use a login shell so that our ~/.bash_profile gets loaded
*/1 * * * * /bin/bash -lc "/Users/anthony/itp/itp-command-fu/03-superbole.js"
Some homebrew recommendations:
brew update
brew install wget
wget https://cdn.rawgit.com/epylinkn/itp-command-fu/master/commandfu.pdf
brew install tree
tree .
brew install jq
curl http://www.simonmarqvard.com/wp-json/wp/v2/posts | jq '.[].title'
# the secret to your video-dj dreams
brew install youtube-dl
youtube-dl -f18 https://www.youtube.com/watch?v=mDX_eYOKe4s
# faster and more configurable command-line search
brew install the_silver_searcher
brew install cask
brew cask info gifrocket
brew cask install gifrocket
open -a Gifrocket
brew cask uninstall gifrocket
brew cask search unity
brew cask install unity
Learn by being curious! Ask yourself:
Is there a better way to do this on the command-line?