# niutil -create . /machines/tower # niutil -createprop . /machines/tower ip_address 10.0.1.155 # niutil niutil -createprop . /machines/tower serves ./local
/System/Library/StartupItems/SystemTuning/SystemTuning
tweak some values, like
sysctl -w kern.sysv.shmmax=167772160 # bytes: 160 megs sysctl -w kern.sysv.shmmin=1 sysctl -w kern.sysv.shmmni=32 sysctl -w kern.sysv.shmseg=8 sysctl -w kern.sysv.shmall=65536 # 4k pages: 256 megsSave, and restart your system.
On some Panther seeds, you may need to add these things to /etc/rc
/etc/rc
, but you want to be able to back out your changes. You also want to preserve the original timestamp of the file. That way if you back out your change, someone else coming along doesn't have to figure out "why did /etc/rc
change yesterday, it doesn't look any different?" Here's how:
% sudo mv rc rc-orig
% sudo cp rc-orig rc
% sudo vi rc
% sudo mv rc-orig rc
Thereby undoing your changes, and not messing up the timestamp of the original file.
(mucho thankos to Louis Bertrand for this one)
$HOME
directory, plus the /Applications directory. There's probably other stuff that should be snarfed (like /Library
), but I didn't on my last backup, and doing a restore from scratch seemed to work OK. Here's a quick outline of backing up to the external firewire drive called "Wikkit":
% sudo mkdir /Volumes/Wikkit/backup
% cd /Users
% sudo hfstar cf - bork | (cd /Volumes/Wikkit/backup; sudo hfstar xf -)
To Restore:
% cd /Users
% sudo mv bork bork-orig
% cd /Volumes/Wikkit/backup
% sudo hfstar cf - bork | (cd /Users; sudo hfstar xf -)
Some folks have had success with psync, but we haven't used it yet.
~/.inputrc
file:
set completion-ignore-case On
Then when you type ls /appli
in the shell you'll get ls /Applications/ like you ought to!
% ~/bin/rename.pl 's/.oop$/.ack/' *.oop
To tack on an extension to all files, do something like
% ~/bin/rename.pl 's/(.*)/$1.jpg/' *
% perl -pi -e 's/\r/\n/g' mealcsv.csv
tr '\r' '\n' < macfile.txt > unixfile.txt
% hdiutil create -ov -imagekey zlib-level=9 -fs HFS+ -format UDZO -scrub -srcfolder /Path/To/The/Goodies fooby.dmg
# svc -d /service/whatever
- Bring the server down
# svc -u /service/whatever
- Start the server up and leave it in keepalive mode.
# svc -o /service/whatever
- Start the server up once. Do not restart it if it stops.
# svc -t /service/whatever
- Stop and immediately restart the server.
# svc -k /service/whatever
- Sends the server a KILL signal. This is like KILL -9. If svc -t fails to fully kill the process, use this option.
(Thanks to the OpenACS documentation)
% cd /Users/bork/Library/Screen\ Savers
or you can surround it with quotes:
% cd "/Users/bork/Library/Screen Savers"
Note that tilde expansion (~/Library
) is suppressed if you use the quotes.
% screen -r There is a screen on: 8395.pts-0.vikki (Multi, attached)You can boot off that other loser by using:
% screen -d 8395.pts-0.vikkiand then doing
screen-r again
% du -sk dir_name
To see how much each of a directory's contents consume, use
% du -sk dir_name/* | sort -n
to get a list ordered by size.
% otool -s __TEXT __info_plist ./thebinary | xxd -r
Muchos Thankos to Dan Jalkut for this one.
% cd directory
% find . -name "*.h" -exec grep NSDoWhatIMean {} ; -print
{}
construct. Also make sure there's a space after the {}
and ;
-h
flag:
% grep -h chicken ~/Documents/ircLogs/FreeNode/2007*/#macsb*
egrep -h -o '@"[^"]*"' MJFirstViewController.mThe -h suppresses printing the file name, -o is "Prints only the matching part of the line"
find /Volumes/Vikki/ -type f -size +2G -print
% sw_vers
ProductName: Mac OS X ProductVersion: 10.3.7 BuildVersion: 7S215
% ps -eo "%p %P %c"
% find . -type f -perm +06000 -print
(or use find /
to start looking from the root directory.)
fcntl
, all things are possible.
char pathbuf[PATH_MAX]; if (fcntl(fd, F_GETPATH, pathbuf) >= 0) { printf ("wow: %s\n", pathbuf); } else { printf ("oops %s\n", strerror(errno)); }Finding this feature was a surprise, having lived under the assumption that you can't map from a file descriptor to a path in the file system. Obviously things like sockets and pipes will return an error, but it actually seems to work.
% grep -c "fix me" *.m
% curl -O http://borkware.com/quickies/files/fullscreensaver.tar.gz
-l
(dash ell) flag to grep. If a file contains the expression, the name of the file (rather than the matching line) is displayed.
e.g. to open all the files that contain 'rzolf'
% grep -l rzolf *.ham | xargs open
-e
option to the rescue:
% grep -e -H filename
hoover Greeble NI POPand file2.txt had the contents
bork Bork BORKInterleave them with
% paste -d '\n' file1.txt file2.txt > blargand get
hoover bork Greeble Bork NI POP BORK
% hdiutil mount diskimage.dmg
LANG
environment variable to be en_US
to make it happier.Once you've totally finished panicking and starting your recovery plan ("dammit now I'll lose a day's work getting this to a genius and re-cloning my repos to another machine") the memory has finished swapping in and the machine wakes. "Hi! Now that you're completely carbonated, let's get back to work!"
Unsurprisingly, major OS updates seem to reset this value. (Firmware updates may do it too.)
(This may be incomplete - I have a couple of days still to make sure it totally works)
Turn off hibernation with:
# sudo pmset -a standby 0 # sudo pmset -a hibernatemode 0
% defaults write com.bignerdranch.bigshow NSQuitAlwaysKeepsWindows -bool false(thanks to Step Christopher for this one)
experimental
:
% find . -path ./experimental -prune -o -name "*.swift"
% rm -- -i-am-a-bad-file
% ls -l total 18192 -rw-r--r--@ 1 markd staff 13354 Jan 5 18:46 Icon-114.png -rw-r--r--@ 1 markd staff 21379 Jan 18 10:56 Icon-152.png -rw-r--r--@ 1 markd staff 484470 Jan 5 18:40 Icon-167.png ...Which are quarantine tags:
% ls -l@ total 18192 -rw-r--r--@ 1 markd staff 13354 Jan 5 18:46 Icon-114.png com.apple.quarantine 61 -rw-r--r--@ 1 markd staff 21379 Jan 18 10:56 Icon-152.png com.apple.quarantine 61 -rw-r--r--@ 1 markd staff 484470 Jan 5 18:40 Icon-167.png com.apple.quarantine 61Get rid of them with this:
% xattr -d com.apple.quarantine *
% perl -pi.bak -e 's/OLDSTRING/NEWSTRING/g' *.html
% find . -type f -name "*.html" -exec grep Spoon {} ; -print
/Volumes/Media2
% rsync -avz -e ssh --progress 'biggun.local:/Volumes/Video/AppleTV\ Videos/Exercise' /Volumes/Media2I can never remember what the flags mean, so:
% sudo sh -c "tar cf - * | (cd /mirror4/web; tar xf -)"
% xmllint -noout kipple.xml
Handy for a quick check after hand-editing a file.% gcc -v --help
ls -l
:
% ls -l ~/junk/SnapshotRepository.sparseimage -rw-r--r--@ 1 markd markd 135270400 Jul 24 20:38 /Users/markd/junk/SnapshotRepository.sparseimageThat means there's some extended attributes. use
ls -l@ to see them
:
% ls -l@ ~/junk/SnapshotRepository.sparseimage -rw-r--r--@ 1 markd markd 135270400 Jul 24 20:38 /Users/markd/junk/SnapshotRepository.sparseimage com.apple.diskimages.fsck 20
comm
.
Here I'm wondering if any objc files in the current directory also exist in the Classes subdirectory
% ls -1 *.[hm] *.xib | sort > oopack % cd Classes % ls -1 *.[hm] *.xib | sort > ../oop2 % cd .. % comm -12 oopack oop2The
-12
suppresses lines only in file1, and lines only in file2. I'm more interested in their intersection.% tail -f /var/tmp/console.log
% unzip -l snorgle.zip
ppid
option with the -o
flag:
% ps -axo user,pid,ppid,vsz,tt,state,start,time,command
% defaults write com.apple.PowerChime ChimeOnNoHardware -bool true % sudo killall PowerChime
So, trick sort into using the last field (with a colon separator) as the sort key:
% grep -c translatesAuto *.xib | sort -t: -n -k2
^t
is the hotkey, doing ^t ^g
will toggle the visible bell on and off.% cat some-unformatted-manifest.json | python -m json.tool(courtesy of Chris Donnelly)
% find . \( -name "*.jpg" -or -name "*.gif" \) -exec do_something_with {} ;
% find . -name "*.jpg" -exec convert -verbose -geometry 150x150 {} {} ;
% identify filename.jpg
If you want to be studly, you can use -format
to tailor
the output
% identify -format "insert into bw_graphics values (generate_primary_key(), '/images/llamas/%f', %w, %h);" *.jpg
generates a sql insert
statement for each image.
nm
outputs a three-column format. I needed to get the set of defined symbols (in particular those that start with __
, in tracking down a C++ linking problem), which is the third column. awk
is good for that. Use $N
to get the nth column (zero-index). This pipeline did the trick:
nm ./oopack.o | awk '{print $2}' | sort | grep __(Thanks to DougEDoug for the pointer)
% awk '{ for (f=1; f <= NF; f++) { if (f != 1 && f != 9) printf("%s ", $f);} printf(" ");}' < ook.txtOr you can put this at the end of a pipeline instead of directing a text file into the command. (courtesy of DougEDoug)
% tar cf - ./stuff | ssh theOtherMachine "tar xf -"
% cd /Users/bork/development/cool\ stuff/neat\ things
The other is to use shell completion to put in the backslashes for you. In
the above path, if you type
% cd /Users/bork/development/cool[tab]
, it'll expand
"cool stuff
" for you.
cp -R
is generally unsafe to copy directories with since it will copy through symbolic links rather than just copying the link (newer cp
's have an -H flag that will work around this). The classic unix way of doing things like this is a push-pull tar
:
% tar cf - dir-name | (cd /destination-dir; tar xf -)
In English: tar out through a pipe into a subshell that's changed directories, feeding that pipe into the tar extraction. If you run both sides of the pipeline as root (via sudo
), the file owners and permissions will be preserved (which cp
won't do)
rf
command to append to an archive rather than creating one:
% find . -name "*.yuck" -print0 | xargs -0 tar rvf oop.tar
-print0
(zero) tells find to output the filenames with trailing NUL characters (rather than newlines), and -0
tells xargs to use a NUL as its input separator, rather than newlines/spaces. The upshot is that you can handle filenames with spaces in them.
Thanks to Ben Cox for the -print0 / -0 suggestion.
% ssh-keygen -t rsa
% scp ~/.ssh/id_rsa.pub gitdown.com:
% cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
mv: rename build/ to oopack: Is a directorywhen using
mv
or ln
on the command line, that's a Darwin error. To correct the problem, remove the trailing slash from the directory name.% sudo tcpdump -Atq -s 0 -i en1
-i en1
will display traffic on your airport card. Use en0
(or nothing, for most systems) for built-in ethernettage.
You can add a host line to limit output to a particular host
% sudo tcpdump -Atq -s 0 -i en1 host zombo.com(thanks to Dan Jalkut for this one)
% launchctl stop com.apple.Dock.agent % launchctl start com.apple.Dock.agent
// Boot into single-user mode with command-S on power-on # /sbin/fsck -fy # /sbin/mount -uw / # mv /var/folders /var/folders-dorked # rebootNearly instant boot again.
touch
. You can specify a specific date or time using the format [[CC]YY]MMDDhhmm[.SS]]
. Here's an example with alternating bolds to make it easier to read:
% touch -t 200703141536 snork.waffle % ls -l snork.waffle -rw-r--r-- 1 markd markd 298 Mar 14 15:36 snork.waffle
% hdid ram://size
where size is the size in bytes. the system will round that number up or down as it sees fit.% sw_vers -productVersion 10.5.1
/usr/bin/drutil info
to get a listing of the kinds of media your drive supports. For example, on the 17" iLamp:% drutil info Vendor Product Rev PIONEER DVD-RW DVR-104 A227 Interconnect: ATAPI SupportLevel: Apple Shipping Cache: 2000k CD-Write: -R, -RW, BUFE, Test, IndexPts, ISRC DVD-Write: -R, -RW, BUFE, Test Strategies: CD-TAO, CD-SAO, DVD-DAO
chflags
in Mac OS X works like chattr
over in Linux-land. So to make a file immutable (can't change it, even if you're the superuser), you can sudo chflags uchg file-name(s)
. To undo it, do sudo chflags nouchg file-name(s)
emacs
inside of screen
is made difficult because both want to use C-A for something important. C-O (AFAIK so far) isn't too useful for my use of emacs, so I use that for screen now:
screen -e^Oo emacs
screen -r