SlideShare a Scribd company logo
The Art of Command Line
2021-02-22
Kenta Yamamoto (@i05)
1
Unix Philosophy - "The Art of UNIX Programming" (2003)
2
$ history | awk '{ print $2 }' | sort | uniq -c | awk '$1>1' | sort -r | head
791 g
172 cat
115 git
83 echo
71 brew
70 yarn
68 ll
50 dig
49 gcloud
43 jj
Make each program do one thing well. To do a new job, build
afresh rather than complicate old programs by adding new
features.
“
“
3
For example, you have to sort the output before uniq because they
only do one thing:
$ history | awk '{ print $2 }' | sort | uniq -c | awk '$1>1' | sort -r | head
4
Execute a shell script:
#!/usr/bin/env bash
# command-ranking.sh
set -euo pipefail
history | awk '{ print $2 }' | sort | uniq -c | awk '$1>1' | sort -r
$ chmod u+x ./command-ranking.sh
$ bash ./command-ranking.sh | head
5
Interface - standard streams:
STDIN
STDOUT
STDERR
$ time curl -IL https://example.com/ 2>&1 > file.txt
$ time curl -IL https://example.com/
...
curl -IL https://example.com/ 0.02s user 0.01s system 5% cpu 0.467 total
6
Parameters - $0 , $1 , $# , $@
#!/usr/bin/env bash
# sample.sh
cat -
echo "file=$0, 1st-arg=$1, 2nd-arg=$2, arg-num=$# args=$@"
$ echo "Hello" | bash $(pwd)/sample.sh foo bar baz
Hello
file=/Users/kyamamoto/src/bitbucket.org/i05/support/sample.sh, 1st-arg=foo, 2nd-arg=bar, arg-num=3 args=foo bar baz
7
Sounds of Silence - $?
$ touch ~/tmp/sample.txt
$ echo $?
0
$ mv no-such-file.txt /tmp/
mv: cannot stat 'no-such-file.txt': No such file or directory
$ echo $?
1
8
Subroutine - $(command)
$ curl "https://jpnic.rdap.apnic.net/ip/$(dig +short myip.opendns.com @resolver1.opendns.com)" 
| jq .
9
Construct argument list - xargs :
$ find . -type f -name "*" ! -path '*/.svn/*' ! -path '*/.git/*' -print0 
| xargs -0 grep --ignore-case --line-number 'foo'
Parallel execution - xargs :
$ find . -type f -not -name '*.bz2' -print0 
| xargs -0 -L 1 -P $(sysctl -n hw.ncpu) bzip2
10
Multibyte encoding - nkf :
$ find . -type f -name "*.txt" | xargs nkf --guess
$ find . -type f -print0 | xargs -0 nkf --overwrite -w
11
Multiline:
TEXT_LIST=$(cat << EOF
__HERE_DOCUMENT__
__HERE_DOCUMENT__
EOF
)
12
Runs everywhere:
case "${OSTYPE}" in
# Mac
darwin*)
[ -f ~/.zshrc.osx ] && . ~/.zshrc.osx
;;
# Linux
linux*)
[ -f ~/.zshrc.linux ] && . ~/.zshrc.linux
;;
esac
13
Pitfall
Mac - BSD
or consider installing brew install gnu-sed instead
$ LANG=C find . -type f -name "*" ! -path '*/.svn/*' ! -path '*/.git/*' -print0 
| xargs -0 sed -i '~' -e 's///gi'
Linux - GNU
$ find . -type f -name "*" ! -path '*/.svn/*' ! -path '*/.git/*' -print0 
| xargs -0 sed -i -e 's///gi'
14
Pitfall
Mac - BSD
$ LANG=C git ls-files -z | xargs -0 sed -i '' -e 's///gi'`
Linux - GNU
$ git ls-files -z | xargs -0 sed -i -e 's///gi'
15
Git subcommands:
$ git grep 'Could not find the specified attachment on the server'
16
Release your brain resource:
Easily navigate directories - go with fewer cd s!
rupa/z, or
wting/autojump
Remote repository management - let the tool decide where to
locate the cloning repositories
x-motemen/ghq
17
Recommended commands:
jq
awk
rsync
time
watch
18
Linter:
koalaman/shellcheck: ShellCheck, a static analysis tool for shell
scripts
19
$ echo "Thank you!"
20
21

More Related Content

What's hot

Find and zip files
Find and zip filesFind and zip files
Find and zip files
Muqthiyar Pasha
 
Fast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambdaFast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambda
Mila Frerichs
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
Bryan Hughes
 
37562259 top-consuming-process
37562259 top-consuming-process37562259 top-consuming-process
37562259 top-consuming-processskumner
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell Script
VCP Muthukrishna
 
The Unbearable Lightness: Extending the Bash shell
The Unbearable Lightness: Extending the Bash shellThe Unbearable Lightness: Extending the Bash shell
The Unbearable Lightness: Extending the Bash shell
Roberto Reale
 
Docker tips & tricks
Docker  tips & tricksDocker  tips & tricks
Docker tips & tricks
Dharmit Shah
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMail
VCP Muthukrishna
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話
dcubeio
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X ServerYasuhiro Asaka
 
KubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume Plugins
KubeAcademy
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
Sebastian Pożoga
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
Stefano Ceschi Berrini
 
Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System Administrators
Allen Wittenauer
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introduction
thasso23
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
Nati Cohen
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxParis, France
 
Introduction to Resque
Introduction to ResqueIntroduction to Resque
Introduction to Resque
koshigoe
 
Character_Device_drvier_pc
Character_Device_drvier_pcCharacter_Device_drvier_pc
Character_Device_drvier_pcRashila Rr
 

What's hot (20)

Find and zip files
Find and zip filesFind and zip files
Find and zip files
 
Fast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambdaFast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambda
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
37562259 top-consuming-process
37562259 top-consuming-process37562259 top-consuming-process
37562259 top-consuming-process
 
File Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell Script
 
The Unbearable Lightness: Extending the Bash shell
The Unbearable Lightness: Extending the Bash shellThe Unbearable Lightness: Extending the Bash shell
The Unbearable Lightness: Extending the Bash shell
 
Docker tips & tricks
Docker  tips & tricksDocker  tips & tricks
Docker tips & tricks
 
Bash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMail
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
KubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume Plugins
 
GoLang & GoatCore
GoLang & GoatCore GoLang & GoatCore
GoLang & GoatCore
 
ES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript SkillsES6 - Level up your JavaScript Skills
ES6 - Level up your JavaScript Skills
 
Orm
OrmOrm
Orm
 
Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System Administrators
 
JIP Pipeline System Introduction
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introduction
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope Rpx
 
Introduction to Resque
Introduction to ResqueIntroduction to Resque
Introduction to Resque
 
Character_Device_drvier_pc
Character_Device_drvier_pcCharacter_Device_drvier_pc
Character_Device_drvier_pc
 

Similar to The Art of Command Line (2021)

Im trying to run make qemu-nox In a putty terminal but it.pdf
Im trying to run  make qemu-nox  In a putty terminal but it.pdfIm trying to run  make qemu-nox  In a putty terminal but it.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdf
maheshkumar12354
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2
Leandro Lima
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
egypt
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
Allen Wittenauer
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foobrian_dailey
 
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docxIntroduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
mariuse18nolet
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-liners
daoswald
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
Alessandro Manfredi
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
Lingfei Kong
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Ashrith Mekala
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
Kenneth Geisshirt
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
Michael J Geiser
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
bokonen
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
Aleksandar Bilanovic
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devs
Neoito
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
Kenneth Geisshirt
 

Similar to The Art of Command Line (2021) (20)

Im trying to run make qemu-nox In a putty terminal but it.pdf
Im trying to run  make qemu-nox  In a putty terminal but it.pdfIm trying to run  make qemu-nox  In a putty terminal but it.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdf
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docxIntroduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-liners
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
 
Slides
SlidesSlides
Slides
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devs
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 

More from Kenta Yamamoto

Vulnerability Detection Based on Git History
Vulnerability Detection Based on Git HistoryVulnerability Detection Based on Git History
Vulnerability Detection Based on Git History
Kenta Yamamoto
 
[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...
[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...
[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...
Kenta Yamamoto
 
文字コードとセキュリティ
文字コードとセキュリティ文字コードとセキュリティ
文字コードとセキュリティ
Kenta Yamamoto
 
良いUrlを設計する
良いUrlを設計する良いUrlを設計する
良いUrlを設計する
Kenta Yamamoto
 
私たちは何を Web っぽいと感じているのか
私たちは何を Web っぽいと感じているのか 私たちは何を Web っぽいと感じているのか
私たちは何を Web っぽいと感じているのか
Kenta Yamamoto
 
Tips for bash script
Tips for bash scriptTips for bash script
Tips for bash script
Kenta Yamamoto
 
優れたビデオゲームに共通する不変の法則
優れたビデオゲームに共通する不変の法則優れたビデオゲームに共通する不変の法則
優れたビデオゲームに共通する不変の法則Kenta Yamamoto
 
20110805 ui14課題2
20110805 ui14課題220110805 ui14課題2
20110805 ui14課題2
Kenta Yamamoto
 
20110804 ui14課題
20110804 ui14課題20110804 ui14課題
20110804 ui14課題
Kenta Yamamoto
 
東日本大震災後の訪日外国人数の変移_2011.3
東日本大震災後の訪日外国人数の変移_2011.3東日本大震災後の訪日外国人数の変移_2011.3
東日本大震災後の訪日外国人数の変移_2011.3
Kenta Yamamoto
 

More from Kenta Yamamoto (10)

Vulnerability Detection Based on Git History
Vulnerability Detection Based on Git HistoryVulnerability Detection Based on Git History
Vulnerability Detection Based on Git History
 
[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...
[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...
[論文紹介] VCC-Finder: Finding Potential Vulnerabilities in Open-Source Projects ...
 
文字コードとセキュリティ
文字コードとセキュリティ文字コードとセキュリティ
文字コードとセキュリティ
 
良いUrlを設計する
良いUrlを設計する良いUrlを設計する
良いUrlを設計する
 
私たちは何を Web っぽいと感じているのか
私たちは何を Web っぽいと感じているのか 私たちは何を Web っぽいと感じているのか
私たちは何を Web っぽいと感じているのか
 
Tips for bash script
Tips for bash scriptTips for bash script
Tips for bash script
 
優れたビデオゲームに共通する不変の法則
優れたビデオゲームに共通する不変の法則優れたビデオゲームに共通する不変の法則
優れたビデオゲームに共通する不変の法則
 
20110805 ui14課題2
20110805 ui14課題220110805 ui14課題2
20110805 ui14課題2
 
20110804 ui14課題
20110804 ui14課題20110804 ui14課題
20110804 ui14課題
 
東日本大震災後の訪日外国人数の変移_2011.3
東日本大震災後の訪日外国人数の変移_2011.3東日本大震災後の訪日外国人数の変移_2011.3
東日本大震災後の訪日外国人数の変移_2011.3
 

Recently uploaded

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 

The Art of Command Line (2021)

  • 1. The Art of Command Line 2021-02-22 Kenta Yamamoto (@i05) 1
  • 2. Unix Philosophy - "The Art of UNIX Programming" (2003) 2
  • 3. $ history | awk '{ print $2 }' | sort | uniq -c | awk '$1>1' | sort -r | head 791 g 172 cat 115 git 83 echo 71 brew 70 yarn 68 ll 50 dig 49 gcloud 43 jj Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features. “ “ 3
  • 4. For example, you have to sort the output before uniq because they only do one thing: $ history | awk '{ print $2 }' | sort | uniq -c | awk '$1>1' | sort -r | head 4
  • 5. Execute a shell script: #!/usr/bin/env bash # command-ranking.sh set -euo pipefail history | awk '{ print $2 }' | sort | uniq -c | awk '$1>1' | sort -r $ chmod u+x ./command-ranking.sh $ bash ./command-ranking.sh | head 5
  • 6. Interface - standard streams: STDIN STDOUT STDERR $ time curl -IL https://example.com/ 2>&1 > file.txt $ time curl -IL https://example.com/ ... curl -IL https://example.com/ 0.02s user 0.01s system 5% cpu 0.467 total 6
  • 7. Parameters - $0 , $1 , $# , $@ #!/usr/bin/env bash # sample.sh cat - echo "file=$0, 1st-arg=$1, 2nd-arg=$2, arg-num=$# args=$@" $ echo "Hello" | bash $(pwd)/sample.sh foo bar baz Hello file=/Users/kyamamoto/src/bitbucket.org/i05/support/sample.sh, 1st-arg=foo, 2nd-arg=bar, arg-num=3 args=foo bar baz 7
  • 8. Sounds of Silence - $? $ touch ~/tmp/sample.txt $ echo $? 0 $ mv no-such-file.txt /tmp/ mv: cannot stat 'no-such-file.txt': No such file or directory $ echo $? 1 8
  • 9. Subroutine - $(command) $ curl "https://jpnic.rdap.apnic.net/ip/$(dig +short myip.opendns.com @resolver1.opendns.com)" | jq . 9
  • 10. Construct argument list - xargs : $ find . -type f -name "*" ! -path '*/.svn/*' ! -path '*/.git/*' -print0 | xargs -0 grep --ignore-case --line-number 'foo' Parallel execution - xargs : $ find . -type f -not -name '*.bz2' -print0 | xargs -0 -L 1 -P $(sysctl -n hw.ncpu) bzip2 10
  • 11. Multibyte encoding - nkf : $ find . -type f -name "*.txt" | xargs nkf --guess $ find . -type f -print0 | xargs -0 nkf --overwrite -w 11
  • 13. Runs everywhere: case "${OSTYPE}" in # Mac darwin*) [ -f ~/.zshrc.osx ] && . ~/.zshrc.osx ;; # Linux linux*) [ -f ~/.zshrc.linux ] && . ~/.zshrc.linux ;; esac 13
  • 14. Pitfall Mac - BSD or consider installing brew install gnu-sed instead $ LANG=C find . -type f -name "*" ! -path '*/.svn/*' ! -path '*/.git/*' -print0 | xargs -0 sed -i '~' -e 's///gi' Linux - GNU $ find . -type f -name "*" ! -path '*/.svn/*' ! -path '*/.git/*' -print0 | xargs -0 sed -i -e 's///gi' 14
  • 15. Pitfall Mac - BSD $ LANG=C git ls-files -z | xargs -0 sed -i '' -e 's///gi'` Linux - GNU $ git ls-files -z | xargs -0 sed -i -e 's///gi' 15
  • 16. Git subcommands: $ git grep 'Could not find the specified attachment on the server' 16
  • 17. Release your brain resource: Easily navigate directories - go with fewer cd s! rupa/z, or wting/autojump Remote repository management - let the tool decide where to locate the cloning repositories x-motemen/ghq 17
  • 19. Linter: koalaman/shellcheck: ShellCheck, a static analysis tool for shell scripts 19
  • 20. $ echo "Thank you!" 20
  • 21. 21