You are previewing Macintosh Terminal Pocket Guide.

Macintosh Terminal Pocket Guide

Cover of Macintosh Terminal Pocket Guide by Daniel J. Barrett Published by O'Reilly Media, Inc.
  1. Macintosh Terminal Pocket Guide
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. 1. The Macintosh Terminal
    1. What’s in This Book?
      1. What’s the Terminal?
      2. What’s a Command?
      3. Ten Commands to Try
      4. Reading This Book
    2. Running the Terminal
    3. The Filesystem
      1. Structure of the Filesystem
      2. Navigating the Filesystem
      3. Home Directories in the Filesystem
      4. System Directories in the Filesystem
      5. File Protections
    4. The Shell
      1. The Shell Versus Programs
      2. Selected Features of the bash Shell
      3. Shell Job Control
      4. Killing a Command in Progress
      5. Terminating a Shell
      6. Tailoring Shell Behavior
  4. 2. Commands
    1. Basic File Operations
      1. ls
      2. cp
      3. mv
      4. rm
      5. ln
    2. Directory Operations
      1. cd
      2. pwd
      3. basename
      4. dirname
      5. mkdir
      6. rmdir
    3. File Viewing
      1. cat
      2. less
      3. head
      4. tail
      5. nl
      6. strings
      7. od
      8. xxd
    4. File Creation and Editing
      1. Creating a File Quickly
      2. Your Default Editor
    5. File Properties
      1. stat
      2. wc
      3. du
      4. file
      5. touch
      6. chown
      7. chgrp
      8. chmod
      9. umask
      10. xattr
    6. File Text Manipulation
      1. grep
      2. egrep
      3. fgrep
      4. cut
      5. paste
      6. tr
      7. sort
      8. uniq
      9. tee
    7. File Location
      1. find
      2. xargs
      3. locate
      4. which
      5. type
      6. whereis
    8. File Compression and Packaging
      1. gzip
      2. bzip2
      3. compress
      4. zip
      5. tar
    9. File Comparison
      1. diff
      2. comm
      3. cmp
      4. md5
    10. Printing
      1. lpr
      2. lpq
      3. lprm
    11. Disks and Filesystems
      1. df
      2. diskutil
      3. mount
      4. fsck_hfs
      5. hdiutil
      6. tmutil
      7. sync
      8. rsync
    12. Viewing Processes
      1. ps
      2. uptime
      3. w
      4. top
    13. Controlling Processes
      1. open
      2. kill
      3. nice
      4. renice
      5. shutdown
    14. Scheduling Jobs
      1. sleep
      2. at
      3. crontab
      4. launchctl
    15. Users and Their Environment
      1. logname
      2. whoami
      3. id
      4. who
      5. users
      6. last
      7. finger
      8. chfn
      9. passwd
      10. chsh
      11. dscl
      12. printenv
    16. Becoming the Superuser
    17. Group Management
      1. groups
      2. dscl
    18. Host Information
      1. uname
      2. sw_vers
      3. hostname
      4. scutil
      5. ifconfig
      6. ipconfig
    19. Host Location
      1. host
      2. whois
      3. ping
      4. traceroute
    20. Network Connections
      1. ssh
      2. telnet
      3. scp
      4. sftp
      5. ftp
    21. Email Commands
      1. mail
      2. mailq
    22. Web Commands
      1. curl
      2. wget
    23. Messaging
      1. talk
      2. write
      3. mesg
      4. tty
    24. Screen Output
      1. echo
      2. printf
      3. pbcopy
      4. pbpaste
      5. yes
      6. clear
    25. Math and Calculations
      1. expr
      2. dc
      3. seq
    26. Dates and Times
      1. cal
      2. date
  5. 3. Advanced Topics
    1. Running a Shell Remotely
      1. Enabling remote logins
      2. Logging in remotely with SSH
      3. SSH roadblocks
    2. Installing Software with a Package Manager
      1. Obtaining an Apple Developer ID
      2. Installing Xcode
      3. Installing Command Line Tools for Xcode
      4. Installing the Homebrew Package Manager
      5. Using Homebrew
      6. Installing from TAR Files
    3. Programming with Shell Scripts
      1. Creating and Running Shell Scripts
      2. Whitespace and Linebreaks
      3. Variables
      4. Input and Output
      5. Booleans and Return Codes
      6. Conditionals
      7. Loops
      8. Break and Continue
      9. Command-Line Arguments
      10. Exiting with a Return Code
      11. Beyond Shell Scripting
    4. Getting Help
    5. Final Words
      1. Acknowledgments
  6. Index
  7. About the Author
  8. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  9. Copyright
O'Reilly logo

Name

chmod — stdin  stdout  - file  -- opt  --help  --version

Synopsis

chmod [options] permissions files

The chmod (change mode) command protects files and directories from unauthorized access in the filesystem by setting access permissions. We described these permissions—read (r), write (w), and execute (x)—in File Protections. These permissions are described as a string of nine characters (rwxrwxrwx) consisting of three triplets: the first for the user owning the file, the second for group ownership, and the third for other users.

For example, here we have a file myfile that is readable and writable by its owner, readable by its group, and readable by others:

ls -l myfile
-rw-r--r--  1 smith  staff  4 Apr 26 22:22 myfile

Using chmod, we can take away the read permissions for the group (g) and the other users (o):

chmod g-r,o-r myfilels -l myfile
-rw-------  1 smith  staff  4 Apr 26 22:23 myfile

Now we make the file read-only for all users (a):

chmod a=r myfilels -l myfile
-r--r--r--  1 smith  staff  4 Apr 26 22:24 myfile

chmod understands permissions in two formats, one numeric, and one symbolic, as depicted in Figure 2-2.

File permission bits explained

Figure 2-2. File permission bits explained

Numeric format

Each triplet rwx can be represented by a number. Imagine that the digit 1 means a permission is present and zero means absent. So read-only permission would be 100 (meaning r--), read and write together would be ...

The best content for your career. Discover unlimited learning on demand for around $1/day.