Tiny Deathstars of Foulness

I have been known to occasionally ask what build number of Mac OS X that someone is using. The sw_vers command can be used to obtain this. Simply run:
And the BuildVersion will be listed. Or just to get the BuildVersion:
sw_vers | grep BuildVersion
Or to just get the number (useful in scripts that catalog such a thing:
sw_vers | grep BuildVersion | cut -c 15-21
As one comment just indicated, you could also just use `sw_vers -buildVersion`. I guess I should review these commands every operating system or 4… Thanks Allen.

February 4th, 2010

Posted In: Mac OS X, Mass Deployment

Tags: , , , , ,

A number of commands available for finding positions that you want in a line and extracting only a certain amount of text can be pretty cumbersome in terms of learning curve. This isn’t to say that once you get the hang of them that they’re terribly complicated but it can take a little while to get the hang of them. And when you need something fast, you might want an easy command for extracting text from lines. In these cases, consider cut. The cut command doesn’t do regular expressions (I guess you could argue that its ability to use a delimiter can be used as a regular expression) and so it’s really easy to use. Basically, you feed cut some data and then tell it which characters in the line that you want to keep. It then gets rid of the rest. The easiest use of this is to look at a list of data. For example, let’s saw we have a file called test.txt with the following contents:
abc123 abc124 abc134 abc234 abd234 acd234
Now we’re going to cat the file (which just reads the file contents) and then pipe the output of reading that file into a cut command (which is done by simply adding a pipe character at the end of the first part of the command. Then we’re going to use the -c option of cut (which looks at character positions) to simply grab the first three positions (1-3) of the lines. The command would end up looking as follows:
cat test.txt | cut -c 1-3
And the output would look as follows (this output could then be redirected into a new file btw):
abc abc abc abc abd acd
You can also specify multiple ranges of characters (or single characters for that matter). For example, to see only characters 1-2 and 5-6:
cat test.txt | cut -c 1-2,5-6
Overall, cut is a very easy to use tool, with a limitation that your pattern that you are looking to maintain must be consistent in terms of the character position that you are using in each line. It also uses every line in a file; however, to go another step and look for all positions in a line only if the line has a pattern that it can match you could simply add a grep in the middle. For example, if you’re looking for each line of our sample text file that has the number 4 then you could do:
cat test.txt | grep 4
This would show you only the last five lines of the file since those are the only lines that have that number in them. You could then pipe the output of that file into your cut and, let’s say, look for characters 1-3 and 6 in the output:
cat test.txt | grep 4 | cut -c 1-3,6
Your result would then be the following:
abc4 abc4 abc4 abd4 acd4
Finally, there are going to be times when you’re not looking for a specific character position in a line but instead a character position or a pattern that begins with another pattern. For this you’re going to end up needing to use a more advanced tool, such as awk or if you’re feelin’ frisky (maybe I’m speaking for myself there) regex. These tools will have a steeper learning curve, but ultimately be far more useful.

January 17th, 2010

Posted In: Mac OS X, Mac OS X Server, Mac Security, Unix

Tags: , , , , , , , , ,

Ever seen in a launchctl list?  Wondered what it did?  This is the infamous clipboard (aka – pasteboard, or on the iPhone the NSPasteboard server).  If you unload the pboard entry in launchctl then you will no longer be able to cut, copy and paste.  pboard relies on the existence of and the accessibility to the user that initiated pboard (ie – root) to have access to the /tmp folder.  Therefore, pboard will be wonky without /tmp and without pboard you won’t be able to paste things.  So, when troubleshooting cut, copy and paste issues, first verify that /tmp exists and then verify that pboard is running using the following command:
launchctl list | grep
And if it isn’t running, start it with:
launctl start

June 29th, 2009

Posted In: Mac OS X

Tags: , , , , , , ,

You can set the cut function of the Finder to move items into the trash rather than into the clipboard: defaults write AllowCutForItems true It’s not the nicest of jokes to play on people though… So to undo it: defaults write AllowCutForItems false Happy April Fools Day

April 1st, 2005

Posted In: Mac OS X

Tags: , , , ,