{"id":60830,"date":"2022-03-25T11:00:00","date_gmt":"2022-03-25T15:00:00","guid":{"rendered":"https:\/\/jumpcloud.com\/?p=60830"},"modified":"2024-12-19T12:25:34","modified_gmt":"2024-12-19T17:25:34","slug":"five-helpful-mac-commands-for-it-admins","status":"publish","type":"post","link":"https:\/\/jumpcloud.com\/blog\/five-helpful-mac-commands-for-it-admins","title":{"rendered":"What Is the Mac Command Line & Why Is It Important for IT Admins?"},"content":{"rendered":"\n
Jump to Commands<\/a><\/p>\n\n\n\n As a Mac admin, or an IT admin overseeing a cross-OS fleet, your role revolves around managing your company\u2019s Apple system infrastructure. To carry out your role efficiently, it is helpful to understand how to use the common Unix commands. <\/p>\n\n\n\n Additionally, while most users of macOS are more familiar with the graphical user interface (GUI), the command line interface (CLI) is more powerful and saves time. In fact, there are some tasks that cannot be accomplished by any other method except the command line.<\/p>\n\n\n\n In this article we will explore the command line, plus its applications and key benefits for IT admins.<\/p>\n\n\n\n A command line, accessed with Terminal.app, empowers you to work on Macs remotely or locally and control a macOS system through a series of text-based commands and scripts. <\/p>\n\n\n\n With an admin account, you can make a tweak to almost everything on your Mac via the Terminal.app. You can also leverage the app to securely connect to servers and workstations remotely and to create simple or complex scripts for automating actions.<\/p>\n\n\n\n When a command is successful, the command line does not display any indicator to notify you of the success. Instead, you will get a new line with your username as shown in Figure 1. It\u2019s important to note that the command and arguments you type in Terminal are case sensitive. <\/p>\n\n\n\n To open Terminal on your Mac, you can search \u201cterminal\u201d in Spotlight as shown in Figure 2 or navigate through Applications > Utilities > Terminal<\/strong>. <\/strong>Once you launch the app, a small window with a command prompt will appear; this is the powerful command line (Figure 3).<\/p>\n\n\n\n You can accomplish many tasks via the CLI, both easy and difficult. From showing hidden files, to getting a list of actively running computer processes, to rebooting a remote workstation, to automating workflows, the number of tasks you can achieve with the terminal app is impressive. <\/p>\n\n\n\n In this section, we will introduce five common commands that every Mac admin should know, but first, let\u2019s learn how to gain admin level privileges.<\/p>\n\n\n\n Executing many commands in the command line will require you to have admin level privileges, i.e., you are expected to be a superuser. For instance, if you do not have the correct privileges and you attempt to run the shutdown<\/kbd> command, the command line will return an error saying you are not a superuser (as seen in Figure 4).<\/p>\n\n\n\n Therefore, to run commands as a superuser, you need to add the sudo<\/kbd> command; sudo stands for superuser do<\/em>. This can be done in two ways: <\/p>\n\n\n\n To gain admin level privileges via the second method, simply run the following command:<\/p>\n\n\n\n We\u2019ve put together a full tutorial series on the common commands every Mac admin must know. We will briefly discuss the commands here and provide a link to the associated article (wherever possible) if you would like to learn more.<\/p>\n\n\n\n SSH \u2014 also known as Secure Socket Shell or Secure Shell \u2014 is a secure network protocol that allows users, especially system admins, to securely access remote devices. To enable SSH, enter and execute the \u2011setremotelogin<\/kbd> command as follows:<\/p>\n\n\n\n To know if SSH has been successfully enabled, simply run and execute the following:<\/p>\n\n\n\n Read our full tutorial on how to enable SSH for accessing a remote Mac’s shell securely<\/a>.<\/p>\n\n\n\n The ability to name each computer in your Mac fleet will allow you to identify and distinguish between them. Using the scutil<\/kbd> command, you can rename your computer name, hostname, and local hostname via the Terminal app. <\/p>\n\n\n\n Check out the full tutorial on how to rename your computer name, hostname and bonjour name<\/a>.<\/p>\n\n\n\n Active Directory (AD)<\/a> provides crucial user and device management capabilities as an identity provider for IT systems. However, IT admins find it challenging to manage Macs with Active Directory because AD was originally created to support Windows systems. To bind a Mac to Active Directory, run the following command in the terminal app:<\/p>\n\n\n\n Replace <adserver.example.com><\/kbd>, <computername><\/kbd>, example.com<\/kbd>, <username><\/kbd> and <password><\/kbd> with your actual information. <\/p>\n\n\n\n Learn more in our full tutorial on how to join Mac to Active Directory services<\/a>.<\/p>\n\n\n\n A Mac admin managing multiple workstations can improve efficiency and productivity if they understand how to install software updates remotely. You can invoke the softwareupdate<\/kbd> command in the terminal to achieve this goal. The command will cause macOS to install or download some or all software updates depending on your choice of argument (see a partial list below):<\/p>\n\n\n\n We created a comprehensive tutorial on how to install macOS software updates remotely<\/a>, you can find the full list of argument options there.<\/p>\n\n\n\n Executing the shutdown<\/kbd> command via the terminal app will shutdown, restart, or put your computer in sleep mode depending on the argument used. Below is a list of options:<\/p>\n\n\n\n Read our full tutorial for more details on how to logoff, restart, and shutdown macOS systems<\/a>.<\/p>\n\n\n\n Executing the system_profiler<\/kbd> command via the Terminal will provide detailed information about the hardware, software, and network settings of your Mac. It\u2019s a great tool for gathering system information quickly.<\/p>\n\n\n\n The top<\/kbd> command displays a real-time summary of system processes, including CPU, memory, and disk usage. This command is useful for monitoring system performance.<\/p>\n\n\n\n The ifconfig<\/kbd> command is used to display or configure network interfaces on your Mac. It provides detailed information about network interfaces, IP addresses, and their statuses.<\/p>\n\n\n\n The ping<\/kbd> command checks network connectivity by sending packets to a specified remote host and measuring the round-trip time. It\u2019s useful for diagnosing network connectivity issues.<\/p>\n\n\n\n The netstat<\/kbd> command displays network connections, routing tables, interface statistics, and other network-related information. It\u2019s useful for monitoring network activity.<\/p>\n\n\n\n The command ipconfig getifaddr en0<\/kbd> retrieves the IP address of a specific network interface (in this case, en0<\/kbd>, typically the primary Ethernet or Wi-Fi interface).<\/p>\n\n\n\n The log show<\/kbd> command displays detailed system logs, which are invaluable for diagnosing and debugging issues. You can filter the logs to find specific events or errors.<\/p>\n\n\n\n The sudo killall<\/kbd> command terminates a running application or process by name. It\u2019s particularly useful when an application becomes unresponsive and needs to be force-quit.<\/p>\n\n\n\n The traceroute<\/kbd> command is used for network diagnostics. It maps the route packets take to reach a destination, identifying any network bottlenecks or failures. This command can also be accessed via the Network Utility application.<\/p>\n\n\n\n The sudo lsof<\/kbd> command lists open files and network connections, making it an excellent tool for network troubleshooting.<\/p>\n\n\n\n The find<\/kbd> command is a versatile tool for locating files and directories based on various criteria such as name, date, or type. It\u2019s particularly useful for quickly pinpointing specific files within a directory structure.<\/p>\n\n\n\n The clear<\/kbd> command removes all previously typed commands and output from the Terminal window, providing a clean workspace. It\u2019s especially helpful when working on long sessions to declutter your screen.<\/p>\n\n\n\n Alternatively, you can use the keyboard shortcut: Command + K<\/kbd><\/p>\n\n\n\n Clearly, the CLI is an important tool in IT admins\u2019 arsenal. Some of the key benefits of the command line for IT admins include the following:<\/p>\n\n\n\n Whether you\u2019re a command line power user or still learning the ropes, did you know you can leverage the JumpCloud Directory Platform to simplify the management of your Mac fleet? From seamless MDM<\/a> to directory-integrated patch management<\/a>, our cloud directory platform was designed to consolidate IT tooling and make admins\u2019 lives easier.<\/p>\n","protected":false},"excerpt":{"rendered":" Make your Mac admin life easier. Learn different ways to leverage Mac terminal commands and simplify the management of your macOS fleet.<\/p>\n","protected":false},"author":131,"featured_media":60831,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_oasis_is_in_workflow":0,"_oasis_original":0,"_oasis_task_priority":"","inline_featured_image":false,"footnotes":""},"categories":[23],"tags":[],"collection":[2778],"platform":[],"funnel_stage":[3016],"coauthors":[2568],"acf":[],"yoast_head":"\nWhat Is the Command Line?<\/strong><\/h2>\n\n\n\n
Launching the Terminal.app<\/strong><\/h2>\n\n\n\n
What Is Possible with Terminal?<\/strong><\/h2>\n\n\n\n
How to Get Admin Privileges on macOS<\/strong><\/h2>\n\n\n\n
\n
sudo -s<\/code><\/p>\n\n\n\n
10 Helpful Mac Terminal Commands Every IT Admin Should Know<\/strong><\/h2>\n\n\n\n
1. Enable SSH for Accessing a Remote Mac’s Shell Securely<\/h3>\n\n\n\n
sudo systemsetup -setremotelogin on<\/code><\/p>\n\n\n\n
sudo systemsetup -getremotelogin<\/code><\/p>\n\n\n\n
2. Rename Computer Name, Hostname, and Bonjour on macOS<\/h3>\n\n\n\n
\n
sudo scutil –set ComputerName <YourComputerName><\/code>\n
\n
sudo scutil –set HostName YourHostName<\/code><\/li>\n\n\n\n
sudo scutil –set LocalHostName YourLocalHostName<\/code><\/li>\n<\/ul>\n\n\n\n
3. Bind a Mac to Active Directory <\/h3>\n\n\n\n
sudo dsconfigad -preferred <adserver.example.com> -a <computername> \u2013domain example.com -u administrator -p <password><\/code><\/p>\n\n\n\n
4. Install macOS Software Updates Remotely<\/h3>\n\n\n\n
\n
sudo softwareupdate -i -a<\/code> OR
sudo softwareupdate –install –all<\/code><\/li>\n\n\n\n
sudo softwareupdate -i -r<\/code> OR
sudo softwareupdate –install –recommended<\/code><\/li>\n\n\n\n
sudo softwareupdate -i <NAME of update exactly as it appears in the list of updates><\/code><\/li>\n<\/ul>\n\n\n\n
5. Logoff, Restart, and Shutdown <\/h3>\n\n\n\n
\n
sudo shutdown -h now<\/code><\/li>\n\n\n\n
sudo shutdown -h +10<\/code><\/li>\n\n\n\n
sudo shutdown -r now<\/code><\/li>\n\n\n\n
sudo shutdown -s now<\/code><\/li>\n<\/ul>\n\n\n\n
6. Get and Manage System Information<\/h3>\n\n\n\n
\n
system_profiler SPHardwareDataType<\/code><\/li>\n\n\n\n
system_profiler SPSoftwareDataType<\/code><\/li>\n<\/ul>\n\n\n\n
\n
top<\/code><\/li>\n\n\n\n
top -o cpu<\/code><\/li>\n<\/ul>\n\n\n\n
7. View Networking and Connectivity Information<\/h3>\n\n\n\n
\n
ifconfig<\/code><\/li>\n\n\n\n
sudo ifconfig en0 up<\/code><\/li>\n<\/ul>\n\n\n\n
\n
ping google.com<\/code><\/li>\n<\/ul>\n\n\n\n
\n
netstat<\/code><\/li>\n\n\n\n
netstat -r<\/code><\/li>\n<\/ul>\n\n\n\n
\n
ipconfig getifaddr en0<\/code><\/li>\n<\/ul>\n\n\n\n
8. Troubleshooting and Diagnostics<\/h3>\n\n\n\n
\n
log show –predicate ‘eventMessage contains “error”‘ –info<\/code><\/li>\n<\/ul>\n\n\n\n
\n
sudo killall process_name<\/code><\/li>\n<\/ul>\n\n\n\n
\n
traceroute google.com<\/code><\/li>\n<\/ul>\n\n\n\n
\n
sudo lsof -i -n -P<\/code><\/li>\n<\/ul>\n\n\n\n
9. Locate Files by Name or Type<\/h3>\n\n\n\n
\n
find . -name “file.txt”<\/code><\/li>\n\n\n\n
find . -mtime -7<\/code><\/li>\n\n\n\n
find . -type f -name “*.log”<\/code><\/li>\n<\/ul>\n\n\n\n
10. Clear Terminal of All Commands<\/h3>\n\n\n\n
\n
clear<\/code><\/li>\n<\/ul>\n\n\n\n
Key Benefits of Command Line for IT Admins<\/strong><\/h2>\n\n\n\n
\n