Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

321–330 of 454 posts

Re: macOS command-line tools you might not know about

#322
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

I've aliased that (and its equivalents on Linux and Android/Termux) to 'xc' and 'xp' (for X11 Copy and X11 Paste, as I'd originated this on Linux).

Being able to populate or read from the system clipboard (or secondary clipboard!), or to feed it, including by reading from or writing to pipes is wonderful.

Re: macOS command-line tools you might not know about

#325
post #38

Earlier quoted context omitted.

The random linebreaks are ok - SSH can handle them. (that's how Userify does it I think, too. it replicates whatever the user provides.. no judgment :)

Ah, it's more for ~/.ssh/authorized_keys which is one key per line.

right (authorized_keys ignores blank lines and comments)

Re: macOS command-line tools you might not know about

#326

Is there a place Apple documents these things? Do people find these things with something like “ls /usr/bin” and wondering “what is this?” or does Apple have an administrator’s guide somewhere? Or has someone written a good book with this stuff?

Hi, author here. There isn't any official canonical documentation that I know of, outside of the individual man pages. This was a list of commands I've been maintaining for myself over the years and thought it would be useful to share.

If you want more like this, I also have another page full of lesser well-known macOS tips and tricks: https://saurabhs.org/macos-tips

Re: macOS command-line tools you might not know about

#327
post #120

Earlier quoted context omitted.

I love this tool too! except one time I quickly typed `cat ~/.ssh/mykey | pbcopy` And sent it straight away to my coworker on Slack. I then spent the rest of the day making a new private key and adding my new pubkey to all of the 1000+ servers I had root access to. I mean we had tools to help but it still wasn’t fun. With great power/convenience comes the potential to do dumb things at lightning speeds!

Userify would have made that pretty painless (all it really seems to do is update the authorized_keys across all of your servers every minute or so)

also userify allows you to set up sudo access on some of the servers and not others, so that'd take care of the other root-access issue you have. (sudo also provides auditing/logging controls that are useful in a multi-user environment)

Re: macOS command-line tools you might not know about

#328
A couple of built-in I didn't see:

macOS software versions:

    sw_vers

macOS hardware overview:

    system_profiler SPHardwareDataType

Convert binary plist to xml

    plutil -convert xml1 -o out.xml in.plist

A couple of lesser known, but also handy ones to install:

    brew install dark-mode

    brew install duti
> screencapture - take screenshots

Big fan of screencapture. I wanted something similar but for capturing window videos, so I built https://github.com/xenodium/macosrec

I often wrap command line utilites with Emacs functions (don't need to remember invocation flags/structure but also enables batch invocations) https://xenodium.com/recordscreenshot-windows-the-lazy-way

Re: macOS command-line tools you might not know about

#329
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

So much of my Linux use is over ssh from a MacOS client that I've made a `pbcopy` executable that just pipes stdin over ssh to my MacBook to its pbcopy (with a dedicated ssh key that runs this as a forced command). Makes it super nice to be on an SSH session and `pbcopy` some content to my MacOS clipboard!

That sounds amazing, I always wanted to do that! Do you have a guide or some script to help with it? Otherwise, I will try to do it on my own.

Re: macOS command-line tools you might not know about

#330
post #213

Earlier quoted context omitted.

Don't forget to pipe head into 'cat -v'... that text file could contain _anything_!

I really recommend folks use "less" over cat, especially keyboard oriented folks. Different terminal emulators don't always have the scroll behavior I want, not do they always allow me to search the file I'm looking at. "less" does all those things, in nearly every environment no matter the terminal emulator, and has other wonderful options to boot (chop long lines so they don't wrap can be nice for logs, line number…

My useless cat is that I always use `cat file | less` when I could just `less file`.

I've been typing cat for over 25 years. Old habits die hard.

Post reply on HN