Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Use Administrative Commands in macOS Terminal

Administrative commands are essential for performing system-level tasks that require elevated privileges. In the Apple environment, specifically macOS, these commands are executed through the Terminal application. Understanding how to use these commands is crucial for system administrators and power users who need to manage system settings, install software, or troubleshoot issues. This article will guide you through some of the most commonly used administrative commands in macOS, providing practical examples to help you get started.

Examples:

  1. Using sudo for Elevated Privileges

    The sudo command allows you to run programs with the security privileges of another user, by default the superuser. This is essential for administrative tasks.

    sudo command_to_run

    Example: Updating the package list with Homebrew

    sudo brew update
  2. Managing Users with dscl

    The dscl (Directory Service command line) command is used to manage directory services, including user accounts.

    Example: Creating a new user

    sudo dscl . -create /Users/newuser
    sudo dscl . -create /Users/newuser UserShell /bin/bash
    sudo dscl . -create /Users/newuser RealName "New User"
    sudo dscl . -create /Users/newuser UniqueID 1001
    sudo dscl . -create /Users/newuser PrimaryGroupID 80
    sudo dscl . -create /Users/newuser NFSHomeDirectory /Users/newuser
    sudo dscl . -passwd /Users/newuser password
  3. Managing Permissions with chmod and chown

    The chmod command changes file access permissions, while chown changes file ownership.

    Example: Changing file permissions

    sudo chmod 755 /path/to/file

    Example: Changing file ownership

    sudo chown username:group /path/to/file
  4. Viewing System Logs with log

    The log command provides access to the unified logging system in macOS, which is useful for troubleshooting.

    Example: Viewing the system log

    sudo log show --predicate 'eventMessage contains "error"' --info
  5. Managing System Services with launchctl

    The launchctl command interfaces with the launchd service manager, allowing you to manage system services.

    Example: Loading a service

    sudo launchctl load /Library/LaunchDaemons/com.example.service.plist

    Example: Unloading a service

    sudo launchctl unload /Library/LaunchDaemons/com.example.service.plist

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.