Text

Jot it down

For testing purposes, I usually create a series of files to run my bash scripts against and I love using the jot command.

jot 3

Generates:

1
2
3

Awesome! This allows me to:

jot 8 | xargs touch

I also use it to generate random series of numbers:

jot -r 10

What if you want to specify a range of numbers to which the randomisation occur?

jot -r 10 580 900

The above gives you 10 random numbers between 580 to 900. Awesome, right? Then there’s more - you can prepend a word to it!

jot -w file_%d -r 10 580 900

Like I said, I love the jot command. There’s a lot more use of this nifty little command. I only cover those I use often.

For the rest of it, you can go through the tutorial here.

Text

Oh yes!

Ever come across a situation where you need to do this (very quickly):

rm -rf *

And you get this (with the -i flag):

rm: remove regular file 'PRON_0001.jpg'?

Sh*t! I have to hit 'y' to every single file? Well, you can use the yes command.

The yes command generates an infinite loop of 'y'. So, your problem solved:

yes | rm -rf *

Of course the above example uses the rm command, which can be solved with the -f flag but you can use it for any other commands that doesn’t offer such an option.

Text

Mac OS command line goodies

I always love doing things without my fingers leaving the keyboard. So, the more I can do from my terminal, the better. Over the years, I’ve come to like quite a few really handy commands.

Open files

Open most files as if you double clicked on it in Finder:

open usage_report.pdf

Wanna open Finder where you are in terminal?

open .

Emailing

Emailing output to yourself (you need to enable postfix first):

ps aux | mail -s "Subject line" me@example.com

You should be able to check if the email has been placed in queue:

mailq

You should see something like this if you’re quick (before it gets sent):

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
6762CA18F19*   20039 Sat Jun  9 20:12:03  root@macbookpro.local
                                         me@example.com

-- 19 Kbytes in 1 Request.

Oh this works on any Linux with mailx and local mta installed.

Clipboard manipulation

How about copying something in terminal to clipboard?

cat some_text.txt | pbcopy

You can then use Ctrl+V anywhere. And if you want to past from clipboard:

pbpaste > from_clipboard.txt

Other misc tools

Current Mac version:

sw_vers

Profiler information:

systerm_profiler

Use the Spotlight engine:

mdfind textedit

Screencapture (full tutorial here):

screencapture ~/Desktop/mycapture.jpg

That’s it! Now go have fun!