A neat feature of
scp is that you can copy in either direction: Give the local file descriptor first to copy from local to remote; give the remote file descriptor first to copy from remote to local. The examples below show both methods, as well as how to copy entire folder hierarchies.
To copy from a local current directory to the remote system:
$ scp filename userID@remotesystem:/path/to/filename
To copy from the remote system to the local current directory:
$ scp userID@remotesystem:/path/to/filename ./
To copy an entire directory (the
-r option indicates recursion):
$ scp -r directoryname userID@remotesystem:/path/to/directory
scutil: Set the computer host name
Sometimes you want to change the name of a computer, but there doesn't seem to be an easy way to do this through any system preference or other graphical utility. You can do it with the very powerful
scutil tool, although you must run the command three times to change the name in the three places where it resides.
You can do a lot more with
scutil in the same way you can do a ton more than drive your car with a gallon of gasoline. Unless you know what you're doing, it's best to let
scutil's other abilities stay in drawer.
$ sudo scutil --set ComputerName "newname"
$ sudo scutil --set LocalHostName "newname"
$ sudo scutil --set HostName "newname"
shutdown: Restart the Mac
System administrators sometimes have to restart computers when the owner isn't around. Sharing the screen isn't always convenient -- or even enabled. If you can get a remote command-line access to the target machine (such as via the
ssh Secure Shell command), rebooting remotely is a cinch using the
shutdown command. The
-r option indicates you want to restart; without it, the Mac will power off. The
now argument means just what it says: Do it now. You can also specify a date and time, in the form yymmddhhmm, to preset a delayed reboot.
$ shutdown -r now
sysctl: Get CPU information and other internal secrets
The official purpose of the
sysctl utility is to get or set kernel state values. Unless you know what you're doing, you don't want to set kernel state values. But looking at them is harmless -- and can be informative.
For example, the example below displays the machine CPU type, which can be useful to know for certain system administration chores. You can use
sysctl to control decisions in a Bash script as well. Run
sysctl -a to get a list of all the kernel variables available for inspection. You might find some others you'd like to inspect.
$ sysctl -n machdep.cpu.brand_string
Intel(R) Core(TM) i5 CPU 750 @ 2.67GHz
systemsetup: Perform various system configuration operations
systemsetup command lets you retrieve and alter a wide range of configuration values normally set from the graphical System Preferences application. Run
systemsetup help to get a complete list of options.
One popular setting is to configure a system to set its clock based on a network time source, as shown below. You'll undoubtedly find useful reasons to set other values.
$ systemsetup -setnetworktimeserver us.pool.ntp.org