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

  1. 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.
  2. Verify the current directory. In the Terminal window, type pwd and 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.
  3. List files in the current directory. Type ls and press Enter. This command lists all files and folders in the current location. You can add options to see more details, such as ls -la, which displays hidden files and shows permissions and ownership data.
  4. Navigate to a different folder. Use the cd command (change directory). Type cd Desktop and press Enter to move to your Desktop folder. You can also use full paths, such as cd /Applications, to jump directly to the Applications folder.
  5. Create a new folder. To make a new directory, type mkdir NewFolderName and 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.
  6. Create a new text file. The touch command creates an empty file. Type touch example.txt and press Enter. You can open this file immediately by typing open example.txt, which will launch the default text editor.
  7. Copy a file to a different location. To copy a file, use the cp command followed by the source file and the destination. Type cp example.txt /Documents/Backup and press Enter. This copies the file to the Backup folder inside your Documents directory.
  8. Move or rename a file. The mv command moves a file to a new location or renames it. To rename the file, type mv example.txt renamed_example.txt. To move it to another folder, type mv renamed_example.txt /Downloads.
  9. Delete a file. The rm command removes files permanently. Type rm renamed_example.txt and 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.
  10. Search for specific text within a file. If you need to find a word or phrase inside a large text file, use the grep command. Type grep "error" example.txt to print every line in the file that contains the word "error".
  11. Clear the terminal screen. If the text becomes cluttered, type clear and press Enter. This wipes the screen, but your history remains accessible using the up arrow key.
  12. Check system uptime and load. Type uptime to see how long the computer has been running, how many users are logged in, and the system load average.
  13. View the manual for a command. If you are unsure how a command works, you can view its documentation. Type man ls and 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.