Skip to main content

Zhy

Command Collection

A collection of useful commands and Bash snippets that I tend to forget way too often. Many more to come.

Files & Directories

Count number of files in a directory recursively

$ find mydir -type f | wc -l

Processes

Get runtime of a process

$ ps -p <pid> -o etime=

Net stuff

Turn on an interface

# ip link set up dev eth0

Manual add/delete ip address

# ip addr add 192.168.1.100/24 dev eth0
# ip addr del 192.168.1.100/24 dev eth0

Add/delete static route

# ip route add 192.168.1.0/24 via 192.168.1.1 dev eth0
# ip route del 192.168.1.0/24

Add default route

# ip route add default via 192.168.1.1

Git

Show remote origin url

$ git remote -v
$ git config --get remote.origin.url # for scripting

Add origin as remote

$ git remote add origin <url>

Change origin url

$ git remote set-url origin <url>

GnuPG

List public/private keys, shorthand

$ gpg -k
$ gpg -K

List keys with keyid, default is none for versions >= 2.1.13, short otherwise.

$ gpg -k --keyid-format <none|short|long>

Check if public key is in keyring

if gpg -k 0x1234ABCD > /dev/null 2>&1; then
    # key exists
fi

Get info about keys cached by gpg-agent

$ gpg-connect-agent 'keyinfo --list' /bye

Pacman

Install local package, e.g., from cache (/var/cache/pacman/pkg/)

# pacman -U mypackage.pkg.tar.xz

Get information about a package

$ pacman -Qi python2

List the files installed by a package

$ pacman -Ql python2

List explicitly installed packages

$ pacman -Qe
$ pacman -Qet # those that are not dependencies

List unneeded dependencies (orphaned packages)

$ pacman -Qdt

TeX Live

Update system-wide font map files

# updmap-sys

Run after adding new fonts

# texhash