Home » Tech Tips » Mac » 50 Useful Mac Terminal Commands for Beginners

50 Useful Mac Terminal Commands for Beginners

Terminal is a powerful app in Mac that allows users to interact with macOS system through a command-line interface. For developers, system administrators, and tech enthusiasts, the Terminal provides an efficient way to perform tasks, automate processes, and troubleshoot issues. In this article, we provide a list of 50 useful Terminal commands to help you navigate and master the app. Note that Windows operating system also comes with similar Terminal app for command-line interface.

Getting Started with the Terminal

Before diving into the commands, it’s essential to understand how to open and use the Terminal. Go to “Applications > Utilities” folder in Finder and open Terminal app from there. Alternatively, use Spotlight (press “Command + Space” keys) to search and open Terminal app.

Mac Terminal App
Mac Terminal App

Terminal commands generally follow this structure:

command [options] [arguments]

You can use the man command to read detailed help documentation for any command. Press q key to quit man command and return back to prompt.

man [command]

List of Useful Mac Terminal Commands

Here are 50 useful commands which you can use in default Terminal app as well as in any third-party Terminal emulator app.

CommandPurposeExample
lsList files and directoriesls -l to list files with details
cdChange the current directorycd /path_to_directory
pwdPrint the current working directorypwd
mkdirCreate a new directorymkdir new_folder
rmdirRemove an empty directoryrmdir empty_folder
rmRemove files or directoriesrm file.txt, rm -r folder_name
catView file contentscat file.txt
lessView file contents page by pageless large_file.txt
nanoOpen a file in the Nano text editornano file.txt
topDisplay real-time system processestop
dfShow disk usagedf -h
duEstimate file and directory sizesdu -h folder_name
whoamiShow the current userwhoami
uptimeDisplay system uptimeuptime
pingTest network connectivityping example.com
curlFetch source data from URLcurl https://www.webnots.com
ifconfigView or configure network interfacesifconfig
netstatDisplay network statisticsnetstat
scpSecurely copy files between systemsscp file.txt user@host:/path
psList active processesps
killTerminate a processkill 1234 (1234 is a process ID)
pkillTerminate processes by namepkill process_name
jobsList background jobsjobs
fgBring a background job to the foregroundfg
chmodChange file permissionschmod 755 file.txt
chownChange file ownershipchown user:group file.txt
diskutilManage disks and partitionsdiskutil list
brewInstall and manage software packagesbrew install package_name
findSearch for filesfind /path -name "file.txt"
grepSearch within file contentsgrep "text" file.txt
locateLocate a file by namelocate file.txt
tarArchive filestar -cvf archive.tar file.txt
zipCompress files into a ZIP archivezip archive.zip file.txt
unzipExtract ZIP filesunzip archive.zip
sshConnect to a remote server via SSHssh user@host
aliasCreate a shortcut for a commandalias ll='ls -la'
echoPrint text to the Terminal or write to fileecho "Hello" > file.txt
cronSchedule taskscrontab -e
fsckFile system consistency checkfsck /dev/disk1
dmesgPrint system boot and diagnostic messagesdmesg
sudoExecute commands with superuser privilegessudo command
historyView command historyhistory
clearClear the Terminal screenclear
wcCount lines, words and bytes in a filewc file.txt
headDisplay the first few lines of a filehead -n 5 file.txt
tailDisplay the last few lines of a filetail -n 5 file.txt
sortSort lines in a file alphabeticallysort file.txt
uniqFilter out duplicate lines in a fileuniq file.txt
diffCompare two files line by linediff file1.txt file2.txt
mvMove or rename a file or directorymv file.txt new_location/

Example Use of Commands

Let’s say, you have a file named “Transactions.doc” in your desktop and wanted to know the number of words in that file.

  • First, type cd desktop and press enter to change the prompt to desktop folder.
  • After that, type wc Transactions.doc and press enter to see the number of lines / words / bytes in the file.
Mac Command Examples
Mac Command Examples

Now, you can use the zip command to archive the file right from Terminal prompt. Simply type zip archive1.zip Transactions.doc and press enter. This will create compress the Transactions.doc file and create archive1.zip in your desktop.

Zip File from Mac Terminal
Zip File from Mac Terminal

Conclusion

Whether you’re a beginner or an experienced user, this list is a handy reference for working with Terminal app in Mac. Familiarizing yourself with these commands can significantly enhance your efficiency and enable you to perform tasks that are difficult or impossible from frontend. You can start with these basics and gradually explore advanced commands to unlock the full potential of macOS.

Leave a Comment

Your email address will not be published. Required fields are marked *