Sci/Tech

MacOS Code Snippets

Here are some commands (many of them run through the Terminal application) I use on MacOS. I’ll update this post periodically with more snippets. Drop me recommendations in the comments section below! 🙂

Create Passwordless SSH Connection

Open the Terminal.

cd ~/ ; mkdir .ssh ; cd .ssh ; ssh-keygen -t rsa

This generates a public and private key in /.ssh. Use all the default options and don’t include a password. Next load the private key (change “someUser” to reflect your account):

ssh-add /Users/someUser/.ssh/id_rsa
cat /Users/someUser/.ssh/id_rsa.pub

This will display a long string of characters ending with your localhost information. Navigate to your web host’s SSH section and copy and paste this public key into the relevant section.

Create an alias to quickly connect via SSH to your server. In the following example, an alias and the SSH command are highlighted.

alias testAlias = 'ssh [email protected] -p12345'

In the future, just type “testAlias” (or whatever you called your alias) to run the SSH command. Drop me a comment if you have questions or if this guide helped you! 🙂


Search for String Recursively Through Folder

Use Terminal to navigate to the folder containing your files. Run the following command replacing “text to find” with the relevant query. The “-lr” flag will recursively search each file contained in that directory and subdirectories.

grep -lr "text to find" *

Change Dock Animation Delay

I run my MacOS dock on the left side of the screen and change the animation delay to minimize lag with the following command in Terminal:

defaults write com.apple.dock autohide-time-modifier -float 0.25; killall Dock

To revert to defaults, run this command:

defaults write com.apple.dock autohide-time-modifier -float 1.0; killall Dock

Move Files Of A Given Extension In All Subfolders

find /path/to/original/folder -name '*.extension' -exec cp {} /path/to/destination/folder \;
Tags

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Close