The Terminal is a command-line interface (CLI) included with MacOS that is used to interact with the operating system by typing text-based commands. It is useful for tasks such as file management or system configuration, where typing the command at a prompt it is a lot faster than scrolling through menus or clicking buttons. The quickest way to find terminal is to use the Spotlight Search. To do this, press CMD Spacebar to open the search.
Type the following into the search bar, the press enter on your keyboard.
Terminal
After opening Terminal, you may want to keep it in the Dock for easier access in the future. To do this, right-click on the Terminal icon in the Dock, then select Keep in Dock from the options.
Once terminal opens, you’ll see a window appear where you can type commands at the prompt.
Here is a list of the most common commands you can use.
Command | Description | Example |
ls | Lists files and directories in the current location. | ls |
ls -l | Lists files with detailed information, such as permissions, owner, and modification date. | ls -l |
cd [directory_name] | Changes to the specified directory. | cd Documents |
cd .. | Moves up one directory level. | cd .. |
mkdir [directory_name] | Creates a new directory with the specified name. | mkdir NewFolder |
touch [file_name] | Creates an empty file with the specified name. | touch newfile.txt |
cp [source] [destination] | Copies a file or directory from the source to the destination. | cp file.txt /Users/username/Desktop |
mv [source] [destination] | Moves or renames a file or directory. | mv oldfile.txt newfile.txt |
rm [file_name] | Deletes a specified file. | rm file.txt |
rm -r [directory_name] | Deletes a directory and its contents. Use with caution. | rm -r OldFolder |
cat [file_name] | Displays the content of a file. | cat file.txt |
pwd | Prints the current working directory. | pwd |
echo [text] | Prints text to the Terminal or redirects it to a file. | echo “Hello World” |
open [file_name or .] | Opens a file or directory in the default application. | open file.txt or open . |
man [command] | Displays the manual page for a command (help information). | man ls |
grep “[pattern]” [file_name] | Searches for a specific pattern in a file. | grep “hello” file.txt |
top | Shows a list of running processes and system resource usage. | top |
ps aux | Lists all running processes. | ps aux |
kill [PID] | Stops a process by its Process ID (PID). | kill 1234 |
clear | Clears the Terminal screen. | clear |
Further Reading
For more information on the subject, have a look at the following book: