Interaction with files, process management, as well as interesting features like weather forecast and more. v-macos-na-vse-sluchai-zhizni-87e981e.jpg” alt=”56 useful macOS terminal commands for all occasions” />
Basics
- sudo. Run command as administrator.
- sudo !!. Run the previous command as administrator.
- man your_command. Show full documentation for the command.
- your_command –help. Display brief help information for the given command.
Terminal Interaction
- history. Show a list of recently entered commands. By adding a number at the end, you can limit the number of items displayed.
- !!. Execute the last command entered.
- clear. Completely clear the terminal window of commands and messages.
- &&. A special argument for executing multiple commands in sequence. For example, first_command&& second_command.
Working with folders and files
- mkdir folder_name. Create a new folder with the given name. If you add other names separated by a space, you can create several folders at once: mkdir first_folder_name second_folder_name.
- rmdir < em>folder_name. Delete an empty folder.
- rm -R folder_name. Delete the folder and all its contents.
- touch file_name. Create a new file without extension.
- open filename. Open the specified file.
- cp file_name folder_name. Copy the file to the specified folder.
- mv file_name folder_name. Move the file to the specified folder.
- rm file_name. Delete file without confirmation.
- rm -i filename. Delete file asking for confirmation (you will need to type y to continue or n to cancel).
- find folder_name -name filename. Find files in the specified folder whose names contain the specified characters.
- grep -rl “search_text“ folder_name. Find all files containing the specified text within the specified folder.
Manage file and folder permissions
- ls -ld folder_name. Show the permissions of the specified folder.
- chmod 600 folder_name. Set read/write permissions for the folder owner only. If you add the -R argument, the permissions will also apply to the contents of the folder.
- chmod 600 file_name. Set read/write permissions for the file owner only.
- chmod 755 file_name. Make the file executable.
System Management
- whoami. Show username.
- sudo purge. Force clear RAM (password required).
- uptime. Show the time the computer has been running since it was turned on.
- sudo shutdown -h now. Turn off the computer (requires an administrator password).
Process Management
- < li>top. Display active processes sorted by CPU usage. The information is updated.
- top -o rsize. Display a list of processes sorted by memory used.
- kill PID_process. Force termination of the specified process. The PID can be found by typing top.
- killall process_name. Force termination of all processes with the specified name. For example, kill a hung application.
Network Interaction
- ping server_address. Check the ping to the specified server, for example ping google.com, and see if there is an Internet connection and how stable it is.
- ifconfig en0. Display the computer's IP and MAC address.
- arp -a. Show a list of all devices on the local network with their IP and MAC addresses.
- curl -O file_link. Download a file from a given URL (works for HTTP, HTTPS and FTP protocols).
Miscellaneous
- curl http://wttr.in/. Show the weather forecast for three days for the current location.
- say Hey Lifehacker! The Mac will say whatever text you type after the command.
- cal Display the calendar for the current month. -A 1 adds the specified number of months after the current date, and -B 1 before it.
< li>nc towel.blinkenlights.nl 23. View Star Wars Episode 4 as a text graphic.
Keyboard shortcuts for working with the macOS terminal
- Tab. Automatically complete a file or folder name after a few characters entered.
- Control + A. Move the cursor to the beginning of the current line.
- Control + E. Move the cursor to the end of the current line.
- Control + U. Delete text from the cursor to the beginning of the line.
- Control + K. Delete text from cursor to end of line.
- Control + W. Delete the word before the cursor.
- Control + T. Swap the two characters before the cursor.
- Esc + T. Swap the two words before the cursor.
- Control + L. Clear the output of the previous command.
- Option + →. Move cursor forward one word.
- Option + ←. Move cursor back one word.
- Control + F. Move cursor one character to the right.
- Control + B. Move cursor one character to the left.
- Control + Z. Suspend the current process.
- Control + C. Terminate a process that is currently running.
- Command + D. Split window into two panels for parallel work. Clicking again will bisect the selected panel.
- Shift + Command + D. Close panel.