Wednesday, February 6, 2019

Linux Shell Jumpstart!

Linux Introduction
  • Originally released by Linus Torvalds in 1991
  • UNIX -> MINIX -> LINUX
  • Free open source under GNU General Public License
  • Many tools from the GNU Project come packaged with Linux.
      This is often referred to as "GNU-Linux".
  • Distro: (meaning distributions)
      specific group of software and conventions.
  • Major distributions (distros): Arch, Debian, Red Hat, Slackware
  • Linux Mint, Ubuntu, kali, are derived from Debian
  • CentOS, Fedora, are derived from Red Hat
  • Bash shell is available on most distros and OSes.
  • Be aware of what system you're using and
      adapt to account for differences in distributions.
    • How to setup
      • Cygwin
      • Windows 10 has subsystem for Linux,
          which provides a bash shell environment.
          It runs within Windows instead of in a VM.
      • Using a Virtual Machine
      • macOS is derived from BSD/UNIX, not from Linux
        • macOS has similar but not the same tool chains.
        • macOS includes the Bash shell.
        • Go to applications and open up a terminal. There you go.
        • Using a Cloud Provider
          • Azure, AWS, GCP, DigitalOcean, Linode and more.
          • Ubuntu/Debian available instance for low tier.
          • Record the provided username and password/key for security login
              and SSH connection.
          • connect: ssh username@11.22.33.44
          • Early Windows system may not have SSH,
              download PuTTY to connect to the cloud server using SSH.
              PuTTY.org
            • Download files from GitHub
              # open property by clocking top left logo, to select font size
              #
              # To run a command as administrator (uer "root"), use "sudo ".
              % man sudo_root
              # ctrl+shift+[+] # to enlarge
              % sudo apt install git ## to use git
              % git clone git://github.com/path/to/files
              
              Command-Line basics
              • CLI: command line interface
              • CLI sends typed commands to OS
              • CLI display text output
              • The environment we use is called "shell" or "interpreter.
              • Early Thompson shell for UNIX in 1971
              • Bash: Bourne-again shell
              • General command Syntax:
                  % Command Options Arguments
              • % ls -aFl /mnt/c/Users/username/Desktop
                % grep "findthis" file.in
                
                General Commands
                % cd
                % pwd
                % man cd
                % which ls
                % find . -name "*in"
                % grep pattern file.txt
                % sort -u file.txt
                % echo text
                % export PATH=.:$PATH
                % man nano
                % which nedit
                % which kate
                
                login shell and profile
                When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior. When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc. In general .profile - for things not related to Bash, like environment variables PATH .bashrc - for configuring the interactive Bash usage like aliases, editor and prompt
                % export VISUAL=vim
                % export EDITOR="$VISUAL"
                % export PS1="\u@\h\\$ "
                % export PS1="[\w] \!> "
                % export PS1="\u@\[\e[31m\]\h\[\e[m\] "
                
                .bash_profile - for make sure .profile and .bashrc are loaded for login shells - If .bash_profile is omitted, only .profile would be loaded.
                % . ~/.profile
                % . ~/.bashrc

                No comments:

                Post a Comment