Shell scripting
This topic is about bash, zsh, fish, and other shell languages. It includes command-line tools like curl and ffmpeg.
9 articles
Opening all the files that have been modified in a Git branch
You can use Git to find where a branch diverged from
main, what files have changed, then open those files in your editor.Whose code am I running in GitHub Actions?
I wanted to know what third-party code I was using in my GitHub Actions. I was able to use standard text processing tools and shell pipelines to get a quick tally.
Setting up Fish to make virtualenv easier
I wrote some shell config to smooth out the experience of using virtual environments in Python.
Making the fish shell more forgetful
A few commands that help me keep unwanted entries out of my shell’s autocomplete.
Checking lots of URLs with curl
A bash script to check the HTTP status code of a bunch of URLs, for simple and portable uptime checking.
Two shortcuts for using S3 in the shell
Two shell functions for editing and inspecting S3 objects as if they were local files.
A shell alias for tallying data
A way to count records on the command-line.
Safely deleting a file called ‘-rf *’
If for some reason you create a file called
-rf *, it’s possible to delete it safely. But really, don’t create it in the first place.Pretty printing JSON and XML in the shell
14 notes
How to do resumable downloads with curl
You want the
--continue-at -flag, which will resume the transfer from the size of the already-downloaded file.Use
systemctl is-activeto determine if a service is runningComparing two files in a bash script
Inspect the exit value of
cmp --silent.Add the
-vflag to see whatrmis deletingDebugging some confusing behaviour with
findandxargsUse the
--verboseflag to see whatxargsis doing; don’t rely onfindto return files in a consistent order.Use
$_to get the last argument to the previous bash commandThis allows you to write commands like
mkdir myfolder && cd $_orgit init myrepo && cd $_.Build a URL with query string parameters with curl
A combination of
--getand--data/--data-urlencodeallows you to write curl commands which are readable and expressive.The
opencommand can ask questionsIf you pass an argument that can’t be easily identified as a file or a URL,
openwill ask you what to do next. This may be a surprise if you were trying to use it in a script.Use the
-n/-iflags to avoid overwriting files withcpandmvUsing
errexitand arithmetic expressions in bashBeware of using
test -nwith command expansionHow to move files when you need sudo on the remote server
Create a directory before you
cpormva file to itHow to use xargs for parallel processing