Categories
Unix Notes

Named Forks

named forks – resource forks

mac 122 % ls -al *.dmg
-rw-r--r--  1 face  staff  1189642 Nov 26 09:12 SQLGrinderPR3.dmg
mac 123 % ls -al *.dmg/..namedfork/rsrc
-rw-r--r--  1 face  staff  0 Nov 26 09:12 SQLGrinderPR3.dmg/..namedfork/rsrc
mac 124 % ls -al *.dmg/..namedfork/data
-rw-r--r--  1 face  staff  1189642 Nov 26 09:12 SQLGrinderPR3.dmg/..namedfork/data
mac 125 % ls -al *.dmg/..namedfork/r
ls: *.dmg/..namedfork/r: No such file or directory
mac 126 %
Categories
Unix Notes

Open current directory in Finder

From the Terminal app…

open .

to open the current directory in the Finder.

That’s open-space-period

Categories
Unix Notes

fsck on reboot

Using Disk Utility from the startup cd, or booting to single-user mode (hold down command-s just after chime) and at the “#” prompt type “fsck -y” repeat that command until no errors are reported, then type “exit” your mac will continue to boot.

Categories
Unix Notes

Short-circuit shell commands

mac 131 work % [[ "a" > "A" ]] && echo fred
fred
mac 132 work % [[ "a" > "A" ]] || echo fred
mac 133 work % [[ "a" > "A" ]] && [[ "a" < "n" ]] && echo fred
fred
mac 138 work % foo="9"
mac 139 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 140 work % echo $foo
defaultString
mac 141 work % foo=" Some String"
mac 142 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 143 work %
mac 143 work % echo $foo
defaultString
mac 144 work % foo="Some String"
mac 145 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 146 work % echo $foo
Some String
mac 147 work % foo=""
mac 148 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 149 work % echo $foo
defaultString
mac 150 work %
Categories
Unix Notes

basename and dirname

basename and dirname are programs – read process creation. Shell substitution can be much quicker and far more obscure.

basename is ${ARG##*/}

dollar-leftcurlybrace-A-R-G-sharp-sharp-asterisk-slash-rightcurlybrace

dirname is ${ARG%/*}

dollar-leftcurlybrace-A-R-G-percent-slash-asterisk-rightcurlybrace

Categories
Unix Notes

Change the prompt in "sh"

I set my prompt in .profile to

PS1="%m %! %c %# "; export PS1

which gives me host – command number – last part of path – # or % depending on root or not…

Categories
Unix Notes

LDAP search from the command line

Get a name, dbkey, and email address from ldap

ldapsearch -hldap.arizona.edu -LLL -x
“(mail=*payne*@*arizona.edu)” dn mail
|
perl -p -i -e
‘ s/.*cn=(.*)+dbkey=([0-9]+),.*/1~2/; s/mail: (.*)/1/’

all of that on one line – or use the continuation characters

Categories
Unix Notes

immutable flag on files

locked files got you down? might be immutable. see “chflags”

uchg set the user immutable flag (owner or super-user only)

The chflags command is your friend.

Categories
AppleScript Notes Unix Notes

Scripting Terminal.app

tell application "Terminal"
 do script with command "top -u -s10 10"
 set number of rows of window 1 to 18
 set number of columns of window 1 to 80
 set background color of window 1 to "black"
 set normal text color of window 1 to "yellow"
 set custom title of window 1 to "Top"
 set miniaturized of window 1 to true
end tell