Linux Command Line Tools - Paiet/Tech-Journal-for-Everything GitHub Wiki

  • Command-Line Basics
    • Exploring Your Linux Shell
      • Bourne Again Shell (bash)
        • Based on the Unix Bourne shell (sh)
        • bash is the default shell in most Linux systems
      • csh or the C Shell utilizes a syntax that is liken to the C programming language
      • tcsh based off of csh
        • More bash-like but still different
        • The T stands for TENEX. An OS that inspired the author of tcsh
      • There are 2 types of default shells
        • Default Interactive Shell
          • The shell that the user works with to enter commands
        • Default System Shell
          • The shell that they system uses to run startup scripts
          • Typically the file /bin/sh points to the default system shell
            • Usually /bin/bash in Linux
            • Points to /bin/dash in Ubuntu
    • Using a Shell
      • Starting a shell
        • Linux can drop you straight to a shell after startup
        • In a GUI environment you can start a terminal emulator
          • XTERM, Konsole, Terminal, gnome-terminal
          • uname -a returns all the system information
      • Internal vs. External Commands
        • Internal commands are built-in to the shell
        • External commands are programs that run in the shell but aren't native to the shell
        • Internal command examples
          • cd Change Directory
            • cd ~/sally is the same as cd /home/sally
          • pwd Print Working Directory
          • echo prints a string of text
            • echo Hello
            • Useful when writing scripts and checking the content of environmental variables
          • exit terminates any shell
          • logout terminates only login shells
        • You can find out whether a command is internal or external by using the type command
          • type pwd
          • type cd
          • type bash
        • type -a will display different programs that use the same name
          • type -a cd
          • type -a pwd
        • Shell tricks and tips
          • Auto-complete commands with Tab
          • history shows list of previously used commands, usually the last 500
            • !! lists and executes the last command
            • !210 lists and executes command #210 in the list
            • history -c clears the history
            • The history is stored in ~/.bash_history
          • Ctrl+P/Up arrow Ctrl+N/Down arrow scrolls through recently used commands
          • Ctrl+R performs a reverse search of commands
          • Ctrl+S performs a forward search of commands
            • Ctrl+G quits the search
          • Ctrl+A moves the cursor to the start of the line
          • Ctrl+E moves the cursor to the end of the line
          • Ctrl+Left or Right arrow keys move the cursor backward or forward a word at a time
            • Esc+B/F performs the same action
          • Ctrl+K deletes from the cursor to the end of the line
          • Ctrl+X+Backspace deletes text from cursor to the beginning of the line
          • Ctrl+T transpose the character before the cursor with the character under the cursor
            • Esc+T transposes the word
          • Ctrl+X+Ctrl+E quick launches the default text editor
    • Exploring Shell Configuration
      • Shell configuration files are just plain text shell scripts
        • ~/.bashrc and /etc/profile
          • Make necessary changes to these files
          • $PATH add directories to search for executables
    • Using Environment Variables
      • Variables are containers for data
      • System Variables and User-Created Variables
      • $TERM

Begin

$> PS1="My New Prompt$>"
My New Prompt$> export PS1
My New Prompt$> export PS1="Prompt$>"
Prompt$> echo $PS1

  • Using Environment Variables

    • env lists all environmental variables
    • unset removes the data from the variable
  • Getting Help

    • man for the manual of a program
    • man man to learn to use man
    • man -k will perform a lookup
      • man -k "system information"
    • man is divided into 9 sections
      • Some commands can reside in multiple sections
        • passwd resides in both sections 1 and 5
        • man defaults to the lowest numbered section
        • man 5 passwd will return the manual for section 5's entry for the passwd command
    • info is like man but uses hypertext and has some internal options for navigating the manual
    • help usually gives a succinct synopsis of use for built-in commands