Essential Terminal Commands for MacBook Users

04/06/24

פקודות טרמינל שימושיות למשתמשי מקבוק

Here are some useful commands for the Terminal on a MacBook:

These commands should cover a wide range of tasks and help you effectively manage your MacBook via the Terminal.

Basic Commands

  1. Change Directory

    cd <directory>

    Example:

    cd Documents
  2. List Files and Directories

    ls

    Common options:

    ls -l      # long format
    ls -a      # show all files, including hidden
    ls -lh     # long format with human-readable file sizes
  3. Print Working Directory

    pwd
  4. Create a New Directory

    mkdir <directory>

    Example:

    mkdir new_folder
  5. Create an Empty File

    touch <filename>

    Example:

    touch newfile.txt
  6. Copy Files or Directories

    cp <source> <destination>

    Example:

    cp file1.txt file2.txt
  7. Move or Rename Files or Directories

    mv <source> <destination>

    Example:

    mv oldname.txt newname.txt
  8. Remove Files or Directories

    rm <file>

    Remove directory and its contents:

    rm -r <directory>
  9. Display File Contents bash cat <file> Example: bash cat file.txt

System Information and Management

  1. Check Disk Usage

    df -h
  2. Check Directory Size

    du -sh <directory>

    Example:

    du -sh Documents
  3. Display Running Processes

    top
  4. Terminate a Process bash kill <pid> Example: bash kill 1234

Network Commands

  1. Check Network Configuration

    ifconfig
  2. Ping a Host

    ping <hostname>

    Example:

    ping google.com
  3. Check Open Network Ports bash netstat -an

File Permissions and Ownership

  1. Change File Permissions

    chmod <permissions> <file>

    Example:

    chmod 755 script.sh
  2. Change File Owner bash chown <owner>:<group> <file> Example: bash chown user:staff file.txt

Miscellaneous

  1. Search for Files

    find <path> -name <filename>

    Example:

    find / -name "*.txt"
  2. Search Inside Files

    grep <pattern> <file>

    Example:

    grep "search_term" file.txt
  3. Compress Files

    zip <archive.zip> <file>

    Example:

    zip archive.zip file.txt
  4. Extract Files bash unzip <archive.zip>

Package Management

  1. Install Homebrew (Package Manager)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install a Package with Homebrew bash brew install <package> Example: bash brew install wget

Git Commands

  1. Clone a Repository

    git clone <repository_url>
  2. Check Repository Status

    git status
  3. Add Changes to Staging Area

    git add <file>

    Add all changes:

    git add .
  4. Commit Changes

    git commit -m "commit message"
  5. Push Changes to Remote Repository

    git push
  6. Pull Changes from Remote Repository bash git pull