tinyapps.org / blog

Saving colorized output from Bash #

even from programs like testdisk, in which output may span many separate screens:

Text-based output:

  1. Install aha: $ sudo apt install aha
  2. $ sudo testdisk | tee >(aha --black>output.html)
  3. After quiting testdisk, type exit on the command line. Find output.html in the current directory.

Graphic-based output:

  1. $ sudo apt install imagemagick ttyrec gcc x11-apps
  2. $ git clone https://github.com/icholy/ttygif.git
  3. $ cd ttygif
  4. $ make && sudo make install
  5. $ ttyrec
  6. Run desired command(s), e.g., $ sudo testdisk
  7. Type exit when finished
  8. Convert ttyrec's output file (ttyrecord by default) to tty.gif in the current directory: $ ttygif ttyrecord

Sources & More

/nix | Mar 05, 2017

List all files on disk #

Even as root, ls and find produced too many errors ("Permission denied", "Not a directory", "directory causes a cycle", "Input/output error", etc) when attempting to list all files on disk. Tree worked a treat:

$ tree -a -i -f / > filesystemlist.txt

 -a All files are listed.
 -i Don't print indentation lines.
 -f Print the full path prefix for each file.
See also Tree for Windows and LINUX Recursively list all files in a directory including files in symlink directories.

/nix | Feb 06, 2017

Convert asciidoc to markdown #

  1. Install pandoc and asciidoc

    $ sudo apt install pandoc asciidoc

  2. Convert asciidoc to docbook

    $ asciidoc -b docbook foo.adoc

    foo.xml will be output into the same directory as foo.adoc

  3. Convert docbook to markdown

    $ pandoc -f docbook -t markdown_strict foo.xml -o foo.md

  4. Unicode symbols were mangled in foo.md. Quick workaround:

    $ iconv -t utf-8 foo.xml | pandoc -f docbook -t markdown_strict | iconv -f utf-8 > foo.md

  5. Pandoc inserted hard line breaks at 80 characters. Removed like so:

    $ iconv -t utf-8 foo.xml | pandoc -f docbook -t markdown_strict --wrap=none | iconv -f utf-8 > foo.md

/nix | Jan 24, 2017

Compare / diff disk images and other large binary files #

with lfhex (Large File Hex Editor). Installation in Debian-based distros is as easy as # apt install lfhex, but that version is sadly plagued with a long-standing bug which hides the (very handy) "Cursor Offset" selection box:
lfhex missing Cursor Offsetlfhex with Cursor Offset
lfhex missing cursor offsetlfhex with cursor offset

As Kalle Olavi Niemitalo explains in the aforementioned bug report, removing statusBar()->showMessage("Ready",2000); from hexGui.cpp before compiling works, but only if you have older versions of Qt, gcc, g++, etc. to compile with (or manage to resolve compatibility problems like this one).

After several false starts, I got a x64 binary compiled under Ubuntu 12.04, gcc 4.6.3, and Qt 4.8.1. Works fine under newer Debian-based distros as well.

See also wxHexEditor, a cross-platform (Linux, Windows, OS X), open source hex editor with support for very large files (up to 2EB) and raw disk access (under POSIX systems). The current version, 0.23 beta, is available via # apt install wxhexeditor.

UPDATE 1: Just noticed this on the lfhex homepage under "Limitations": "Search/compare can be slow (compared to cmp or any other non-paged IO app)". Note that cmp -s is faster than just cmp and roughly equal to diff -q. More info. Tip: If you just need to know whether two large files differ, first check the file sizes. Only then if necessary run: diff --speed-large-files --brief --report-identical-files file1 file2.

UPDATE 2: To compare two files, run $ lfhex -c file1 file2 (there isn't a comparison option within the GUI, though the preceding command will launch the GUI in comparison mode).

/nix | Nov 05, 2016

Interrupt PhotoRec recovery, change the destination, and resume #

During a PhotoRec session, if disk space on the destination starts running precariously low, you can interrupt the session, change the destination, and resume like so:
  1. Halt the session and exit PhotoRec: Stop > Y > Quit > Quit > Quit
  2. If desired, move recup_dir.* to new destination (while not required, you may wish to keep all of the recovered files together). In any case, do not move or edit photorec.ses, which is located in the current working directory)
  3. Launch PhotoRec again
  4. When "Continue previous session ? (Y/N)" prompt appears, press Y
  5. Browse to new destination directory then press C
  6. Recovery will resume where it left off

/nix | Oct 24, 2016

Mounting partitions from full disk images with guestfish #

Just added a long-overdue update to Mounting partitions from full disk images with guestfish, part of the inimitable libguestfs:
"libguestfs can access almost any disk image imaginable. It can do it securely — without needing root and with multiple layers of defence against rogue disk images. It can access disk images on remote machines or on CDs/USB sticks. It can access proprietary systems like VMware and Hyper-V."

/nix | Oct 02, 2016

Installing ddrescue in Debian, Ubuntu, Mint, et.al. #

A few ddrescue install tips for Debian-based distros:

/nix | Sep 30, 2016

A lickable Linux distro #

Apricity OS is an Arch-based Linux distribution with a simple, beautiful, and consistent UI:

Apricity OS

According to the developers, "Apricity OS idles at around 500 megabytes of memory usage, as opposed to other popular operating systems that idle at up to several gigabytes. This also helps bring boot times down to just a few seconds." I found it fast and responsive running in a VM with just 2GB of RAM. Love the little coffee cup icon in the menu bar which functions much like OS X's caffeinate, though it has the added benefit of disabling the screensaver as well.

(via Hacker News)

/nix | Apr 03, 2016

Ubuntu Linux: "Wi-Fi is disabled by hardware switch" #

A weedy wireless on/off switch on an ancient Sony VAIO laptop suddenly started acting up:
Wi-Fi Network (Intel Vaio VGN-SZ795N C)
Wi-Fi is disabled by hardware switch
No problem - let's plug in a USB wifi adapter:
Wi-Fi Network (Intel Vaio VGN-SZ795N C)
Wi-Fi is disabled by hardware switch

Wi-Fi Network (Realtek 802.11n WLAN Adapter)
Wi-Fi is disabled by hardware switch
That's strange:
$ rfkill list
0: phy0: Wireless LAN
	Soft blocked: no
	Hard blocked: yes
1: phy1: Wireless LAN
	Soft blocked: no
	Hard blocked: no
$ sudo rfkill unblock all
$ rfkill list
0: phy0: Wireless LAN
	Soft blocked: no
	Hard blocked: yes
1: phy1: Wireless LAN
	Soft blocked: no
	Hard blocked: no
Won't bore you with all of the dead ends I explored (booting from a live CD, resetting the BIOS, removing the battery and draining the capacitors, performing all manner of mudras with the wifi switch, running a slew of esoteric commands I don't remember, etc); happily, I finally stumbled, exhausted, on Pfistodactyl's concise answer for disabling the built-in wifi adapter:
  1. $ lspci -v
  2. Note the value of "Kernel driver in use:" for the onboard wireless LAN controller (e.g., "iwl4965")
  3. Add the following line to /etc/modprobe.d/blacklist.conf: "blacklist iwl4965" (without quotes)
  4. Reboot
Happiness restored!

/nix | Dec 24, 2015

Cross-platform, ad hoc, recursive file transfer via HTTP #

Recursively copy desired_dir located on server to current directory on client without having to fool around with usernames, passwords, config files, FTP, NetBIOS, Bonjour, etc:

On server: cd desired_dir && python -m SimpleHTTPServer

On client: wget -r -np http://server_ip_address:8000/

/nix | Jun 21, 2015

Subscribe or visit the archives