On Github actionshrimp / command-line-presentation
Mostly about bash
Windows cmd.exe does some of this (or powershell)
BUT you can use git bash on windows
Text (commands) -> Executing programs [ -> Text output ]
$ ls sushi-cat-1.jpg sushi-cat-2.jpg sushi-cat-3.jpg ...
$ rm angsty-poetry.txt
$ curl http://www.7digital.com <html lang="en-GB" ...
Little programs each good at one thing (usually)
OH: "unix: microservices since 1973" #truth
— Pieter Noordhuis (@pnoordhuis) October 22, 2014For built-ins:
$ help
For commands, CONVENTION: --help (or -h)
$ curl --help Usage: curl [options...] <url> Options: (H) means HTTP/HTTPS only, (F) means FTP only --anyauth Pick "any" authentication method (H) -a, --append Append to target file when uploading (F/SFTP) --basic Use HTTP Basic Authentication (H) ...
$ curl --help | less
More in depth help: man <command>
(May not be installed on git bash)
$ man curl NAME curl - transfer a URL SYNOPSIS curl [options] [URL...] DESCRIPTION curl is a tool to transfer data from or to a server... RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP)...
(from ls's help) -a, --all do not ignore entries starting with .
$ ls -a ... $ ls --all ...
$ ls -lahg
$ tail -n 5 index.html ... $ head -n 5 index.html
$ rm -rf / ...
$ ls -l total 88K drwxr-xr-x 4 dave users 4096 Sep 29 16:16 css $ ls -lh total 88K drwxr-xr-x 4 dave users 4.0K Sep 29 16:16 css $ du -h ...
$ find . -iname "*.json"
$ find . -name 'foo.cs' '!' -path '.git'
/? instead of -h or --help
Switches are generally in the style /X rather than -x
... but it's what you're used to
Helping you write commands
Executing programs
$ cd ~
Aliases serve a similar purpose
$ history
$ mv *.jpg pictures/
$ ls src/**/*.cs
$ echo {a,b}{c,d} ac ad bc bd
$ ls long-file-name-with-a-msitaek-in-the-middle.txt $ mv long-file-name-with-a-{msitaek,mistake}-in-the-middle.txt $ ls long-file-name-with-a-mistake-in-the-middle.txt
$ echo {1..10} 1 2 3 4 5 6 7 8 9 10
$ cat server-errors-2014-09-2{5..9}.log ...
Syntax is a bit nasty
$ for i in {1..4}; do touch new-file-$i.txt; done;
$ touch new-file-1.txt $ touch new-file-2.txt $ ...
Brace expansion can often achieve similar results depending on the command you're running, e.g.
$ touch new-file-{1..4}.txt
$ touch new-file-1.txt new-file-2.txt ...
Using a scripting language can be quicker for more complex stuff
e.g.
$ ls -lah
$ whoami a-stupidly-long-username-argh-what-a-pain-to-type $ sudo chown $(whoami) someone-elses-file.txt
This also works:
$ sudo chown `whoami` someone-elses-file.txt
Those are backticks, $(..) is prefered.
# Search all .cs files (recursively) in src/ for 'ElusiveWidgetFactory' $ cat src/**/*.cs | grep ElusiveWidgetFactory # Page through 7digital.com HTML $ curl www.7digital.com | less # Monitor error log file and report lines which match "500" $ tail -f /var/log/server/error.log | grep 500
Requires stdin convention to be followed
Rule of Silence - no unnecessary output
Rule of Repair - fail noisily
$ curl "http://api.7digital.com/1.2/release/search?q=..." \ | xml format > search_results.xml
echo bin >> .gitignore
# /dev/null becomes "nul" on windows $ curl -vs www.7digital.com >/dev/null
$ run-the-tests 2>&1 >/dev/null | grep "a-particular-error"
$ grep "something" < myfile.txt
We didn't cover "if then else"
Don't try to do too much!
Useful because it's everywhere
Use a real scripting language if it makes sense