The single ampersand & is used to run commands asynchronously in the background. From the bash docs: If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell. This is known as executing the command in the background, and these are referred to as asynchronous commands. The […]
Command Line
How to kill a process
The easiest way: use pkill to kill a running process by name. Let’s say you have a background task running: Those sleep commands will run for 60 seconds and 600 seconds, respectively. Kill a process by name If we want to kill them sooner, we can just pkill them by name: pkill works similar to […]
The Bash trap command
Bash’s trap command is used to catch and react to signals sent to your shell. It’s similar to an event listener in the browser, or a pubsub topic subscriber. The typical use case is to run some kind of cleanup command when a process terminates, like this: The command above will run cleanup_job when it […]
Save your shell history to log files
Every command I enter on my computer is written to a log file. These logs have come in handy countless times; I tell anyone who will listen to save their logs too. My inspiration for doing this came from this atomic object post many years ago, and I am so glad I followed their advice. […]
Copy and paste from the command line
We use copy and paste all the time, so why not use them from the command line? I do it all the time, so let’s do a quick run down. First, the commands: Copy something from the web and paste it to a file This is my most frequent usage of either of these commands, […]
How to free up disk space
Part of being a developer means constantly downloading new packages, updates, codebases, etc. Eventually, your computer starts to fill up. This post details how to clean it out. The du command This is the disk usage command, and it is key to figuring out what is using your space. Here’s my usual workflow: Starting at […]
Command line manual pages and tldr
When looking into command line … commands, you’ve probably seen the man command, which is short for manual. For instance, if I want to know all about the ls command I can run man ls, which returns this on my mac: That’s a lot of info, and the screenshot above just the tip of the […]
How to find files on linux / mac
Command line find is a powerful, underutilized tool. In this post, I’ll go through the following use cases: Find files by name I use this all the time. Let’s say I’m in my ~/Downloads directory. That directory has several hundred files in it—and quite a few subdirectories—so it’s a bit hard to comb through in […]
Grep, grep options, and grep’s faster open-source alternative: ripgrep
Tldr: Grep In large codebases just finding the things you need can be hard. The built-in solution on linux/unix is grep. The basic format is grep {search_term} {file_path}. Here are a few simple examples: Here are a few commonly-used useful flags for grep: Flag Effect -i makes search case-insensitive -r recursively search directories -n show […]