These basic Terminal commands are often overlooked, though are useful for Mac users trying to obtain information about a system they may not be familiar with quickly and efficiently.
How many times has this happened to you? You’re tasked with working on group of devices that you have little to no prior knowledge of, or you simply need to pull some basic info from the machines quickly. The fastest way I’ve found to accomplish this is by using the Terminal and some basic, but incredibly useful, commands to extract the needed information in no time flat.
I’ve even added some of the Terminal commands below to a script I’ve crafted that helps to further automate this process, whether being executed manually or over SSH. The best part: These Terminal commands are all very flexible and may be combined with other commands in more complex scripts to create actionable, universal tasks, built on the information output from the basic commands below.
SEE: Editorial calendar: IT policies, checklists, toolkits, and research for download (TechRepublic Premium)
1. How to obtain the macOS version
This command provides a simple output of the major and minor version of macOS installed locally.
2. How to determine system uptime
Simple and to the point. This command provides information on how long the system has been online since the last reboot in days and hours. It also lists how many users are located within the system and the average loads on resources.
3. How to get a system overview
This is a personal favorite of mine and one I use in place of the two above. This command outputs more information than you might need, but in the name of efficiency, it provides the system version, kernel version, boot status, computer name, current user’s name, uptime, and system security details, such as if secure virtual memory and system integrity protection statuses.
4. How to set the time and date
date -u [month][day][hour][minute][year]
While this may seem trivial, anyone who has ever experienced trouble authenticating to a directory service because the time/date were off will think otherwise. The syntax seems convoluted but is easy to follow once you understand it. You only need to add the two-digit month, day, hour, minute, and year—all together, no spaces—to set the time and date accordingly.
5. How to get a list of users
dscl . list /Users | grep -v '_'
You’re going to want to know if there are any users on the device you may have missed before you wipe a device or decommission it from company inventory. The command above will provide just that, including any hidden accounts that may exist. If you run the command without the | grep -v ‘_’ part, it will also include all daemon accounts created to perform services.
6. How to see permissions on files or folders
Don’t forget to first change directory to the correct working folder, then run the command above to see the permissions assigned to all files and subdirectories, including ownership in sequential order.
7. How to see how much storage is used by a particular directory or file
du -h -d 1
Like the permissions check above, first navigate to the directory you wish to work from, then enter one of the two “du” commands, depending on what you wish the output to be. The former will display the total size of the root directory; the latter will display each file or directory in descending order with their respective sizes along the left-hand side.