Skip to content

Shell Wiki

Diff two directories

diff --brief --recursive -x '.git' -x 'autoload' \
    ~/.config/nvim ~/local.usersnap.com/.config/nvim

Find and replace recursively in a directory

find docs -name '*.md' | xargs sed -i "" 's/\[/\[:fontawesome-solid-link: /g'

Source.

Note: -i "" is only for MacOS. More here.

Moving around

# inspiration from https://twitter.com/fatih/status/1381555413083168769
# cd to the root of git repo
alias cdr="cd $(git rev-parse --show-toplevel)"

# use fzf to quickly cd into subdirectories
function c() {
  local selected_directory
  selected_directory=$(fd -t d | fzf --height=6 --layout=reverse)

  if [ -n "$selected_directory" ]; then
    cd $selected_directory
  fi
}

Ignore directories with tree

tree -I '__pycache__|node_modules|test_*'