You can perform advanced system tasks and manage files directly from your Mac using the Terminal application. This requires no third-party software and uses standard Unix commands to control the operating system. Before starting, ensure you have administrative access to your user account to run these commands.
What You'll Need
- A Mac running macOS (Terminal is included by default).
- Administrative privileges for the user account (often requires entering your password).
- A basic understanding of file paths and directory structures.
Step-by-Step
- Open the Terminal application. You can find it by pressing Command (⌘) + Space, typing "Terminal", and pressing Enter. Alternatively, navigate to Applications > Utilities > Terminal in Finder.
- Verify the current directory. In the Terminal window, type
pwdand press Enter. This stands for "print working directory" and will show you the folder path you are currently inside, such as/Users/YourName. Knowing this is crucial because commands often act on the current folder unless you specify a different one. - List files in the current directory. Type
lsand press Enter. This command lists all files and folders in the current location. You can add options to see more details, such asls -la, which displays hidden files and shows permissions and ownership data. - Navigate to a different folder. Use the
cdcommand (change directory). Typecd Desktopand press Enter to move to your Desktop folder. You can also use full paths, such ascd /Applications, to jump directly to the Applications folder. - Create a new folder. To make a new directory, type
mkdir NewFolderNameand press Enter. This creates a folder named "NewFolderName" in your current location. Ensure you do not leave a space between the command and the folder name, as the system will interpret the space as a separator. - Create a new text file. The
touchcommand creates an empty file. Typetouch example.txtand press Enter. You can open this file immediately by typingopen example.txt, which will launch the default text editor. - Copy a file to a different location. To copy a file, use the
cpcommand followed by the source file and the destination. Typecp example.txt /Documents/Backupand press Enter. This copies the file to the Backup folder inside your Documents directory. - Move or rename a file. The
mvcommand moves a file to a new location or renames it. To rename the file, typemv example.txt renamed_example.txt. To move it to another folder, typemv renamed_example.txt /Downloads. - Delete a file. The
rmcommand removes files permanently. Typerm renamed_example.txtand press Enter. Be extremely careful with this command; unlike the Trash bin, files deleted this way cannot be recovered. Always double-check the file name before pressing Enter. - Search for specific text within a file. If you need to find a word or phrase inside a large text file, use the
grepcommand. Typegrep "error" example.txtto print every line in the file that contains the word "error". - Clear the terminal screen. If the text becomes cluttered, type
clearand press Enter. This wipes the screen, but your history remains accessible using the up arrow key. - Check system uptime and load. Type
uptimeto see how long the computer has been running, how many users are logged in, and the system load average. - View the manual for a command. If you are unsure how a command works, you can view its documentation. Type
man lsand press Enter to see the manual page for the list command. To exit the manual, press the Q key.
Common Mistakes
One of the most frequent errors is typing the command name incorrectly. Commands are case-sensitive; typing ls works, but LS will result in an error. Another common mistake is forgetting the space between the command and the argument. For example, cpfile.txt folder will not work, but cp file.txt folder will. Always ensure there is a space separating the instruction from the file or folder name you are targeting.
Tips
Use the Tab key to autocomplete file and folder names. If you type part of a name and press Tab, the Terminal will attempt to complete it. If there are multiple files that start with the same letters, pressing Tab twice will show a list of matching options. This prevents typos and speeds up navigation. Additionally, you can use the Up Arrow (⬆️) key to cycle through your previous commands, allowing you to quickly repeat or slightly modify a command you just ran.
Troubleshooting
If the Terminal reports "command not found," double-check your spelling and capitalization. If the command is correct but you are still receiving errors, verify that you have administrative privileges. Some sensitive system commands require the use of sudo (superuser do) at the beginning of the command. For example, sudo rm file.txt will ask for your password to execute the deletion. Note that macOS will not show asterisks or dots while you type your password for security reasons.
Frequently Asked Questions
Is it safe to run commands in Terminal?
Most basic commands, such as ls, cd, and mkdir, are safe and will not harm your system. However, commands like rm and rm -rf are destructive. Always verify the spelling and the file path before executing a command that deletes or modifies files.
How do I find out what a specific command does?
You can access the built-in manual pages by typing man [command]. For example, to learn about the cp command, type man cp. Press the spacebar to scroll down and the Q key to exit.
Why do I get a "Permission denied" error?
This error means you do not have the necessary rights to modify or move the file. This often happens when trying to move system files or files owned by the root user. You can try using sudo before the command, but be cautious as this requires your administrator password.
Can I undo a command I just typed?
For most file operations, there is no undo button. This is why it is critical to be certain of the command before pressing Enter. Always double-check the file names and paths, especially when using the rm command.
How do I exit the Terminal?
You can simply close the Terminal window, which will end the current session. If you are stuck inside a command that is waiting for input, press Control+C to interrupt it and return to the command prompt.