Skip to content

Instantly share code, notes, and snippets.

View brunneis's full-sized avatar

Rodrigo Martínez brunneis

View GitHub Profile
@brunneis
brunneis / docker-bidirectional-mount.sh
Last active January 9, 2018 17:25
How to launch a Docker container where both the host and the container can share mounted volumes (i.e., loop devices) in a bound path. Share hotplug volumes with Docker.
#!/bin/bash
docker run -ti -v "$(pwd)"/shared_dir:/mnt/shared_dir:rw,shared --privileged ubuntu
@brunneis
brunneis / delete-files-containing-string.sh
Created January 18, 2018 19:03
Delete all files containing a string (for files with very long lines)
#!/bin/bash
SEARCH_PATH="."
MAX_CHARS_PER_FILENAME=50
grep -r "string" $SEARCH_PATH | cut -c 1-$MAX_CHARS_PER_FILENAME | cut -d ':' -f 1 | xargs rm
@brunneis
brunneis / recover-html-from-cache-chrome.md
Last active January 18, 2018 19:07
Recover an html file from Chrome's cache

Do not load the target page until proceed

  1. Go to chrome://view-http-cache/
  2. Open the document you want to restore
  3. Copy the buffer from the second block of hex data to a file (input.txt)
  4. Execute the following command:

xxd -r < input.txt > output.html

@brunneis
brunneis / disable-internal-speaker.sh
Last active February 5, 2018 08:03
Disable motherboard's speaker sound (beep)
#!/bin/bash
# Temporary fix
sudo rmmod -v pcspkr
# Permanent fix
echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist.conf
update-initramfs -u
# reboot
@brunneis
brunneis / remove-dangling-volumes.sh
Created February 12, 2018 11:26
Remove dangling Docker volumes
#!/bin/bash
docker volume rm $(docker volume ls -q -f dangling=true)
@brunneis
brunneis / umount-ancoris-devices.sh
Last active February 15, 2018 12:31
Umount all ancoris devices mounted under $PARENT_MOUNT_PATH path
# Umount all loop devices mounted under PARENT_MOUNT_PATH path
PARENT_MOUNT_PATH="/mnt/ancoris"
# loop devices
sudo umount $(df | grep /dev/loop | grep $PARENT_MOUNT_PATH | awk '{print $1}')
# tmpfs
sudo umount $(df | grep tmpfs_ | grep $PARENT_MOUNT_PATH | awk '{print $1}')
@brunneis
brunneis / secure-erase.sh
Created February 16, 2018 22:54
Secure erase (overwrite all the blocks on the device with random data three times)
#!/bin/bash
DEVICE_ID=/dev/sdx
shred -v $DEVICE_ID
@brunneis
brunneis / current-block-size.sh
Created February 28, 2018 11:43
Get the block size of the partition to which belongs the current directory
#!/bin/bash
stat -c %S -f .
@brunneis
brunneis / vmdk-bd.sh
Created March 1, 2018 15:14
Create a vmdk linked to a real device (VirtualBox)
#!/bin/bash
VBoxManage internalcommands createrawvmdk -filename sda.vmdk -rawdisk /dev/sda
@brunneis
brunneis / lvm-cheatsheet.md
Created March 2, 2018 20:55
LVM cheatsheet

Resize logical volume

lvresize -L +485G --resizefs /dev/fedora/root