macos operation knowledge and command line routine operation

switch path in terminal

In macOS Terminal, you can use cdthe command to switch locations (i.e. change the current working directory). Here are some commonly used commands and techniques:

  1. View the current location: You can use pwdthe command to display the full path of the current working directory.

  2. Switch to the specified directory: use cdthe command followed by the path of the target directory, for example cd /path/to/directory. You can use absolute paths (full paths from the root directory) or relative paths (paths relative to the current directory).

  3. Return to the previous directory: Use cd ..the command to return to the previous directory.

  4. Return to home directory: Enter cd(only cd, without any parameters), press enter to return to your home directory (usually /Users/你的用户名/).

  5. Use the tab key to automatically complete the path: When entering the path, press the tab key to automatically complete the directory or file name, which can reduce the chance of input errors.

  6. Use the ~ symbol to represent the home directory: you can use to cd ~enter your home directory, or you can use to cd ~/Desktopenter the Desktop directory under the home directory.

These are some basic commands and tricks that will help you switch places in macOS Terminal. There are other advanced commands and options that you can learn and explore as needed.

switch to another disk

If you want to switch from your user directory (usually /Users/你的用户名/) to another disk, you can use the following steps:

  1. Determine the name of the other disk: First, you need to determine the name of the disk you want to switch to. ls /VolumesYou can list all volumes (including other disks) mounted in the current system by typing in the terminal , and find the name of the disk you want to switch to.

  2. Switch using an absolute path: Once you know the name of another drive, you can use an absolute path to switch to that drive. Suppose you want to switch to OtherDrivethe disk named , you can enter the following command in the terminal:

cd /Volumes/OtherDrive

This will switch to the disk with the specified name.

Please note that if you need administrator privileges when switching to other disks, you may need to add them before the command sudo. For example:

sudo cd /Volumes/OtherDrive

This will ask you to enter your administrator password to gain access. sudo cdIn general, however, using is invalid in a terminal , because sudoonly affects cdthe command, not cdthe commands following the command.

Openbash_profile

This file can be edited using a text editor or a command-line editor.

Here are a few common methods:

  1. Open with a text editor:

    • In a terminal, execute the following command to open ~/.bash_profilethe file:
      nano ~/.bash_profile
      
    • This will nanoopen the file with a text editor ~/.bash_profile. You can edit and save changes in the file. When you press Ctrl+X to exit the editor, you will be prompted to save your changes.

    or

    • If you prefer another text editor, you can use that editor's command-line tool to open it ~/.bash_profile. For example, for Visual Studio Code, you can execute the following command:
      code ~/.bash_profile
      
      This will open ~/.bash_profilethe file with Visual Studio Code.
  2. Open with a command line editor:

    • In a terminal, execute the following command to open ~/.bash_profilethe file:
      vi ~/.bash_profile
      
    • This will open the file with Vi or Vim editor ~/.bash_profile. You can use the commands of the Vi editor to edit and save changes.

    or

    • If you are familiar with other command-line editors, you can use the editor's command-line tool to open ~/.bash_profile. For example, with Emacs, you can execute the following command:
      emacs ~/.bash_profile
      
      This will open the file with the Emacs editor ~/.bash_profile.

Please choose the method that suits you according to your preference and available editors, and use the corresponding command to open ~/.bash_profilethe file for editing.

edit with vibash_profile

  1. Enter edit mode: In the Vi editor, it is in command mode by default. To enter edit mode, press ithe key. Now you can enter and edit content in the file.

  2. Make modifications: In edit mode, you are free to modify ~/.bash_profilethe contents of the file. You can add, remove, or modify shell commands, environment variables, and more. After editing, you can enter your modifications through the keyboard.

  3. Save changes: After finishing the changes, press Escthe key to exit the editing mode. Then type :wq, meaning to save the file and exit the Vi editor. Press Enterthe key to execute the command.

    If you just want to save the file without exiting the Vi editor, you can use :wthe command to save the file.

  4. Exit Vi editor (optional): If you don't want to save the changes after you finish editing, you can press Escthe key to exit the editing mode. Then type :q!, which means to abandon the modification and force quit the Vi editor. Press Enterthe key to execute the command.

nano ~/.bash_profile

After you have nanoedited ~/.bash_profilethe file with the command, you can save and exit as follows:

  1. Press Ctrl + Xthe key, this will display nanothe exit prompt for .

  2. Press Ythe key to confirm and save the changes.

  3. Press Enterthe key to confirm the file name (usually ~/.bash_profile).

  4. This nanowill save the changes and exit, returning you to the command line interface.

Note that after saving changes, you may need to reload ~/.bash_profilethe file or restart the terminal for the changes to take effect. You can execute one of the following commands:

  • Execute source ~/.bash_profilethe command to reload ~/.bash_profilethe file.
  • Alternatively, close the terminal and reopen a new terminal window for the changes to take effect.

This way, your changes will be saved and applied to ~/.bash_profilethe file.

macos architecture confirmation

To determine if macOS is running on Apple Silicon (arm64), you can perform the following steps:

  1. Click the Apple icon in the upper left corner and select "About This Mac".
  2. In the window that pops up, check the "Processor" or "Chip" column.
  3. If it says something like "Apple M1," "Apple M1 Pro," or "Apple M1 Max," then your version of macOS is running on Apple Silicon, which is the arm64 architecture.
  4. If it says something like "Intel Core i5," "Intel Core i7," or other Intel processor information, then your version of macOS is running on the Intel x86 architecture.

Show hidden, hidden folder

Press the Command+Shift+Period (CMD+Shift+.) shortcut.

Right-click function extension

Right-click assistant == APP Store

screenshot

Capture full screen: Shortcut key (Shift+Command+3)
Screenshot window: Shortcut key (Shift+Command+4, then press space bar)

Change the position of the Windows keyboard Alt and Win keys on the usb interface under MacOS

https://support.apple.com/zh-cn/guide/mac-help/mchlp1011/mac

  1. On your Mac, choose Apple menu > System Settings, then click Keyboard in the sidebar. (You may need to scroll down.)

  2. Click Keyboard Shortcuts on the right, then select Modifier Keys from the list on the left.

  3. For each modifier key whose default action you want to change, click the pop-up menu, then choose an action to perform when the key is pressed or choose No Action.

For example, if you are used to using the Control key on your keyboard, and the corresponding position on Apple keyboards is the Caps Lock key, you can click the Caps Lock key pop-up menu, then choose Control to Performs the same action as pressing the Control key.

dual screen setup

Left and right screen swap: System Settings -> Display -> Arrangement

System Integrity Protection (SIP)

Sometimes the application cannot be installed and it is related to SIP

  1. When the Apple M1 M2 Mac is turned off, press and hold the power button until the setting appears and then release it to enter the recovery mode
  2. Intel chips need to power on or restart the Mac, immediately press and hold Command ⌘ + R on the keyboard until you see the Apple logo or a spinning globe and release the keys to enter recovery mode
//关闭
csrutil disable
//打开
csrutil enable
//查看状态
csrutil status

Remove apps downloaded from the internet

Please add a picture description

Guess you like

Origin blog.csdn.net/weixin_35691921/article/details/130730666