OT: totally awesome 'defaults' find

jarednichols
Honored Contributor

Perhaps everyone already knows this, but I just found this to be awesome:

So, I'm mucking around in /var/db/dslocal/nodes/Default/users. There's lots of users' plist files. Now, I want to see the contents of one of these so I do a

defaults nobody.plist

and in response, I get

Domain nobody.plist does not exist

Well, "that's annoying," I think to myself, knowing I'm now going to have to type the full path to the .plist to see its contents.

Not so much, as it turns out.

Instead I did a

defaults read `pwd|nobody.plist`

and out spat my plist contents.

Not sure why I never tried that before, but I did just now and it's a good one to share. Sure there's a little bit more typing but it's better than the full path, IMHO.

Cheers.

2 ACCEPTED SOLUTIONS

bbass
Contributor

The following commands return different results:

defaults read `pwd`/nobody.plist
defaults read `pwd|nobody.plist`

They both offer output but the first one seems to return the proper results.

View solution in original post

tlarkin
Honored Contributor

Hey Everyone,

If if makes any of you feel better I just discovered this a while back ago recently. If you are in an open terminal session, and want to view a man page in a separate window, just type in the command, highlight it with the mouse, and then right click it and view man page. It will open up the man page in a nice new bright yellow window. I have NO CLUE when this became an available feature. I only discovered it after finally upgrading to Lion a few months back.

@ Joel -
I have been following your scripts here and checked out your website, good work man! Keep it up!

Thanks,
tom

View solution in original post

15 REPLIES 15

rockpapergoat
Contributor III

don't you mean `pwd`/user.plist?

that's standard *nix stuff, jj!

tlarkin
Honored Contributor

Jared,

So, now we will expect you to be growing out your "Unix beard!"

-Tom

jarednichols
Honored Contributor

D'oh. Holy cow how'd I miss that one. It still worked, even.

Don't look now but the emperor is wearing no clothes. haha

bbass
Contributor

The following commands return different results:

defaults read `pwd`/nobody.plist
defaults read `pwd|nobody.plist`

They both offer output but the first one seems to return the proper results.

yr_joelbruner
New Contributor III

Another variation using the $() style, helps me with readability:

defaults read $(pwd)/nobody.plist

The Bonus for me was I always hated how defaults would complain when you put .plist at the end, but now I realize when you specify a path and it's not in domain lookup mode you can keep the .plist - I can clear out some ".plist" suffix trimming code from some scripts now :) Thanks

tlarkin
Honored Contributor

Hey Everyone,

If if makes any of you feel better I just discovered this a while back ago recently. If you are in an open terminal session, and want to view a man page in a separate window, just type in the command, highlight it with the mouse, and then right click it and view man page. It will open up the man page in a nice new bright yellow window. I have NO CLUE when this became an available feature. I only discovered it after finally upgrading to Lion a few months back.

@ Joel -
I have been following your scripts here and checked out your website, good work man! Keep it up!

Thanks,
tom

mm2270
Legendary Contributor III

@Tom, dude that is sweet! Never knew you could open man pages like that. I've always just opened another tab or window in my Terminal to access those. I definitely need to start using that one! Thanks for the tip! :)

talkingmoose
Moderator
Moderator

Nifty!

tlarkin
Honored Contributor

Haha, yeah I just discovered that maybe a month ago. I stumbled upon it by accident. Then I googled it and saw that OSXdaily.com had it documented. Need to visit that site more often I guess.

Though, I am not sure if it updates when the OS updates, so it still may be "best practices" when using Apple command line binaries to look the man page up on the dev website to see what has been changed in different versions, if anything at all.

Cheers!

Tom

jwojda
Valued Contributor II

I don't get it - what type of scenarios would this be helpful?

donmontalvo
Esteemed Contributor III

@jwojda Laziness...smartness...kind of like typing "sudo !!" to repeat the previous command using sudo.

Don

--
https://donmontalvo.com

rmanly
Contributor III

A couple things.

  1. @tlarkin grats on the new job

  2. man page lookup is a nice find. I used to just open another Terminal window to do this before. Back in the day I used to do this to open them in Preview.

pman () {
        /usr/bin/man -t "${1}" | /usr/bin/open -f -a /Applications/Preview.app
}
  1. I ran a File Activity DTrace Instrument while doing the contextual menu man page lookup and it is in fact reading from the man page at /usr/share/man/x/x so the new pop-up view will be updated as long as the man page itself is :D

** now the fun project is to see if I can make it not yellow.

EDIT: there is a Window Setting for 'Man Page' in Terminal Prefs. Excellent :)

tlarkin
Honored Contributor

@rmanly Thanks man, I am pretty stoked to be aboard here!

Also, here is something I wrote a long time ago. I actually stole the idea from someone else, but hey who is actually original these days?

function woman {
  tmpfile="/tmp/man ${*}.pdf"
  if [ ! -f "${tmpfile}" ]
  then
      man -t "${*}" | pstopdf -i -o "${tmpfile}"
  fi
  open "${tmpfile}"
}

Just put that in your ~/.bash_profile and run woman <man page> and it will open it in PDF. Called it woman because it is "prettier," than man.

Though now with Lion I prefer to use the right click method, works like a charm for me.

rmanly
Contributor III

prettier. HA!

It looks like Sal and the boys threw in a few new surprises.

http://www.macosxautomation.com/lion/terminal.html

Dragging a folder onto the Terminal icon could be a LOT faster in some cases than typing.

Also, I can see dragging a path to the tab bar being useful but I will probably forget and just open a new window or tab anyway.

nkalister
Valued Contributor

about man page viewing . . . bwana is really nice, give it a try:
http://www.bruji.com/bwana/
lets you open man pages in your browser by typing man:<command name> in the browser URL field.
It has a man page search interface in the browser, too.