You are previewing Linux: Phrasebook.
O'Reilly logo
Linux: Phrasebook

Book Description

Linux Phrasebook is sure to become the pocket guide that you keep within reach at all times. This concise, handy reference can be used "in the street," just like a language phrasebook. Skipping the usual tutorial on Linux, the Linux Phrasebook goes straight to practical Linux uses, providing immediate applicable solutions for day-to-day tasks. It includes code phrases that allow Linux users to employ the command line to complete onerous and repetitive tasks, as well as flexible code and commands can be customized to meet the needs of any Linux user. The concise information combined with random accessibility makes the Linux Phrasebook a robust, yet agile, reference guide that no Linux user should be without.

Table of Contents

  1. Copyright
    1. Dedication
  2. About the Author
  3. Acknowledgments
  4. We Want to Hear from You!
  5. Reader Services
  6. Introduction
    1. Audience for This Book
    2. Conventions Used in This book
  7. I. Getting Started
    1. 1. Things to Know About Your Command Line
      1. Everything Is a File
      2. Maximum Filename Lengths
      3. Names Are Case-Sensitive
      4. Special Characters to Avoid in Names
      5. Wildcards and What They Mean
      6. Conclusion
    2. 2. The Basics
      1. List Files and Folders
        1. ls
      2. List the Contents of Other Folders
        1. ls music
      3. List Folder Contents Using Wildcards
        1. ls ~/videos/*.wmv
      4. View a List of Files in Subfolders
        1. ls -R
      5. View a List of Contents in a Single Column
        1. ls -1
      6. View Contents As a Comma-Separated List
        1. ls -m
      7. View Hidden Files and Folders
        1. ls -a
      8. Visually Display a File’s Type
        1. ls -F
      9. Display Contents in Color
        1. ls --color
      10. List Permissions, Ownership, and More
        1. ls -l
      11. Reverse the Order Contents are Listed
        1. ls -r
      12. Sort Contents by File Extension
        1. ls -X
      13. Sort Contents by Date and Time
        1. ls -t
      14. Sort Contents by Size
        1. ls -S
      15. Express File Sizes in Terms of K, M, and G
        1. ls -h
      16. Display the Path of Your Current Directory
        1. pwd
      17. Change to a Different Directory
        1. cd
      18. Change to Your Home Directory
        1. cd ~
      19. Change to Your Previous Directory
        1. cd -
      20. Change a File to the Current Time
        1. touch
      21. Change a File to Any Desired Time
        1. touch -t
      22. Create a New, Empty File
        1. touch
      23. Create a New Directory
        1. mkdir
      24. Create a New Directory and Any Necessary Subdirectories
        1. mkdir -p
      25. Find Out What mkdir Is Doing As It Acts
        1. mkdir -v
      26. Copy Files
        1. cp
      27. Copy Files Using Wildcards
        1. cp *
      28. Copy Files Verbosely
        1. cp -v
      29. Stop Yourself from Copying over Important Files
        1. cp -i
      30. Copy Directories
        1. cp -R
      31. Copy Files As Perfect Backups in Another Directory
        1. cp -a
      32. Move and Rename Files
        1. mv
      33. Rename Files and Folders
        1. mv
      34. Delete Files
        1. rm
      35. Remove Several Files At Once with Wildcards
        1. rm *
      36. Remove Files Verbosely
        1. rm -v
      37. Stop Yourself from Deleting Key Files
        1. rm -i
      38. Delete an Empty Directory
        1. rmdir
      39. Remove Files and Directories That Aren’t Empty
        1. rm -Rf
      40. Delete Troublesome Files
      41. Become Another User
        1. su username
      42. Become Another User, with His Environment Variables
        1. su -l
      43. Become root
        1. su
      44. Become root, with Its Environment Variables
        1. su -
      45. Conclusion
    3. 3. Learning About Commands
      1. Find Out About Commands with man
        1. man ls
      2. Search for a Command Based on What It Does
        1. man -k
      3. Quickly Find Out What a Command Does Based on Its Name
        1. man -f
      4. Rebuild man’s Database of Commands
        1. man -u
      5. Read a Command’s Specific Man Page
        1. man [1-8]
      6. Print Man Pages
        1. man -t
      7. Learn About Commands with info
        1. info
      8. Navigate Within info
      9. Locate the Paths for a Command’s Executable, Source Files, and Man Pages
        1. whereis
      10. Read Descriptions of Commands
        1. whatis
      11. Find a Command Based on What It Does
        1. apropos
      12. Find Out Which Version of a Command Will Run
        1. which
      13. Conclusion
    4. 4. Building Blocks
      1. Run Several Commands Sequentially
        1. ;
      2. Run Commands Only If the Previous Ones Succeed
        1. &&
      3. Run a Command Only If the Previous One Fails
        1. ||
      4. Plug the Output of a Command into Another Command
        1. $()
      5. Understand Input/Output Streams
      6. Use the Output of One Command As Input for Another
        1. |
      7. Redirect a Command’s Output to a File
        1. >
      8. Prevent Overwriting Files When Using Redirection
      9. Append a Command’s Output to a File
        1. >>
      10. Use a File As Input for a Command
        1. <
      11. Conclusion
  8. II. Working with Files
    1. 5. Viewing Files
      1. View Files on stdout
        1. cat
      2. Concatenate Files to stdout
        1. cat file1 file2
      3. Concatenate Files to Another File
        1. cat file1 file2 > file3
      4. Concatenate Files and Number the Lines
        1. cat -n file1 file2
      5. View Text Files a Screen at a Time
        1. less file1
      6. Search Within Your Pager
      7. Edit Files Viewed with a Pager
      8. View the First 10 Lines of a File
        1. head
      9. View the First 10 Lines of Several Files
        1. head file1 file2
      10. View the First Several Lines of a File or Files
      11. View the First Several Bytes, Kilobytes, or Megabytes of a File
        1. head -c
      12. View the Last 10 Lines of a File
        1. tail
      13. View the Last 10 Lines of Several Files
        1. tail file1 file2
      14. View the Last Several Lines of a File or Files
        1. tail -n
      15. View the Constantly Updated Last Lines of a File or Files
        1. tail -ftail -f --pid=PID# terminates after PID dies.
      16. Conclusion
    2. 6. Printing and Managing Print Jobs
      1. List All Available Printers
        1. lpstat -p
      2. Determine Your Default Printer
        1. lpstat -d
      3. Find Out How Your Printers Are Connected
        1. lpstat -s
      4. Get All the Information About Your Printers at Once
        1. lpstat -t
      5. Print Files to the Default Printer
        1. lpr
      6. Print Files to Any Printer
        1. lpr -P
      7. Print More Than One Copy of a File
        1. lpr -#
      8. List Print Jobs
        1. lpq
      9. List Print Jobs by Printer
        1. lpstat
      10. Cancel the Current Print Job Sent to the Default Printer
        1. lprm
      11. Cancel a Print Job Sent to Any Printer
        1. lprm job ID
      12. Cancel All Print Jobs
        1. lprm -
      13. Conclusion
    3. 7. Ownerships and Permissions
      1. Change the Group Owning Files and Directories
        1. chgrp
      2. Recursively Change the Group Owning a Directory
        1. chgrp -R
      3. Keep Track of Changes Made to a File’s Group with chgrp
        1. chgrp -vchgrp -c
      4. Change the Owner of Files and Directories
        1. chown
      5. Change the Owner and Group of Files and Directories
        1. chown owner:group
      6. Understand the Basics of Permissions
      7. Change Permissions on Files and Directories Using Alphabetic Notation
        1. chmod [ugo][+-=][rwx]
      8. Change Permissions on Files and Directories Using Numeric Permissions
        1. chmod [0-7][0-7][0-7]
      9. Change Permissions Recursively
        1. chmod -R
      10. Set and Then Clear suid
        1. chmod u[+-]s
      11. Set and Then Clear sgid
        1. chmod g[+-]s
      12. Set and Then Clear the Sticky Bit
        1. chmod [+-]t
      13. Conclusion
    4. 8. Archiving and Compression
      1. Archive and Compress Files Using zip
        1. zip
      2. Get the Best Compression Possible with zip
        1. -[0-9]
      3. Password-Protect Compressed Zip Archives
        1. -P -e
      4. Unzip Files
        1. unzip
      5. List Files That Will Be Unzipped
        1. -l
      6. Test Files That Will Be Unzipped
        1. -t
      7. Archive and Compress Files Using gzip
        1. gzip
      8. Archive and Compress Files Recursively Using gzip
        1. -r
      9. Get the Best Compression Possible with gzip
        1. -[0-9]
      10. Uncompress Files Compressed with gzip
        1. gunzip
      11. Test Files That Will Be Unzipped with gunzip
        1. -t
      12. Archive and Compress Files Using bzip2
        1. bzip2
      13. Get the Best Compression Possible with bzip2
        1. -[0-9]
      14. Uncompress Files Compressed with bzip2
        1. bunzip2
      15. Test Files That Will Be Unzipped with bunzip
        1. -t
      16. Archive Files with tar
        1. -cf
      17. Archive and Compress Files with tar and gzip
        1. -zcvf
      18. Test Files That Will Be Untarred and Uncompressed
        1. -zvtf
      19. Untar and Uncompress Files
        1. -zxvf
      20. Conclusion
  9. III. Finding Stuff
    1. 9. Finding Stuff: Easy
      1. Search a Database of Filenames
        1. locate
      2. Search a Database of Filenames Without Worrying About Case
        1. locate -i
      3. Manage Results Received When Searching a Database of Filenames
        1. -n
      4. Update the Database Used by locate
        1. updatedb
      5. Searching Inside Text Files for Patterns
        1. grep
      6. The Basics of Searching Inside Text Files for Patterns
      7. Search Recursively for Text in Files
        1. -R
      8. Search for Text in Files, Ignoring Case
        1. -i
      9. Search for Whole Words Only in Files
        1. -w
      10. Show Line Numbers Where Words Appear in Files
        1. -n
      11. Search the Output of Other Commands for Specific Words
        1. $ ls -1 | grep 1960
      12. See Context for Words Appearing in Files
        1. -A, -B, -C
      13. Show Lines Where Words Do Not Appear in Files
        1. -v
      14. List Files Containing Searched-for Words
        1. -l
      15. Search for Words Inside Search Results
        1. grep | grep
      16. Conclusion
    2. 10. The find Command
      1. Find Files by Name
        1. find -name
      2. Find Files by Ownership
        1. find -user
      3. Find Files by Group Ownership
        1. file -group
      4. Find Files by File Size
        1. file -size
      5. Find Files by File Type
        1. find -type
      6. Show Results If the Expressions Are True (AND)
        1. find -a
      7. Show Results If Either Expression Is True (OR)
        1. find -o
      8. Show Results If the Expression Is Not True (NOT)
        1. find -n
      9. Execute a Command on Every Found File
        1. find -exec
      10. Print Find Results into a File
        1. find -fprint
      11. Conclusion
  10. IV. Environment
    1. 11. Your Shell
      1. View Your Command-Line History
        1. history
      2. Run the Last Command Again
        1. !!
      3. Run a Previous Command Using Numbers
        1. ![##]
      4. Run a Previous Command Using a String
        1. ![string]
      5. Display All Command Aliases
        1. alias
      6. View a Specific Command Alias
        1. alias [alias name]
      7. Create a New Temporary Alias
        1. alias [alias]= ’[command]’
      8. Create a New Permanent Alias
        1. alias [alias name]= ’[command]’
      9. Remove an Alias
        1. unalias
      10. Conclusion
    2. 12. Monitoring System Resources
      1. View All Currently Running Processes
        1. ps aux
      2. View a Process Tree
        1. ps axjf
      3. View Processes Owned by a Particular User
        1. ps U [username]
      4. End a Running Process
        1. kill
      5. View a Dynamically Updated List of Running Processes
        1. top
      6. List Open Files
        1. lsof
      7. List a User’s Open Files
        1. lsof -u
      8. List Users for a Particular File
        1. lsof [file]
      9. List Processes for a Particular Program
        1. lsof -c [program]
      10. Display Information About System RAM
        1. free
      11. Show File System Disk Usage
        1. df
      12. Report File Space Used by a Directory
        1. du
      13. Report Just the Total Space Used for a Directory
        1. du -s
      14. Conclusion
    3. 13. Installing Software
      1. Install Software Packages for RPM-Based Distributions
        1. rpm -ihv [package] rpm -Uhv [package]
      2. Remove Software Packages for RPM-Based Distributions
        1. rpm -e [package]
      3. Install Software Packages and Dependencies for RPM-Based Distributions
        1. yum install [package]
      4. Remove Software Packages and Dependencies for RPM-Based Distributions
        1. yum remove [package]
      5. Upgrade Software Packages and Dependencies for RPM-Based Distributions
        1. yum update
      6. Find Packages Available for Download for RPM-Based Distributions
        1. yum search [string] yum list available
      7. Install Software Packages for Debian
        1. dpkg -i [package]
      8. Remove Software Packages for Debian
        1. dpkg -r [package]
      9. Install Software Packages and Dependencies for Debian
        1. apt-get install [package]
      10. Remove Software Packages and Dependencies for Debian
        1. apt-get remove [package]
      11. Upgrade Software Packages and Dependencies for Debian
        1. apt-get upgrade
      12. Find Packages Available for Download for Debian
        1. apt-cache search
      13. Clean Up Unneeded Installation Packages for Debian
        1. apt-get clean
      14. Troubleshoot Problems with apt
      15. Conclusion
  11. V. Networking
    1. 14. Connectivity
      1. View the Status of Your Network Interfaces
        1. ifconfig
      2. Verify That a Computer Is Running and Accepting Requests
        1. ping ping -c
      3. Trace the Route Packets Take Between Two Hosts
        1. traceroute
      4. Perform DNS Lookups
        1. host
      5. Configure a Network Interface
        1. ifconfig
      6. View the Status of Your Wireless Network Interfaces
        1. iwconfig
      7. Configure a Wireless Network Interface
        1. iwconfig
      8. Grab a New Address Using DHCP
        1. dhclient
      9. Make a Network Connection Active
        1. ifup
      10. Bring a Network Connection Down
        1. ifdown
      11. Display Your IP Routing Table
        1. route
      12. Change Your IP Routing Table
        1. route
      13. Troubleshooting Network Problems
      14. Conclusion
    2. 15. Working on the Network
      1. Securely Log In to Another Computer
        1. ssh
      2. Securely Log In to Another Machine Without a Password
        1. ssh
      3. Securely Transfer Files Between Machines
        1. sftp
      4. Securely Copy Files Between Hosts
        1. scp
      5. Securely Transfer and Back Up Files
        1. rsync -v
      6. Download Files Non-interactively
        1. wget
      7. Download Websites Non-interactively
        1. wget
      8. Download Sequential Files and Internet Resources
        1. curl
      9. Conclusion
    3. 16. Windows Networking
      1. Discover the Workgroup’s Master Browsers
        1. nmblookup -M [Master Browser] nmblookup -S [NetBIOS name] nmblookup -A [IP address]
      2. Query and Map NetBIOS Names and IP Addresses
        1. nmblookup -T
      3. List a Machine’s Samba Shares
        1. smbclient
      4. Access Samba Resources with an FTP-Like Client
        1. smbclient
      5. Mount a Samba Filesystem
        1. smbmount smbumount
      6. Conclusion