Command Line – System Administration

In this article, I will run through a few commands used to admin your machine.

ps

used to list processes running on the system, examples of usage below

ps

List processes belonging to the current user that are attached to the terminal

ps -x

List processes belonging to the current user, whether or not they are attached to the terminal

ps -ax

List all running processes on the system

ps -aux 

List all the running processes on the system, with additional info about the resources used (most commonly used in trying to find the process causing a system slowdown)

top 

Lists the top CPU consuming processes on the system, this will run continuously though so type q to quit it

top

displays a list of processes, highest process ID (process spawned most recently) first, updates once every second

top -us5

Displays processes sorted by CPU usage, updates once every 5 seconds

kill

Used to kill processes, sometimes essential in restoring control to a hung GUI

kill ###

replace ### with the number of the process you wish to terminate and it should end

kill -1 ###

tells process ### to hang up, which is basically like restarting or reloading the process

kill -9 ###

tells process ### to terminate instantly, like a force quit option in the GUI

ifconfig

Used to view the current network configuration, you can use it to change settings but these may not stick after a reboot, so to enforce changes use the Network preference pane in System Preferences

ifconfig -a

List the computers network ports and their settings

lsof

Used to list open files on the machine

lsof

Lists all files currently open by the you and your processes

sudo lsof

Lists all files currently open by any user on the entire system

sudo lsof -i

Lists all open network connections on the entire system

sudo lsof “/Volumes/External_Drive”

Replace External_Drive with the name of your USB Key or External Hard Drive and it will list all the open files on that volume, useful when a drive won’t eject due to something still using that device.

For more info on the functions listed above just type man followed by their name

man ps

man top

man kill

man ifconfig