# MacOS Terminal Command Bible
What do you want to do? Command Flags/Notes
Find out what a command does \[command\] -h
Shutdown/Restart sudo shutdown -h now sudo shutdown -r now -h -- HALT -r -- Restart
Download a File via Terminal curl -O -- <URL to the file>
Rename a macOS computer scutil --set LocalHostName "NAME" scutil --set ComputerName "NAME" scutil --set HostName "NAME" ComputerName is for a User-Friendly name that gets displayed, LocalHostName is for network-based identification (Bonjour, etc), and HostName is for SSH and terminal Changing Hostname will reset your Automate connection most likely. You must rename the LocalHostName and ComputerName in order for Automate to recognize the changes. Resend System Information from the Agent page, then refresh your cache to update. Update all three for consistency's sake.
Get a macOS computer name scutil --get ComputerName scutil --get HostName
Show files in a specific directory ls -a -- list all directory contents (includes hidden) -l -- list detail information for each entry -la -- do both of the above in one flag -ld -- display permissions of a directory
Delete a file or directory rm -f -- Force -rf -- Recursively force \*\*USE WITH CAUTION\*\*
Run a command at Administrator level sudo Run before a command, may ask for a password. Use with caution. -i -- Persistent \*\*Always remember to log out of Sudo\*\*
Read the manual for a command man \[command\]
Find a file on the system find
Make a directory or folder mkdir
Copy a file or folder cp
Move between folders cd \[folder\] i.e `cd /usr/local/bin` ~ -- home .. -- Up one directory
Find the directory I'm currently in pwd
Move a file or folder mv
Quickly read a text file in Terminal cat
Run an application from Terminal open
Get Ip configuration ifconfig -a -- Show All
Leave the terminal exit
Find a running process ps top lsof -ax | grep <appname> top is an interactive, constantly updating command lsof lists all open files, but every daemon, port and process is a file so… yeah it works here too
Kill a running process kill <PID> May need to be ran as root
Mark file as executable (to run scripts) chmod +x filename.sh chmod can be altered to have more granular permissions may need a "#!/bin/bash" or whatever shell it's using at the beginning
Add certificate to keychain sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /Location/Of/Certificate.cer Mostly used for WatchGuard, there's a script that should be doing this automagically ((Mac) Install Client-Specific Watchguard Certificates)
Follow a file as it updates tail -f -- follow
Please keep in mind that all commands run through Automate run at root level authentication [https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html](https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html) Labtech installs into /usr/local/ltechagent/ Has an lttray daemon that you can find via 'launchctl list | grep labtech' Runs two ltechagents and the lttray process that shows up in ps or top. Location Shortcuts
/ Top level directory
. Current directory
.. Parent directory
~ Home directory
/var/log/system.log System log
/Library/logs System application logs
~/Library/logs User application logs
All Commands can be autocompleted by tapping the \[TAB\] key