Posts

Showing posts with the label *nix

Convert unix timestamp to date - Mac Terminal

OSX 10.6.8 date -r *timestampHere*

cURL to REST API

More curl goodness: curl -i -X PUT -H "Content-Type:application/json" \ http://localhost//restserver/index.php/api/key \ -d '{"level":10}' curl -i -X PUT -H "Content-Type:application/json" \ http://localhost//restserver/index.php/api/example/send \ -d '{"username":"me","password":"1234","level":10}' using a file as input: curl -i -X PUT -H "Content-Type:application/json" \ http://localhost//restserver/index.php/api/key \ -d @filename.json

prettify JSON

To pretty print JSON output you can use the command line... so any cURL request returning JSON can be piped to python: curl http://somesite.com/cont/res/ | python -m json.tool or cat somefile.json / python -m json.tool

*nix - split string into lines

I was having trouble with cut, why not use tr (translate)? echo $PATH | tr ':' '\n'

USB boot Debian 6.0.7 on Dell Studio 1537

What a nightmare... I've tried installing linux, to boot from a USB, a fair few times with not a lot of success but at last I've nailed it :) Not without a final big balls up along the way, however! When it comes to the part of the installer where it asks you if and where to install grub (or whatever bootloader) be blooming sure of what you are doing. I can't remember what the exact options were or what I selected but I ended up in the senario where windows would not boot unless the USB was plugged in. If I started the machine without the USB plugged in the you'd see "Welcome to GRUB" and then it complain about not finding some files or another. Basically I think I somehow ended up with Grubs config files on the stick instead of on the HD of the laptop. So after booting off the USB, installing grubs files on it, how to get the PC running windows by default??? (So the wife and kids are happy?) Has to dig out the Vista install disk and repair the MBR...

bash nav

From here: http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-productivity/ Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to the end of the command line Ctrl + u – delete from cursor to the start of the command line Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word) Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor Ctrl + xx – move between start of command line and current cursor position (and back again) Alt + b – move backward one word (or go to start of word the cursor is currently on) Alt + f – move forward one word (or go to end of word the cursor is currently on) Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word) Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word) Alt + u – make uppe...

less navigation

Command line tools, gotta love em, but of you don't use them on a regular basis; how to remember everything? I need to get to grips with a built in terminal editor: vim or emacs? (if anyone decides to start yet another flame war on the back of this don't bother...) I uses nano/pico but that's somewhat limited and as less uses vim navigation it seems another push towards using vim. Anyhoo... here's a site with a few useful shortcuts: http://www.thegeekstuff.com/2010/02/unix-less-command-10-tips-for-effective-navigation/

diff between directories

Whoa, no post for a while...! Compare directory contents using diff: diff -qr dirA dirB | grep -v -e 'DS_Store' -e 'Thumbs' | sort > diffs.txt obviously change dirA & dir B to whats required. *Need to look at the grep filter to ignore all invisible "._" files Found this here: http://hints.macworld.com/article.php?story=20070408062023352

Unix titbits

find . -newermt '30 seconds ago' -print find ('.' = files in current dir and subfolders thereof) -newermt (an option, see man page) (files changed within) '30 seconds ago' -print (don't forget to print the results to std output) :D find . \! -name ".DS_Store" -type f -print find only plain/standard files (-type f) NOT called .DS_Store (\! -name ".DS_Store")(NB escaped !)

Mac OS X - Unix

When MacOS became Mac OS X I was initially skeptical, thought it was slow and not all that... How wrong I was. Amongst a multitude of other things, one of the great aspects of this OS is it's Unix underpinnings. If it hadn't been I'd have probably never dabbled with Unix and the power that comes with the CLI. Nice :)