Pretty Printing from the Commmand Line

DateTags

JSON

The python standard library provides a json library that can be used to pretty print json.

$  echo '{"this": ["that"]}' | python -m json.tool
{
  "this": [
      "that"
  ]
}

XML

$  echo '<root><foo a="b">lorem</foo><bar value="ipsum" /></root>' | xmllint --format -
<?xml version="1.0"?>
<root>
  <foo a="b">lorem</foo …
more ...

Spinning down a Harddrive

DateTags

I wanted to spin down a hard drive before disconnecting. I have an external hard drive and even after I unmounted the drive the disks were still spinning.

Find the device label of the mounted drive:

$ lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda    253:0    0  20G …
more ...

List User Installed Packages

DateTags

I started thinking about doing a fresh linux install and was worried that I might not remember all the packages that I had manually installed. A quick search revealed a one-liner that compares the currently installed packages to the list of packages that were available initially to produce a nice …

more ...

Colored diff on the Command line

DateReadtime 1 minutes Tags

If you wanted your diff output to be colored you have three options

  1. Use a verison control program that outputs colored diff output

    git diff --color=always old-file new-file | less -R
    
    note:Mercurial does not allow you to run its hg diff outside of a repository
  2. Use a text editor …

more ...

Manually Connecting Ethernet

DateReadtime 3 minutes Tags

I broke my computers internet installing wicd.

Getting internet back

  1. Check the interfaces

    $ ifconfig
    
  2. Check eth0 explicitly

    For whatever reason, my eth0 wasn't showing up until I explicitly specified it.

    $ ifconfig eth0
    
  3. Get an ip address

    $ sudo ifconfig eth0 192.168.1.100
    
  4. Connect to the outside internet

    sudo route …
more ...

indent

DateTags

Indent is an program that can reformat C code for you.

Today, someone emailed me their strangely formatted code and I decided before I even looked at it that I would run it through "indent." After looking through the man page for the "correct" flags, I settled on a style …

more ...