Useful Commands


Here's a list of command lines I've found useful to automate repetitive or long tasks. They are categorized by operating system or task.

Git

Unstaging added files

This works even without a valid HEAD refspec, useful if you added things earlier, and you forgot to write a .gitignore file first.

git rm --cached -r -f .

GNU/Linux

File Management

Batch Convert UNIX Man Pages into HTML Files, With Links

'%N' is replaced for the name for the link tag, and '%S', the section number. Runs in BASH. Tested on Ubuntu. Requires mandoc to be installed.

mkdir html && for x in .; do mandoc -Thtml -O man=./html/%N.%S.html,toc $x > html/$x.html; done

Virtual Machines

Mount A file system attached to a virtual machine DISK image

I've found this to be more useful than guestmount (provided by the libguestfs-tools package for Ubuntu), because it does not require superuser privileges to execute, and is easy to unmount afterwards. Based on the answer provided on Super User: https://superuser.com/a/1548983.

mkdir -p ~/tmp/windows10-vm
nbdfuse ~/tmp/windows10-vm [ qemu-nbd path_to_disk_image ] &
fusermount -u ~/tmp/windows10-vm

Networking

Find Ports in use by Processes

May require superuser privileges to see info for processes for other users.

netstat -atpn