Shell

  • What is the shell?
    A command line-interface (CLI) to interact with computer.
    It is a Textual Interface. When we use a shell, we open a terminal to communicate with it. Shell is a program typically without graphic interface, running in the back of computer, while terminal is another program with a visualized interface. It has a prompt where we can input commands. These command will be interpreted and conducted by shell. Furthermore, the output of the commands will be shown in the terminal. (That is: Terminal is a program, a function, which accept the commands of user and show display the output from operating system.)

  • Common shells: bash(supported by almost all UNIX systems), zsh, fish

Shell Commands

The shell parses the command by splitting it by whitespace, and then runs the program indicated by the first word, supplying each subsequent word as an argument that the program can access.

Basic structure: [command] [flag] [arguments]

Some Functions And Program

How does it know what these program are?
The shell is a programming environment, just like Python or Ruby, and so it has variables, conditionals, loops, and functions
So when we run command actually we run a piece of code on it and shell interpret it.
Computer are chipped with these centric applications and they are stored somewhere.
If the shell is asked to execute a command that doesn’t match one of its programming keywords, it consults an environment variable called $PATH that lists which directories the shell should search for programs when it is given a command.

  • man (command) : RTFM.
  • date
  • echo  If you want to input an argument containing more than one word (word separated by whitespace), you could quote it or use single quote to escape.   e.g. echo "Hello, World"
  • which Find out which file will be executed for a given program name.
  • chmod: For permission management
    • rgo:User, Group, Other
    • rwx: Read, Write, Execute
Permissionfor Filefor Directory
rRead (4)List content (ls)
wWrite (2)i.e.add/remove files
xExecute (1)Search (cd to it.)
d for directory.

Navigating in the Shell&&Traverse the File System:

  • pwd: Print Work Directory.
  • cd: Change Directory.
    • ~:Home
    • -: Directory previously in
    • \:Root
  • ls: List what lives in a given directory.
    • -l: Detailed information including permissions.
  • mv: Move a file / Rename a file.
  • cp: Copy.
  • mkdir: Make a new Directory.
  • man: Take an argument as the name of program and show its manual. Press q to quit.
  • cat
  • head: read the first 10 lines
  • less: read larger files
  • rm

Most command receiver flag and option (flag with values) starting with - , which can modify their behavior. . for current directory and .. to its parent directory.

With these commands we can do Shell Scripting with bash.

Note

  • !! : Entire last command, including arguments.
    A common pattern is to execute a command only for it to fail due to missing permissions; you can quickly re-execute the command with sudo by doing sudo !!

Editors

  • Nano
  • Vim
  • Emacs

Usage: [editor name] [file]

Shell Scripting

Open Source Software (OSS)

Free and Open Source Software (FOSS) or Free/Libre Open Source Software (F/LOSS)

“Free as in beer, and free as in freedom”

The Four Freedoms

  1. The freedom to run the program as you wish, for any purpose.
  2. The freedom to study how the program works, and change it so it does your computing as you wish. Access to the source code is a precondition for this.
  3. The freedom to redistribute copies so you can help others.
  4. The freedom to distribute copies of your modified versions to others. By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.

Open source software:

Term used by some software and technology companies. You may not have the right to use, modify, or redistribute the software or source code.

OSS Licenses: Legal Jiggery-Pokery

  • Copyleft (GPL)
    • “I want to make sure that all versions of GNU remain free.” - Stallman (GNU Manifesto)
    • “a cancer that attaches itself in an intellectual property sense to everything it touches” - Steve Ballmer
  • Permissive (MIT, BSD, Apache, WTFPL)
    • Do whatever you want (basically)

UNIX

Unix’s advantages over non-Unix systems

  • UNIX philosophy: simple, short, clear, and modular code
  • UNIX idea: “everything is a file”
  • Worse is better.
  • Sockets for networking, now copied beyond Unix systems
  • “It’s very simple — you read the protocol and write the code.” - Bill Joy on implementing TCP/IP