56 useful terminal commands in macOS for all occasions – how-wiki.ru
28.02.2024

56 useful terminal commands in macOS for all occasions

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

56 useful macOS terminal commands for all occasions

  1. sudo. Run command as administrator.
  2. sudo !!. Run the previous command as administrator.
  3. man your_command. Show full documentation for the command.
  4. your_command –help. Display brief help information for the given command.

Terminal Interaction

56 useful macOS terminal commands for all occasions

  1. history. Show a list of recently entered commands. By adding a number at the end, you can limit the number of items displayed.
  2. !!. Execute the last command entered.
  3. clear. Completely clear the terminal window of commands and messages.
  4. &&. A special argument for executing multiple commands in sequence. For example, first_command&& second_command.

Working with folders and files

56 useful terminal commands in macOS for all occasions

  1. 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.
  2. rmdir < em>folder_name. Delete an empty folder.
  3. rm -R folder_name. Delete the folder and all its contents.
  4. touch file_name. Create a new file without extension.
  5. open filename. Open the specified file.
  6. cp file_name folder_name. Copy the file to the specified folder.
  7. mv file_name folder_name. Move the file to the specified folder.
  8. rm file_name. Delete file without confirmation.
  9. rm -i filename. Delete file asking for confirmation (you will need to type y to continue or n to cancel).
  10. find folder_name -name filename. Find files in the specified folder whose names contain the specified characters.
  11. grep -rl “search_text folder_name. Find all files containing the specified text within the specified folder.

Manage file and folder permissions

56 useful macOS terminal commands for all occasions

  1. ls -ld folder_name. Show the permissions of the specified folder.
  2. 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.
  3. chmod 600 file_name. Set read/write permissions for the file owner only.
  4. chmod 755 file_name. Make the file executable.

System Management

56 useful terminal commands in macOS for all occasions

  1. whoami. Show username.
  2. sudo purge. Force clear RAM (password required).
  3. uptime. Show the time the computer has been running since it was turned on.
  4. sudo shutdown -h now. Turn off the computer (requires an administrator password).

Process Management

56 useful macOS terminal commands for all occasions

    < li>top. Display active processes sorted by CPU usage. The information is updated.
  1. top -o rsize. Display a list of processes sorted by memory used.
  2. kill PID_process. Force termination of the specified process. The PID can be found by typing top.
  3. killall process_name. Force termination of all processes with the specified name. For example, kill a hung application.

Network Interaction

56 useful terminal commands in macOS for all occasions

  1. 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.
  2. ifconfig en0. Display the computer's IP and MAC address.
  3. arp -a. Show a list of all devices on the local network with their IP and MAC addresses.
  4. curl -O file_link. Download a file from a given URL (works for HTTP, HTTPS and FTP protocols).

Miscellaneous

56 useful terminal commands in macOS for all occasions

  1. curl http://wttr.in/. Show the weather forecast for three days for the current location.
  2. say Hey Lifehacker! The Mac will say whatever text you type after the command.
  3. < li>nc towel.blinkenlights.nl 23. View Star Wars Episode 4 as a text graphic.

  4. 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.

Keyboard shortcuts for working with the macOS terminal

  1. Tab. Automatically complete a file or folder name after a few characters entered.
  2. Control + A. Move the cursor to the beginning of the current line.
  3. Control + E. Move the cursor to the end of the current line.
  4. Control + U. Delete text from the cursor to the beginning of the line.
  5. Control + K. Delete text from cursor to end of line.
  6. Control + W. Delete the word before the cursor.
  7. Control + T. Swap the two characters before the cursor.
  8. Esc + T. Swap the two words before the cursor.
  9. Control + L. Clear the output of the previous command.
  10. Option + →. Move cursor forward one word.
  11. Option + ←. Move cursor back one word.
  12. Control + F. Move cursor one character to the right.
  13. Control + B. Move cursor one character to the left.
  14. Control + Z. Suspend the current process.
  15. Control + C. Terminate a process that is currently running.
  16. Command + D. Split window into two panels for parallel work. Clicking again will bisect the selected panel.
  17. Shift + Command + D. Close panel.