MacOS
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" |
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 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> |
|
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 |
|
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
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
How to convert DMG to PKG Mac App for distribution
How to convert DMG to PKG Mac App for distribution
https://www.hexnode.com/mobile-device-management/help/convert-dmg-to-pkg-mac/
DMG files or Disk Image files used to install software contain app files, installation files and other file types. They are usually used by macOS software installers downloaded from the internet.
PKG files are macOS installation packages containing installer scripts and compressed installation files used to install Mac software applications on a user hard drive.
The issue with DMG files is that it needs to be mounted as a virtual disk to push apps, whereas PKG files can be directly installed. Hence, it is ideal to convert DMG files to PKG files to push them through Hexnode. It’s a rather simple process that can be done with the help of the Terminal.
Terminal can create PKG files from DMG files and they can then be distributed via Hexnode as enterprise apps.
For using downloaded DMG files: Enable the “App Store and identified developers” option under Mac system preferences > Security and Privacy> Allow apps downloaded from.
PKG files can only be created from DMG files containing applications by using the Terminal.
Steps to convert macOS DMG files to PKG files.
- Go to the folder that contains the DMG file.
- Double click the DMG file. It gets mounted as a virtual disk and reveals its contents.
- Copy the .app file to the Applications folder in the macOS device.
- Eject the DMG file by clicking on the eject button.
- Open Terminal.
- Build the PKG file using the productbuild command
sudo productbuild --component /path_to_installedapp/macapp.app / path_to_savedpackage/packagename.pkg
The two arguments specify the location of the installed .app file (path_to_installedapp/macapp.app) and the location to create the PKG file (path_to_savedpackage/packagename.pkg), respectively.
- Provide the device login password and wait for a few seconds for the build to finish.
- The PKG file gets created at the desired location.
To distribute the created PKG files, check out Distribute macOS Enterprise App using Hexnode.
Signing a PKG file is recommended to enforce corporate data security and ensure that the app in use is trustable, safe and malware-free. Check out How to sign pkg files for deployment.
The only red flag here is that not all apps are created similarly, which may affect the time required for the PKG build.