On a Macintosh computer, many of the commands at the terminal are similar to those on Linux systems since macOS is based on a Unix derivative called Darwin. Here are some common commands and examples for Mac users:
ls– List directory contents.
ls
cd– Change the current directory.
cd ~/Documents
pwd– Print the working directory.
pwd
mkdir– Create a new directory.
mkdir new_directory
rmdir– Remove a directory.
rmdir new_directory
touch– Create a new, empty file.
touch new_file.txt
rm– Remove files or directories.
rm new_file.txt
cp– Copy files or directories.
cp source_file.txt destination_file.txt
mv– Move or rename files or directories.
mv old_name.txt new_name.txt
cat– Concatenate and display file content.cat file.txtmoreorless– Display file content page by page.less file.txthead– Display the beginning of a file.head file.txttail– Display the end of a file.tail file.txtfind– Search for files in a directory hierarchy.find . -name "*.txt"grep– Search text using patterns.grep "search_term" file.txtopen– Open files, directories, or URLs.open .kill– Terminate processes.kill 12345 # Where 12345 is the process IDps– Report a snapshot of current processes.ps -efsudo– Execute a command as another user (typically the superuser).sudo nano /etc/hostsman– Display the manual page for a command.bash man ls
These commands will help users navigate the filesystem, manage files and directories, view and search file content, manage processes, and obtain help while using the Terminal on a Macintosh computer.
which– Shows the full path of shell commands.which lswho– Show who is logged on.whowhoami– Print the user name associated with the current effective user ID.whoamiuptime– Tell how long the system has been running.uptimedf– Report file system disk space usage.df -hdu– Estimate file space usage.du -sh *top– Display dynamic real-time view of a running system.topclear– Clear the terminal screen.clearhistory– Display the command history.historydate– Display or set the system date and time.datecal– Display a calendar.calenv– Display, set, or remove environment variables.envexport– Set an environment variable.export VAR_NAME=valueunset– Unset an environment variable.unset VAR_NAMEalias– Create an alias for a command.alias ll='ls -la'unalias– Remove an alias.unalias llcurl– Transfer data from or to a server.curl http://example.comwget– Non-interactive network downloader.wget http://example.com/file.txtssh– OpenSSH SSH client (remote login program).ssh username@hostnamescp– Secure copy (remote file copy program).bash scp file.txt username@hostname:/path
These additional commands cover a wide range of functionalities from managing environment variables, viewing system information, managing network connections, and much more. By mastering these commands, users can greatly enhance their efficiency and capability in handling various tasks on a Macintosh computer.
ping– Test the reachability of a network host.ping google.comtraceroute– Print the route packets take to a network host.traceroute google.comnetstat– Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.netstat -anifconfig– Configure network interface parameters.ifconfignslookup– Query Internet name servers interactively.nslookup google.comdig– DNS lookup utility.dig google.comftp– FTP client.ftp ftp.example.comsftp– Secure file transfer program.sftp username@hostnamenano– Nano’s ANOther editor, an enhanced free Pico clone (text editor).nano file.txtvim– Vi IMproved, a programmers text editor.vim file.txtchmod– Change file modes or Access Control Lists.chmod 755 file.txtchown– Change file owner and group.chown username:groupname file.txtchflags– Change file flags.chflags uchg file.txttar– Archive utility.tar -cvf archive.tar /path/to/directorygzip– Compress or expand files.gzip file.txtgunzip– Decompress files.gunzip file.txt.gzzip– Package and compress (archive) files.zip archive.zip file.txtunzip– List, test and extract compressed files in a ZIP archive.unzip archive.zipscreen– Terminal multiplexer with VT100/ANSI terminal emulation.screentmux– Terminal multiplexer.bash tmux
These commands help in network troubleshooting, file and directory permission management, text editing, file compression and archiving, and managing multiple terminal sessions among others. They are beneficial for system administration, network management, and everyday usage.
kill– Terminate or signal a process.kill 12345 # where 12345 is the process IDps– Report a snapshot of the current processes.ps auxpgrep– Look up or signal processes based on name and other attributes.pgrep -l bashpkill– Signal processes based on name and other attributes.pkill bashlsof– List open files.lsofgrep– Print lines that match patterns.grep "pattern" filenamefind– Search for files in a directory hierarchy.find /path/to/directory -name filenameawk– Pattern scanning and processing language.awk '{print $1}' filenamesed– Stream editor for filtering and transforming text.sed 's/old/new/' filenamecut– Remove sections from each line of files.cut -d':' -f1 /etc/passwdsort– Sort lines of text files.sort filenameuniq– Report or omit repeated lines.uniq filenamediff– Compare files line by line.diff file1 file2head– Output the first part of files.head -n 10 filename # outputs the first 10 lines of filenametail– Output the last part of files.tail -n 10 filename # outputs the last 10 lines of filenamexargs– Build and execute command lines from standard input.find . -name "*.txt" | xargs rmtouch– Change file timestamps.touch filenamecat– Concatenate and print (or display) the content of files.cat filenameless– Display file content page by page.less filenamemore– Display file content page by page (similar to less but less feature-rich).bash more filename
These commands cover aspects like process management, file searching, text processing, and viewing file contents among others. By learning these commands, users can perform a myriad of tasks on a Macintosh computer efficiently and effectively from the command line.
who– Show who is logged on.whow– Show who is logged on and what they are doing.wuptime– Tell how long the system has been running.uptimedate– Print or set the system date and time.datecal– Display a calendar.caldf– Report file system disk space usage.df -hdu– Estimate file space usage.du -sh /path/to/directoryfree– Display the amount of free and used memory in the system.free -htop– Display Linux tasks (dynamic view of system processes).tophtop– Interactive process viewer (advanced version of top).htopalias– Create an alias for a command.alias ll='ls -la'unalias– Remove an alias.unalias llhistory– Display the command history.historyclear– Clear the terminal screen.clearexit– Exit the shell.exitssh– OpenSSH SSH client (remote login program).ssh username@hostnamescp– Secure copy (remote file copy program).scp file.txt username@hostname:/path/to/directoryrsync– A fast, versatile, remote (and local) file-copying tool.rsync -av /path/to/source-directory username@hostname:/path/to/destination-directorycurl– Transfer data from or to a server.curl http://example.comwget– Non-interactive network downloader.bash wget http://example.com/file.zip
These commands help users to gather system information, manage disk space, create command aliases, and perform network-related tasks among others. By mastering these commands, users can control and interrogate their Macintosh system proficiently via the command line interface.