Executing Commands - Paiet/Tech-Journal-for-Everything GitHub Wiki

  • Basic execution
    • date
    • pwd
    • hostname
    • ls
  • Command options
    • ls -l
    • ls -l -a
    • ls -la
    • ls --all
    • cat /etc/passwd
    • ls --hide=Desktop
    • tar -cvf backup.tar /home/dpezet
  • Learning more about you
    • id
    • who -uH
  • Finding a command
    • echo $PATH
    • Shell search order
      1. Aliases
        • Type alias to list
      2. Shell reserved words
      3. Function
      4. Built-in command
        • cdexittype, etc
        • type exit
      5. Filesystem command
        • which ls
        • type ls
    • Command may not be in the path
      • locate chage
      • chage sets a password expiration
  • Shell history
    • ~/.bash_history
    • Arrow keys
    • Ctrl-P and Ctrl-N
    • history
    • !521
    • !man
    • !?<string>?
    • !!
    • !! <additional args>
    • fc 521 523
      • Edits a range of commands in the default editor
      • Commands are executed on exit
  • Tab autocomplete
  • Piping commands
    • cat /etc/passwd
    • cat /etc/passwd | sort
    • cat /etc/passwd | sort | less
      • or !! | less
  • Sequential commands
    • mkdir test ; cd ./test ; touch file.txt ; ls -la ; pwd
  • Expanding commands
    • One at a time
      • which dash
      • chsh -s /bin/dash
    • All at once
      • chsh -s $(which dash)
    • Can do arithmetic
      • echo "I am $[2015 - 1957] years old."
      • echo "There are $(ls | wc -w) files in this directory."
        • wc is word count
        • The math is done outside of the shell
  • Shell Variables
    • echo $USER
    • set
    • set | grep USER
  • Defining the PATH
    • Update in ~/.bashrc
    • PATH=$PATH:/getstuff/bin ; export PATH
  • Aliases
    • alias p='pwd ; ls --CF'
    • unalias p
  • Configuring the bash shell
    • Config files
      • /etc/profile
        • Sets up environment for all users
        • Run when you log in
      • /etc/bashrc
        • Sets up environment for bash
        • Runs each time bash launches
        • Can be overridden in ~/.bashrc
      • ~/.bash_profile
        • Sets up environment for a single user
  • Prompt
    • $ and #
    • Regular users see $
    • Root users see #
    • The prompt is defined in the $PS1 variable
    • Define in ~/.bashrc to make changes permanent
    • export PS1="[\t \w]\$ "
    • Variables
      • \! Command history number
      • \# Command number
      • \$ User promt
      • \w Full path
      • \W Current working directory
      • \[ & \] Non-printing characters
      • \\ Backslash
      • \d Date
      • \h Hostname
      • \n Newline
      • \s Shell name
      • \t Time
      • \u Username
⚠️ **GitHub.com Fallback** ⚠️