Rootree
Github Logo

Helpful Commands

Github Logo

This is a list of helpful commands that you may find useful.

Aliases

  • Shell command aliases that I frequently use. Add these to your .bashrc or .zshrc file, and then run source ~/.bashrc or source ~/.zshrc to apply the changes.

    alias gita="git add ."
    alias ls="ls -a -l"
    alias gits="git status"
    alias gitpl="git pull"
    alias gitps="git push --follow-tags"
    alias yarnu="yarn upgrade-interactive"
    alias yarnd="yarn run dev"
    alias yarnr="yarn run release patch"

Archives

  • To archive and compress a directory.

    tar -zcf output.tar.gz directory-to-compress
    • Compress, create, output file
  • To extract a compressed archive

    tar -xzf archive.tar.gz
    • Extract, compressed, input file

Disk Usage

  • To find the largest files and directories in a directory

     du -ha * | sort -h | tail -n 20
    • du Disk usage, human-readable, include files.
    • sort Sort, human-numeric-sort
    • tail Show end of file, 20 lines.

Docker

  • Get shell access to a running container

    docker exec -ti <container_name> sh
  • Get shell access to an image

    docker run --rm -it --entrypoint sh <image_name>

Git

  • Remove branches not on remote

    git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done
  • Remove files from the repository that are present in .gitignore

    git rm -r --cached .
    git add .
  • Selectively add or overwrite a file from another branch

    git checkout --patch <branch> <file>
  • Revert a file to the state it was at a commit

    git checkout <commit hash> -- <file>
  • Clone into the current directory

    git init
    git remote add origin <url_of_repository>
    git fetch origin
    git checkout -b main --track origin/main
  • Discard all changes since last commit

    git stash --include-untracked
  • Compare a file between two branches

    git diff <branch1>..<branch2> <file>

Grep

  • Search for a time-stamp in a directory. (Where 24 is the year, 06 is the month, 13 is the day, and 17:20 is the local time)

    grep -R -E "24(\-|\/)?06(\-|\/)?13(T| )(17|21)\:20" .
    • Recursive, match pattern

MacOS Specific

  • Dock Hide/Show Speed

    defaults write com.apple.dock autohide-delay -int 0
    defaults write com.apple.dock autohide-time-modifier -float 0.15
    killall Dock

    You can change the values for 0 and 0.4 to see if a different setting works better for you.

  • Remember to change int to float if you want to use a float instead of 0.

    If you don’t like it, you can undo the changes using these commands:

    defaults delete com.apple.dock autohide-delay
    defaults delete com.apple.dock autohide-time-modifier
    killall Dock

SCP

  • Copy a file from an SSH source

    scp username@host:source-path destination-path