The Linux Command Line: A Complete Introduction


by, William E. Shotts, JR.
I just read this book and here are the notes that I took while reading:


General Definitions and Notes

  1. Shell - is a program that takes keyboard commands and passes them to the operating system to carry out

  2. Bash - a GNU Project called bash : Bourne Again Shell - Bourne is a call out to Steve Bourne

  3. Terminal Emulator - GUI access to the shell

  4. $ date - displays complete date and time

  5. $ cal - displays current month calendar and highlights current day

  6. $ df - displays the amount of free space on your disk drives

  7. $ exit - exits the terminal emulator window

  8. $ ctrl-alt-F1 through F6 - displays the Consoles running behind the scenes

  9. $ pwd - Print name of current working directory

  10. $ cd - change directory

  11. $ ls - List directory contents

  12. $ . - is the current directory

  13. $ .. - is the parent directory

  14. $ cd - entered alone takes you back to the home directory

  15. $ cd - - Changes the working directory to the previous working directory

  16. $ cd ~ - Changes the working directory to the home directory of username

  17. $ ls -a - shows all files including the hidden files that start with dot(.)

  18. $ file - determines the file type of a file

  19. $ less - View file contents

  20. $ ls -l - List with output long format

  21. $ -rw-r--r-- 1 root root:

    • - type of file
    • next three characters are access rights for the owner
    • next three characters are for members of the file's group
    • final three characters are for everyone else.
    • 1 - File's number of hard links.
    • root - user name of the file's owner
    • root - name of the group that owns the file
  22. ASCII text - (pronounced "As-Key") is short for American Standard Code for Information Interchange

  23. Less commands -

    • page up or b - scroll back one page
    • page down or Spacebar - scroll forward one page
    • G - move to the end of the text file
    • lG or g - move to the beginning of the text file
    • /characters - search forward to the next occurrence of characters
    • n Search for the next occurrence of the previous search
  24. LFHS - Linux Filesystem Hierarchy Standard

  25. symbolic link ls -l --> yields an l at the beginning with two file names

  26. cp - Copy files and directories

  27. mv Move/rename files and directories

  28. mkdir - Create directories

  29. rm - Remove file and directories

  30. ln - Create hard and symbolic links

  31. wildcards

\* Any characters
? Any single character
[characters] - any character that is a member of the set *characters*
[!characters] - any character that is not a member of the set *characters*
[[:class:]] - Any character that is a member of the specified *class*
	- [:alnum:] - any alpha numeric character
	- [:alpha:] - Any alphabetic character
	- [:digit:] - Any numeral
	- [:lower:] - Any lowercase letter
	- [:upper:] - Any uppercase letter
- * - all files
- g* - any file beginning with g
  1. Here is a useful tip: Whenever you use wildcards with rm (besides carefully checking your typing!), test the wildcard first with ls. This will let you see the files that will be deleted. Then press the up arrow key to recall the command and replace the ls with rm

  2. ln file link - to make a hard link

  3. ln file link - to make a symbolic link

  4. type - indicate how a command name is interpreted

  5. which - Display which executable program will be executed

  6. man - Display a command's manual page

  7. apropos - Display a list of appropriate commands

  8. info - Display a command's info entry

  9. whatis - Display a command's info entry

  10. alias - Create an alias for a comman

  11. Command can be four things:

- An executable program
- A command built into shell itself
- A shell funciton
- An alias
  1. type command - will examine the command

  2. which - display an executable's location

  3. help - displays quick info about a command

  4. command > filename - the > puts the command output to a filename

  5. command >> filename - the >> appends the command output to the end of the filename

  6. 2> - performs the redirection of standard error to the file

  7. Notice - that the order of the redirections is significant. The redirection of standard error must always occur after redirecting standard output or it does not work.

  8. /dev/null location to redirect to in able to throw away the output of the command (this file is called a bit bucket

  9. cat - Concatenate Files

  10. | - or pipelines reads data from standard input and send to standard output

  11. ls -l dir | less let's you page through the output of ls -l dir

  12. uniq - removes duplicates from a list

  13. uniq -d - shows the duplicates from a list

  14. wc - displays the number of lines, words, and bytes contained in a file

  15. grep - used to find text patterns within files ( -i will ignore case) - global regular expression print

    • Options:
      • i - Ignore case
      • v - Invert match
      • c - print the number of matches (count)
      • l - print the name of the file with the match
      • L - print name of file with no match
      • n - Prefix each matching line with the line number in the file
      • h - suppress the output filenames of multifile searches
  16. head - shows the first 10 lines of a file, can be adjusted with -n

  17. tail - shows the last 10 lines of a file, can be adjusted with -n

  18. echo - Display a line of text

  19. $((expression)) - arithmetic expansion

  20. ** **** - Exponentiation

  21. echo Front-{A,B,C} - will return Front-A Front-B Front-C

  22. mkdir {2009..2011}-1 - will return 2009-1 2010-1 2011-1

  23. printenv | less - will return a list of variables on the system

  24. **ls -l $(which cp) - will return the contents of cp without having to know the location of cp

  25. quoting - to selectively suppress unwanted expansions

  26. "" - if you place text inside double quotes, all the special characters used by the shell lose their special meaning and are treated as ordinary. The exceptions are:

    • $
    • \
    • `
  27. ' ' - to suppress all expansions use single quotes

  28. \ - to suppress a character use \

  29. Readline - bash uses a library(a shared collection of routines that different programs can use)

  30. Cursor Movement Commands:

    • ctrl-A - Move cursor to the beginning of the line
    • ctrl-E - Move cursor to the end of the line
    • ctrl-F - Move cursor forward one character
    • ctrl-B - Move cursor back one character
    • ctrl-L - clear the screen
  31. Cutting and Pasting (Killing and Yanking Text

    • ctrl-D - Delete the character at the cursor location
    • ctrl-T - Transpose (exchange) the character at the cursor location with the one preceding it
    • ctrl-K - Kill text from the cursor location to the end of the line
    • ctrl-U - Kill text from the cursor location to the beginning of the line
  32. set | less - shows the programmable completions

  33. history | less - browses history from the beginning

  34. !### - where ### is the history line item - will repeat the history command

  35. !! - repeat the last command

  36. id - Display user identity

  37. chmod - Change a file's mode

  38. umask - Set the default file permissions

  39. su - Run a shell as another user

  40. sudo - Execute a command as another user

  41. chown - Change a File's owner

  42. chgrp - Change a file's group ownership

  43. passwd - Change a user's password

  44. id - displays a number called a user ID, or uid. The user is assigned a primary group ID, or gid

  45. ps - Report a snapshot of current processes

  46. top - Display tasks

  47. jobs - List active jobs

  48. bg - Place a job in the background

  49. fg - Place a job in the foreground

  50. kill - Send a signal to a process

  51. killall - Kill processes by name

  52. shutdown - Shut down or reboot the system

  53. Processes

    • Upon startup, the kernel initiates a few processes and launches a program called init
    • init runs shell scripts located in /etc called "init scripts"
    • these "init scripts" start all the system services
    • many of these services are daemon programs
    • programs can launch other programs, expressed in the process scheme as a parents launch childs
    • each process is assigned a process ID (PID)
    • PIDs are assigned in ascending order, with init always getting PID 1
  54. *daemon programs - programs that sit in the background and do their thing without having any user interface

  55. & - placed after launching something, this puts the process in the background

  56. printenv - Print part of all of the environment

  57. set - Set shell options

  58. export - Export environment to subsequently executed programs

  59. Two types of shells

- *login shells* - is one in which we are prompted for our username and password
- *non-login* - when we launch a terminal session in the GUI
  1. vi - The first version of vi was written in 1976 by Bill Joy, a University of California, Berkeley student who later went on to co-found Sun Microsystems. vi derives its name from theword visual, because it was intended to allow editing on a video terminal with a moving cursor.

  2. Package Management Systems:

- low-level tools -- handle tasks such as installing and removing package files
- high-level tools -- perform metadata searching and dependency resolution
  1. rpm -qa - lists all packages installed

  2. rpm -q - determines if a package is installed

  3. dnf info package_name - get's info about installed and available packages

  4. rpm -qf - determines which package installed a file

  5. ping - Send an ICMP ECHO_REQUEST to network hosts

  6. traceroute - Print the route packets trace to a network host

  7. netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

  8. ftp - Internet file transfer program

  9. lftp - An improve Internet file transfer program

  10. wget - Non-interactive network downloader

  11. ssh - OpenSSH SSH client (remote login program)

  12. scp - Secure copy(remote file copy program)

  13. sftp - Secure file transfer program

  14. locate - Find files by name

  15. find - Search for files in a directory hierarchy

  16. xargs - Build and execute command lines from standard input

  17. touch - Change file times

  18. stat - Display file or filesystem status

  19. rsync - remote file and directory synchronization

  20. Regular Expressions - symbolic notations used to identify patterns in text:

- **.** - any single character
- **^** - anchor for search string being found at beginning of line
- **$** - anchor for search string being found at the end of the line
- **[]** - brackets are used to for expressions, character expansion
	- ^ - negation
	- \- - character range
  1. locale - display the localization settings

  2. sort - Sort lines of text files

  3. aspell - Interactive Spell Checker

  4. shell script - a file containing a series of commands

  5. here document or here script - is an additional form of I/O redirection in which we embed a body of text into our script and feed it into the standard input of a command

- example is using cat << \_EOF\_ instead of echo, so that you can use quotes freely
- here with <<\- ignores leading tab characters
  1. shell functions - are "miniscripts" that are located inside other scripts and can act as autonomous programs

  2. $? - the exit status of the last performed command

  3. ** test expression (or [ expression ] )** - evaluations

  4. string1 =~ regex - true if string matches regex

  5. ** (( )) ** - is designed for integers

  6. Combining Expressions

- AND test uses -a, [[]] and (()) use &&
- OR test uses -o, [[]] and (()) use ||
- NOT both use !
  1. read - read a single line of standard input
The Linux Command Line: A Complete Introduction
Share this