Commands I forget (last update: 2020-06-16, created: 2012-10-03) back to the list ↑
Some console commands (Bash, cmd.exe, Linux-specific, Windows-specific, etc) I use infrequently, but still I need them from time to time, and I waste time to look them up. This note may grow over time.

Linux mount partition from image

Step 1. Find the partition offset (in sectors):

> fdisk ./hdd.img

Command (m for help): p

Disk ./hdd.img: 21.0 GB, 20971044864 bytes
255 heads, 63 sectors/track, 2549 cylinders, total 40959072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76a0ce3e

    Device Boot      Start         End      Blocks   Id  System
./hdd.img1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
./hdd.img2          206848    40955903    20374528    7  HPFS/NTFS/exFAT

Command (m for help): q

Step 2. Mount the partition (example for partition 2):

>sudo mount -o loop,offset=$[512 * 206848] ./hdd.img /some/path
Other ways to do it:
1. Extract the partition using dd.
2. Use losetup and a normal mount later.
3. Use partprobe or partx on /dev/loopN to map partition devices - /dev/loopNpM (thx licho).

VirtualBox raw disk image

VirtualBox is unable to directly use raw disk images (as far as I know), but has a built-in raw-to-vdi converter:

vboxmanage convertfromraw disk.raw disk.vdi
It can also convert to other formats, like vmdk or vhd (--format vdi|vmdk|vhd) and has some other variant options (the default variant is "Standard" which is not raw+header, but a kind of sparse format afair).

And the other way around:

vboxmanage internalcommands converttoraw disk.vdi disk.raw

VirtualBox real USB device used in VM/guest

Note: The VM/guest system can be running. I've tested this with Windows host and Linux guest.
1. [optional] On host, in case you don't won't to mount USB disk on host "by accident"*: run mountvol /N as admin to disable automatic volume mounting.
2. Plug in the device and run vboxmanage list usbhost. It should display a list of USB devices like this:

Host USB Devices:
...
UUID:               88a02f42-c127-4f4d-ac37-94f3d513462a
VendorId:           0x0346 (0346)
ProductId:          0x0252 (0252)
Revision:           1.0 (0100)
Product:            USB Mass Storage Device
SerialNumber:       0e5db835813035
Address:            {46fd9e61-d465-11cf-8052-444445670000}\0022
Current State:      Busy
...

3. Find your device, note e.g. VendorId and ProductId.
4. Unplug your device.
5. Add a filter using the following command:

vboxmanage usbfilter add 0 --target NameOfYourVM --name pendrive --productid 0252 --vendorid 0346
6. [optional] Run: mountvol /E as admin.
7. Plug in the device again. It should get detected by the VM.

* Windows FS drivers will "attach" to the volume anyway, you just won't get a letter assigned for it (it won't get mounted). This normally doesn't matter, unless you have a FS exploit on your pendrive that gets triggered on mount/unmount (yes, it did BSoD my host, grr).

Removing lots and lots of files on GNU/Linux

Well, rm * just won't do. Use find:

find . -name 'somenamemask*' -type f -print -delete

Deny execute in a directory on Windows

IO - Inherit Only (i.e. this does not apply to the container itself, only to it's children)
OI - Objects Inherit (i.e. this works on files, not on directories; this can be combined with CI which is Container Inherit)
X - eXecute obviously

icacls download /deny everyone:(IO)(OI)(X)

That annoying "Address already in use" error

If you're able to modify the application:

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)  # ADD THIS LINE BEFORE BIND
server_socket.bind(('0.0.0.0', 443))
server_socket.listen(256)

System-wide disable (a little heavy handed, since this protection is there for a reason, but sometimes worth it):

echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle

See also the official documentation.

Chrome's "always show full URL"

chrome://flags/#omnibox-context-menu-show-full-urls
Then restart, right-click on the URL bar and select "Always show full URLs".
【 design & art by Xa / Gynvael Coldwind 】 【 logo font (birdman regular) by utopiafonts / Dale Harris 】