- Coreutils manual • GNU 📚
- bat • A
cat
clone with with syntax highlighting and Git integration 🛠️
- exa • A modern replacement for
ls
🛠️
- fd • A simple, fast and user-friendly alternative to
find
🛠️
- fzf • A command-line fuzzy finder 🛠️
grep
- jq • A lightweight and flexible command-line JSON processor 🛠️
kill
• stop a running process by its PID
- lsof • List open files 🛠️
- identify which process is running on port 5000:
lsof -i:5000
- identify the PID of the process on port 5000:
lsof -t -i:5000
ncdu
• list files by size 🛠️
pbcopy
/pbpaste
- ripgrep • ripgrep recursively searches directories for a regex pattern while respecting your gitignore 🛠️
- sed • A stream editor for filtering and transforming text 🛠️
tldr
top
- Linux Command Line playlist • The Frugal Computer Guy 📺
- Manipulating Files in Your Current Working Directory • Red Hat Enterprise Linux Step By Step Guide 📖
- 7 Essential Command Line Text Tools • grep, jq, yq, jqp, sed, bat (including as a less replacement), awk • DevOps Toolbox 📺
- These Modern Linux Tools Will BLOW YOUR MIND • DevOps Toolbox 📺
fd
= find
replacement
sd
= sed
replacement
exa
(now eza
) = ls
replacement
dust
= du
replacement
dog
= dig
replacement
xh
= curl
replacement
ncdu
= du
replacement
duf
= df
replacement
bat
= cat
replacement
- Examples:
Bash/Zsh Syntax
- Create and delete files and folders:
mkdir <folder-name>
- create directory
rm -rf <folder-name>
- delete directory and its contents
touch <file.ext>
- create file
rm <file.ext>
- delete file
- Moving and copying files:
mv <file1.ext> <file2.ext> <target-folder>
- move individual file(s)
mv * <target-folder>
- move all files in current folder
mv <file.ext> <renamed.ext>
- rename file
cp <file1.ext> <file2.ext> <target-folder>
- copy individual file(s)
cp * <target-folder>
- copy all files in current folder
cp <file.ext> <renamed.ext>
- copy and rename file
- Keyboard shortcuts:
⌃A
- jump to beginning of line
⌃E
- jump to end of line
⌃U
- clear from cursor position to beginning of line
⌃R
- search command history (hit ENTER
to run command)
⌘K
- clear console
- Package website shortcuts:
npm home <repo name>
- opens repo’s homepage
npm repo <repo name>
- opens repo’s github page
npm bugs <repo name>
- opens repo’s github issues
- The Bash String Operators | Kevin Sookocheff • Kevin Sookocheff 📖
- Single vs double quotes:
- Introduction to Bash Scripting • Bobby Iliev 📕
- Bash on Exercism • Get fluent in Bash by solving 89 exercises • Exercism 👩🎓
Environment variables
Configuring Zsh
Configuring kitty
Searching Kitty Terminal Output with Vim
- use nvim as scrollback pager
- tl;dr
# kitty.conf
# update nvim -u path to point to your own config (if using a custom one)
scrollback_pager nvim --noplugin -u ~/.config/kitty/scrollback/init.lua -c "silent write! /tmp/kitty_scrollback_buffer | te cat /tmp/kitty_scrollback_buffer - "
# change cmd+f and cmd+o to anything you like
# search scrollback in a pager (mapped to nvim above)
# see: https://sw.kovidgoyal.net/kitty/actions/#action-show_scrollback
map cmd+f show_scrollback
map cmd+o show_last_command_output
- why use nvim to search command output?
- if you’re a vim user, you already know how to quickly jump to the beginning/end and up/down through text
- you also already know how to search and navigate back and forth through your results
- you also already know how to easily copy text
- compared to the default
less
pager or other options like tmux
’s copy mode, nvim
gives you the ability to actually alter the output by running set modifiable
and then deleting any lines you don’t want to see
- you also have full control over the configuration of your
nvim
instance to customize the appearance and behavior of your search environment however you like
- to keep this pager speedy, you can point to a simplified config that loads quickly and removes everything irrelevant if you like
- I added this to mine to allow deleting lines (to reduce noise) and starting at the bottom by default:
-- Allow deleting lines and start at the bottom
vim.api.nvim_create_autocmd('VimEnter', {
command = [[
setlocal modifiable
normal G
]]
})
Filtering kitty terminal output with fzf
Navigating Kitty Terminal With Your Keyboard
- creating, resizing and navigating windows and tabs
- tl;dr:
# Create windows
map ctrl+\ new_window_with_cwd
# Navigate windows (i.e. splits/panes)
map ctrl+h neighboring_window left
map ctrl+l neighboring_window right
# map ctrl+j neighboring_window bottom # FIXME: interferes with menu up/down (e.g. for fzf)
# map ctrl+k neighboring_window top # FIXME: interferes with menu up/down (e.g. for fzf)
# Navigate tabs
map ctrl+] next_tab
map ctrl+[ previous_tab
# toggle zoom current window
map ctrl+m toggle_layout stack
- explain how layouts work
- unlike most terminals, most kitty layouts won’t let you decide if you want to split a window vertically or horizontally
- the new window will position itself automatically based on the active layout
- (examples)
- if you want more control over which direction your next split will occur in, you need to activate the
splits
layout
- zoom a single window by activating the
stacks
layout
- add keymap to toggle the zooming
- keymaps to quickly move your cursor between windows
- I prefer the following
- watch out for conflicts with similar navigation keymaps in running terminal apps (e.g. fzf)
- how to use ctrl+j/k in both…?
- Add resize mappings too
- Add layout swap mappings too?
- Inbox:
- add maps for navigating back and forth to previous command prompts
- terminal shortcut to scroll to the beginning of the output for the last command?
- how to scroll with the keyboard (no mouse)? - Overview - kitty: https://sw.kovidgoyal.net/kitty/overview/#scrolling
- shortcuts: add same split creation + navigation ones as in tmux
- best prefix for custom maps? command-key?
- define better auto splits and manual split mappings (via the “splits” layout?): https://sw.kovidgoyal.net/kitty/layouts/
Stopping the process running on a port
- Problem:
- you try to start a process in your terminal (e.g. start a local dev server) and see an error that the port is already in use
- you check all your open terminal windows and don’t see a process to stop
- Identify what the process is like this:
- If that process is safe to stop, use the “PID” value from the output above or isolate that value like this:
- Then kill that process using its PID like this:
- To make it easier to free up a port in the future, you could also add a zsh function like this to your
.zshrc
(or equivalent terminal config file):
# kill process running on given port
k() { lsof -t -i:$1 | xargs kill -9; }
Switch to bash on Mac to get access to shellcheck
?
Make a file executable
Generate any number of test files in a directory
Searching command history
Inbox
- explainshell.com • match command-line arguments to their help text
- Comics • Julia Evans 📖
- broot • A new way to see and navigate directory trees 🛠️
- Navigating
less
pager (e.g. during a git log
):
- terminal: How To Append Current Date To Filename in Bash Shell - nixCraft -
today=$(date +"%Y-%m-%d")
- terminal: explainshell.com - match command-line arguments to their help text - get great explanations of all options for common shell commands
- terminal: bash: Propagate all arguments in a Bash shell script - Stack Overflow - refer to all args passed to a bash function
- terminal: search - grep: show lines surrounding each match - Stack Overflow - add context lines to grep with -B, -A, and -C
- terminal: How to Exclude Files and Directories When Creating a tar.gz File | Baeldung on Linux
- terminal: tr: tr - Translate characters - IBM Documentation - translate characters in a string (e.g. edit the result of a grep search)
- terminal: tr: linux - Removing characters from grep output - Stack Overflow
- terminal: bash: How to Check if a File or Directory Exists in Bash | Linuxize
- rsync: Output a List of Changed Files From rsync | Baeldung on Linux - various options for outputting more or less info about a transfer
- bash: bash - Disable functions/aliases in a sourced script - Stack Overflow - if you have conflicting command names, they win in this descending order: alias, function, built-in, PATH executable
- curl: curl - includes a 3 hr tutorial video
- post: list the various version manager tools (nvm, pyenv, tfvm, etc - find the rest!)
- symlink - How can I derefence symbolic links in bash? - Stack Overflow - follow a symbolink link with
readlink -f <path/to/symlink>
- Navigating around in your shell
- kitty: Overview - kitty - ctrl+shift+z to go to previous shell prompt, ctrl+shift+x for next shell prompt, ctrl+shift+g to browse last command output in less, ctrl+shift+h to browse full scrollback in less
- 5 ways to navigate the Linux terminal faster | Enable Sysadmin
- Mastering Zsh Keyboard Shortcuts for Efficient Shell Navigation and Editing | by Robioki Denis | Medium
- kitty:
- kitty: make last prompt sticky at top of screen? (“context”, “sticky”)
- kitty vs tmux vs wexterm for copy mode?
- kitty: add diff kitten? https://sw.kovidgoyal.net/kitty/kittens/diff/
- kitty: can’t use ssh kitten inside of a tmux session (works outside of tmux); fixable?
- kitty: how do I scroll/jump using the keyboard?
- The Set Builtin (Bash Reference Manual) - what the various
set -[*]
options at the top of scripts mean
- bash: shell - Getting “numeric argument required” when running a script with arithmetic operations - Stack Overflow - don’t
return
values from functions, echo
them instead; echo
is the equivalent of a JS return
statement; in bash, return
is an int between 0 and 255 (I think representing the status of how successful the function run was)
- shellcheck: ShellCheck – shell script analysis tool - in-browser version
- bash: linux - How do I syntax check a Bash script without running it? - Stack Overflow -
bash -n <scriptname>
to check the syntax of a script file without running it
- bash: In a bash script, using the conditional “or” in an “if” statement - Unix & Linux Stack Exchange - to use
OR
in an if
statement, wrap each condition in its own [[ ]]
and put a ||
between them
- starship: Your shell prompt, ON STEROIDS // Starship - try again? I do miss the config being short and only containing lines you’ve added…
- Assess Disk Usage from the Terminal • How to use
du
and dust
commands to view the size of a folder and its subfolders • Elijah Manor 📺
- warp: IDE-style Warp Terminal Update • Coding in Public 📺
- Bash for Beginners • Microsoft Developer 📺
- More fun in the terminal with Wezterm! • Defining Wezterm’s config with lua makes it easy to dynamically compute settings (e.g. pick a random option) • Josh Medeski 📺
- Prompt:
- Using JavaScript to Write a Custom CLI • Demo of Clack • Coding in Public 📺
- Parse Command Line Positional Arguments and Flags with Bash - How to parse arguments to a bash script - Nick Janetakis
- Nushell - Alternative to bash/zsh that treats inputs as structured data instead of strings
- TUI Terminal Tools - Terminal Trove - Directory of TUIs