We tend to use a lot of commands in the Terminal app. That is, after all, what it’s there fore. And there’s a nice history of what we do. There are also a number of ways to view and manage the bash history. The simplest of which is the history command, which will show the previous commands run. Here, we’ll simply run it:
Keep in mind that this shows the history based on context, so if you sudo bash, you’ll potentially see a different history. You can also use the bash built-in fc command, which has the additional awesomeness of being able to edit and re-run commands from the history. To start, we’ll simply look at showing the last 16 commands using the -l option:
You can also constraint entries in the output by specific line numbers. For example, to see lines 12 through 18, simply use them as the first two positions of the command after fc:
fc 12 18
You can load the history into an editor and remove or add entries using fc without any options:
To exit the editor, hit control-z. I’ve written in the past about using substitution. For example, sudo !! to run the last command. fc can do some basic substitution as well. For example, use the -s to start substation and then enter a string, which will append whatever you like before a command. So the following would put sudo in front and re-run the previous command:
fc -s sudo
And let’s say that you were doing a find for a string of krypted. To then swap that string with charles:
fc -s krypted=charles
Overall, the bash history can be incredibly useful. I frequently pipe the output of a series of lines into a new file with a .sh at the end as a starting point for scripts and use these substitution options to save myself a bunch of time not retyping longer commands. Enjoy.
krypted August 14th, 2015
I missed posting this one back in November. I’m slow… It’s from an interview I did a little while back. http://tech.mn/news/2014/11/04/jamf-software-bushel-apple-device-management/
Mostly, these are placeholders so I can find interviews I’ve done easily… #bushel
krypted August 11th, 2015
There’s a quick and easy IT Business Edge slideshow at http://www.itbusinessedge.com/slideshows/the-5-mobile-apps-you-really-need-for-smb-success.html that I helped with about 5 Mobile Apps You Really Need for SMB Success.
Hope you enjoy!
krypted August 10th, 2015
Little article I/Bushel contributed to from Tech Republic covering considerations for small businesses looking to move to the Apple platform. It’s available at http://www.techrepublic.com/article/5-considerations-for-smbs-that-want-to-move-to-apple/#ftag=RSS56d97e7.
krypted August 9th, 2015
I’ve always found the easiest way to script the volume of an OS X computer (and when I say volume I mean sound level, not a logical volume created from partitioning a hard drive – but I have articles for scripting those as well) is using the osascript command to invoke an Applescript command that sets the volume to zero. To put some syntax around this:
osascript -e "set volume 0"
krypted August 6th, 2015
You can query whether a process is running by name. You can do this with ps and pipe the output to grep. It’s not hard, but you can do this more quickly with pgrep. You can also kill that process with pkill. Which includes the ability to send a signal.
So, let’s look at closing down iTunes with pkill:
Or we can send it with a signal (9):
pkill -9 iTunes
Or you could just grab the pid of a process by name:
It might display:
And that’s it. Easy Peasy.
krypted August 2nd, 2015
Safari has a bookmarks bar. Some people want to hide it. A lot of people used to do stuff like this by modifying the default user template in OS X. Not something we’ll be doing much in the future. So to do so with a script:
defaults write com.apple.Safari ShowFavoritesBar -bool false
To turn it back on:
defaults write com.apple.Safari ShowFavoritesBar -bool true
krypted July 31st, 2015
As of OS X 10.9 (and in many cases more importantly in OS X Server for 10.9 and higher), OS X now performs ARP cache validation when trying to pass traffic over a router. If you are double NAT’d/use redundant gateways then the traffic can be interpreted as network redirection and cause some pretty bad packet loss/latency. You can disable this feature by turning off net.link.ether.net.arp_unicast_lim using sysctl:
sysctl -w net.link.ether.inet.arp_unicast_lim=0
That will only disable unicast arp validation until the next reboot. If it fixes a latency problem you’re having then you can go ahead and make it permanent by adding the following line into /etc/sysctl.conf:
If you’re still having issues with latency, you should turn it back on. To enable it again, repeat, swapping the 0 with a 1.
krypted July 19th, 2015
So a few months ago, closing in on 3,000 posts, the database got too big and krypted.com started suffering from innodb corruption, resulting in database outages. While I was able to get the site up, it was using a read-only database that kept me from doing any new articles or updates. It was a strange time in my life, like suddenly being single after living with someone since Y2K (when I started the site). But I got through it and was able to repair the relation… er, site. Now, with a new database that is free from corruption we’re ready to get to 6,000 posts!
Also, I had a little feedback on the usability of the site. I had thought people would scroll down to find the search box. Apparently there’s a reason most sites put it at the top. It’s now there here. I also made a couple of new pages (in addition to the articles I’ve been posting since it came back up) and removed a couple of pages. Most of the pages have gotten fresh information and had at least something retired. No changes to articles in all of this, just pages.
Finally, I know I’ve made this offer in the past, but I welcome any guest authors that would love a place to store their stuff. Talk about anything technical you’d like, from Arduino to BRU to Casper to Munki to OpenMDM to Linux to PowerShell. It should just be technical…
krypted July 17th, 2015