-
Easy way to obfuscate shellscripts
Provided the command you actually want to perform is the following:
$ cat file
$ echo “cat file”|xxd -p
6361742066696c650a
This is your desired command in hex format. To execute it you
$ $(echo 6361742066696c650a|xxd -r -p)
the contents of the file be here
Mind the extra $ used to directly execute the outcome. Shout out to Gentooans.
-
*NIX: Know your operating system
Ever wondered where exactly you should copy your binaries? Where to keep temp files? Where symbolic links? Give the following a look:
$ man hier
Hier standing for hierarchy, as you probably figured. You can find both good usable info and just interesting reading.
For future reference, if you need a temporary file, but only for a short amount of time, stick it in /tmp, as seen in a few earlier examples, if you need your temp file to survive a reboot, stick it in /var/tmp.
-
Wget: Downloading recursively
When ever I’ve needed to quickly fetch something for a terminal session off the net I’ve always found curl handy. However, there are still a few things it can’t do and one namely is downloading from online directories recursively flawlessly.
Since I run Macports it’s not much of a problem to quickly get wget running to get the job done, though. The Macports stock installation is some 1.1 Mb or so and a few extra dribbles to install wget by doing
$ sudo port install wget
The dependencies are found and installed automatically. And after a minute or so, depending on your machine, you’ll have the power of wget in your OS X Terminal.
Since I can be lazy even at tech every now and then I didn’t dig into the manpage of wget to find the appropriate flags but instead gave Google a talk for a change. Courtesy of I Still Know What You Learned Last Summer the following snippet will allow you to download the provided url to the current running directory.
wget -rkp -l3 -np -nH --cut-dirs=1 http://www.source.adr/folder/You can check the source for more information on the flags.
-
Terminal: Sort ps aux
To sort the output of ps aux by used CPU
ps aux|tail -n +2|sort -k 3,3n
and by memory
ps aux|tail -n +2|sort -k 4,4n
I’m sure there are flags in ps to do that stuff for you but I found doing this faster.
The pipe to tail just removes the headers from the output, provides useful for parsing data.
-
Terminal: Learning to live with one Terminal window, not plenty.
Over the time I’ve really grown lazy with the amount of Terminal windows I pop open.Oh, just another one to check that manpage, just that one to do this, to do that.And before you know it your screen is filled with them.
What about situations where you can’t use multiple parallel sessions in separate windows or it would be just time consuming to do so? Enter multitasking management in bash.
Essentially, you will be able to run commands in the background, pause them and continue them when necessary.
I’ll use the commandtopas an example as it shows constantly updating output. To run the command in the background simply append an ampersand to it.
$ top &
[1] 5607
The output numbers are there for your convenience, the second number is the PID of the newly created process, the first number is it’s background job number. It’s the first thing running in the background, therefor it has the number one.
To bring the command back to foreground simply use either of the following:
$ %1
$ fg %1
Both will yield the same result, the process will be brought to the foreground in all of its glory. If the command is paused you can resume it in the background with either
$ %1&
$ bg %1
As far as I see, there’s duplicate commands for readability in job management, if there’s a better reason for having duplicate approaches, let me know via theAsk memenu, please.
If you have a command running in the foreground and want to suspend it to the background, simply hit
Ctrl-Z
to halt it and take it to the background immediately or
Ctrl-Y
to wait for the command to try and read input and then halt and take it to the background.
As you see, both of these will halt the command so if you wish to keep it running, use one of the examples above.
-
OS X: Hide ‘Other…’ from the log-in window list
If you’ve ever enable the root account on your system for security reasons you probably noticed and additional item is added to your log-in window list, namely ‘Other…’. The following command will hide it.
$ sudo defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED false
-
Terminal: Show system info
Just a handy reminder, if you want to see all the information, use system_profiler or to see the options, use system_profiler -listDataTypes.
To see the information most users are usually interested in, use the following command:
$ system_profiler SPHardwareDataType SPDisplaysDataType SPSerialATADataType

-
One-liner: List all mounted drives and their mount points
$ ls /Volumes|sed ‘s/\ \ //’|xargs -I {} diskutil info {}|grep -e ‘Volume Name’ -e ‘Mount Point’
Volume Name: BOOTCAMP
Mount Point: /Volumes/BOOTCAMP
Volume Name: Thyroxine
Mount Point: /You can grep for any info available from diskutil (device identifier, node, part, type and so on) by adding an additional -e ‘pattern’.
-
One-liner: Kill program by name
As an extension to the previous post, this one-liner will prompt you for a name of a program and then will kill all instances of it. Essentially a more extensive version of the command killall.
Note that it will ask you for your password if necessary for sudo.
Also, be careful killing wrong processes.
$ read -p “Program to kill: ” -e NAME;ps aux|grep -i $NAME|grep -v grep|sed ‘s/\ \ //g’|cut -d \ -f 2|xargs sudo kill
Program to kill: VLC
-
OS X: What is MDS and why is it using my CPU?
If you have a habit of checking your Activity Monitor or running top -o cpu in your Terminal every now and then you’ll often have the chance to notice a certain process popping up, using a good amount of your CPU: mds.
Essentially, mds is the indexer for Spotlight, the default launcher-finder-combined-thingy that ships with OS X. And needless to say, if you don’t use Spotlight and have, for example, replaced it with (the thoroughly superior and just in general awesome) Quicksilver launcher you don’t really need the process.
Neither running right now or otherwise in general.
First off, you can kill the currently running mds by
$ ps aux|grep -i mds|grep -v grep|sed ‘s/\ \ //g’|cut -d \ -f 2
32
$ sudo kill 32
The first line finds the running mds process and returns the PID for it, the second command will kill it off. Note that it will need root privileges as mds is always executed as root.
After that, if you want to turn mds off for good, you can disable disk indexing by doing the following:
$ sudo mdutil -a -i off