VNC into another Mac – Command Line

To open a VNC connection to another Mac from the Command Line is very simple, you just need to open Terminal and enter the following

open vnc://username@IPADDRESS

This will then launch the screen sharing app and connect to the machine requested, you will then be presented with a login box, so enter the password for the machine

no need for any extra software, it’s all built in

Disable Time Machines Disk Prompt

Whether you use Time Machine or not, you will probably have been irritated by the constant questioning of whether you wish to use an external drive to backup with Time Machine to it.

If this is the case then there is a simple way of disabling this via the command line

Open Terminal & type

sudo defaults write /Library/Preferences/com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool YES

And hit Enter, you will no longer be prompted by Time Machine, if for some reason you miss the prompts then just swap the YES for a NO and you will be presented with them again

Once disabled, you can still choose which disk to use for Time Machine by using the options in System Preferences.

Open System Preferences

click on Time Machine

Click on Select Disk and then choose the disk you wish to use

job done!

Command Line – Search

In this item I will go through a couple of the commands you can use to locate files on your system.

find

Surprisingly enough, to find some files you can run find, examples of usage are below

find -x / -name filename

this will search your boot volume for files entitled filename

find / -name filename

this will search all mounted volumes (including network shares) for the file named filename, this can take rather a long time so probably best to specify the volume you wish to search

find . -name ‘*filename*’

this searches the current directory and subdirectories for any files with filename anywhere in their name

grep

Search the contents of text files and print lines containing the word searched for

grep searchterm ~/Documents/filename

searches the file called filename stored in my Documents folder, for the text ‘searchterm’

grep -R searchterm ~/Documents

searches through all the files and folders in my Documents folder for ‘searchterm’

grep -Rl searchterm ~/Documents

searches through all the files and folders in my Documents folder for ‘searchterm’, but this time it will only list the file path, not the contents of the file matching the ‘searchterm’

grep daemon /var/log/system.log

searches the system log for entries that mention ‘daemon’

For more info on additional options, check out their manuals

man find

man grep

 

Command Line – System Administration

In this article, I will run through a few commands used to admin your machine.

ps

used to list processes running on the system, examples of usage below

ps

List processes belonging to the current user that are attached to the terminal

ps -x

List processes belonging to the current user, whether or not they are attached to the terminal

ps -ax

List all running processes on the system

ps -aux 

List all the running processes on the system, with additional info about the resources used (most commonly used in trying to find the process causing a system slowdown)

top 

Lists the top CPU consuming processes on the system, this will run continuously though so type q to quit it

top

displays a list of processes, highest process ID (process spawned most recently) first, updates once every second

top -us5

Displays processes sorted by CPU usage, updates once every 5 seconds

kill

Used to kill processes, sometimes essential in restoring control to a hung GUI

kill ###

replace ### with the number of the process you wish to terminate and it should end

kill -1 ###

tells process ### to hang up, which is basically like restarting or reloading the process

kill -9 ###

tells process ### to terminate instantly, like a force quit option in the GUI

ifconfig

Used to view the current network configuration, you can use it to change settings but these may not stick after a reboot, so to enforce changes use the Network preference pane in System Preferences

ifconfig -a

List the computers network ports and their settings

lsof

Used to list open files on the machine

lsof

Lists all files currently open by the you and your processes

sudo lsof

Lists all files currently open by any user on the entire system

sudo lsof -i

Lists all open network connections on the entire system

sudo lsof “/Volumes/External_Drive”

Replace External_Drive with the name of your USB Key or External Hard Drive and it will list all the open files on that volume, useful when a drive won’t eject due to something still using that device.

For more info on the functions listed above just type man followed by their name

man ps

man top

man kill

man ifconfig

Command Line – Text editing

There are a variety of text editors available to use via the command line on OS X, but I prefer to use nano, so here is a little tutorial on the basics of using this utility.

To use it, you will need to fire up Terminal

then to edit a file you will need to type nano and then the filename as below

nano filename

If the file exists already then it will open that, but if the file doesn’t exist then it will open a blank file with the specified filename.

If you are attempting to edit a system file then you will probably need to run it as an administrator, so if you are running in a regular user account you will need to do the following

su administrator

then enter the password for the administrator account, then type

sudo nano filename

you will then need to enter the administrator password again.

The commands above are relevant if you are currently in the directory of the file you wish to edit, if you aren’t then it’s probably easiest to enter the full path of file you wish to edit, such as

sudo nano /System/Library/Preferences/filename

Once you are in the editor then you can navigate using the arrow keys

To save a file press CTRL X at the same time

this should only be used for plain text files, nothing with formatting such as Microsoft Word documents as these will either show up with all the HTML tags or gibberish

For a full list of things you can do with nano type

man nano 

this will give you the manual for nano, to exit the manual just type  q