Skip to main content
Answer

OT: totally awesome 'defaults' find

  • March 28, 2012
  • 15 replies
  • 43 views

Forum|alt.badge.img+24

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.

Best answer by bbass

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.

15 replies

Forum|alt.badge.img+13

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

that's standard *nix stuff, jj!


Forum|alt.badge.img+31
  • Honored Contributor
  • March 28, 2012

Jared,

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

-Tom


Forum|alt.badge.img+24
  • Author
  • Valued Contributor
  • March 28, 2012

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


Forum|alt.badge.img+7
  • Contributor
  • Answer
  • March 28, 2012

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.


Forum|alt.badge.img+8

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


Forum|alt.badge.img+31
  • Honored Contributor
  • March 29, 2012

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
Forum|alt.badge.img+24
  • Legendary Contributor
  • March 29, 2012

@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
Forum|alt.badge.img+36
  • Community Manager
  • March 29, 2012

Nifty!


Forum|alt.badge.img+31
  • Honored Contributor
  • March 29, 2012

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


ImAMacGuy
Forum|alt.badge.img+23
  • Esteemed Contributor
  • March 30, 2012

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


donmontalvo
Forum|alt.badge.img+36
  • Hall of Fame
  • March 30, 2012

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

Don


Forum|alt.badge.img+12
  • Contributor
  • May 4, 2012

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 :)


Forum|alt.badge.img+31
  • Honored Contributor
  • May 4, 2012

@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.


Forum|alt.badge.img+12
  • Contributor
  • May 4, 2012

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.


Forum|alt.badge.img+19
  • Contributor
  • May 4, 2012

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.