Linux Workshop

Session I

  • Introduction to FOSS and Linux
  • Files and Processes
  • Directory Structure
  • Basic Linux shell commands

Introduction

FOSS

  • Free and Open Source Software
  • Free Software Foundation(FSF) by Richard Stallman
  • Anyone is freely licensed to use, copy, study, and change the software in any way, and the source code is openly shared so that people are encouraged to voluntarily improve the design of the software

Benefits

  • Decrease Software Cost
  • Increase Security
  • Stability
  • Protect Privacy
  • Give Users control over hardware

Licenses

  • Copyleft - practice of offering people the right to freely distribute copies and modified versions of a work with the stipulation that the same rights be preserved in derivative works down the line. eg. GNU GPL3
  • Licenses considered to have minimum restrictions of that kind, like Apache license, the BSD license, and the MIT license, are called permissive software licenses.

Examples

  • Linux, Ubuntu, MySQL, Apache, Firefox, Libre
  • Open Source Games - SuperTuxCart,Battle of Wesnoth,Minetest :P

Linux

  • Unix like operating system mostly POSIX compliant
  • The defining component of Linux is the Linux kernel, an operating system kernel first released on 5 October 1991 by Linus Torvalds - GNU License
  • The underlying source code may be used, modified and distributed—​​commercially or non-commercially—​​by anyone under the terms of its respective licenses, such as the GNU General Public License. Typically, Linux is packaged in a form known as a Linux distribution, for both desktop and server use
  • distributions include the Linux kernel, supporting utilities and libraries, and usually a large amount of application software to fulfill the distribution's intended use
  • Debian, Ubuntu, Linux Mint, Fedora, openSUSE, Arch Linux and Gentoo, together with commercial Red Hat Enterprise Linux and SUSE Linux Enterprise Server distributions

Basic Linux Commands

Know the system

  • uname
    The “uname” command stands for (Unix Name), print detailed information about the machine name, Operating System and Kernel.
  • 
    $ uname -a
    Linux arjun-SVF15218SNB 3.13.0-32-generic #57-Ubuntu SMP 
    Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
    
    					
  • ls
    The command “ls” stands for (List Directory Contents), List the contents of the folder, be it file or folder, from which it runs.
  • 
    $ ls
    
    Android-Games                     Music
    Pictures                          Public
    Desktop                           Tecmint.com
    Documents                         TecMint-Sync
    Downloads                         Templates
    					
  • ls -l
    The command “ls -l” list the content of folder, in long listing fashion.
  • 
    $ ls -l
    
    total 162
    -rwxrwxrwx 1 root root   523 Feb 24 10:52 bower.json
    -rwxrwxrwx 1 root root  1062 Feb 24 10:52 CONTRIBUTING.md
    drwxrwxrwx 1 root root     0 Feb 24 10:52 css
    -rwxrwxrwx 1 root root  3338 Feb 24 10:52 Gruntfile.js
    -rwxrwxrwx 1 root root  9413 Feb 25 11:32 index.html
    drwxrwxrwx 1 root root     0 Feb 24 19:32 js
    drwxrwxrwx 1 root root     0 Feb 24 10:52 lib
    -rwxrwxrwx 1 root root  1075 Feb 24 10:52 LICENSE
    -rwxrwxrwx 1 root root 21146 Feb 24 23:08 linusTorvalds.jpg
    drwxrwxrwx 1 root root  4096 Feb 24 11:02 node_modules
    -rwxrwxrwx 1 root root  1111 Feb 24 10:52 package.json
    drwxrwxrwx 1 root root  4096 Feb 24 10:52 plugin
    -rwxrwxrwx 1 root root 41365 Feb 24 10:52 README.md
    -rwxrwxrwx 1 root root   364 Feb 24 19:08 session contents
    drwxrwxrwx 1 root root     0 Feb 24 19:33 temp
    drwxrwxrwx 1 root root  4096 Feb 24 10:52 test
    -rwxrwxrwx 1 root root 50809 Feb 24 22:38 TuxWallpaper.jpg
    
    					
  • ls -a
    Command “ls -a“, list the content of folder, including hidden files(starting with ‘.’).
  • 
    $ ls -l -a
    
    drwxrwxrwx 1 root root  4096 Feb 24 23:08 .
    drwxrwxrwx 1 root root     0 Feb 24 18:45 ..
    -rwxrwxrwx 1 root root   523 Feb 24 10:52 bower.json
    -rwxrwxrwx 1 root root  1062 Feb 24 10:52 CONTRIBUTING.md
    drwxrwxrwx 1 root root     0 Feb 24 10:52 css
    drwxrwxrwx 1 root root  4096 Feb 25 11:02 .git
    -rwxrwxrwx 1 root root   123 Feb 24 10:52 .gitignore
    -rwxrwxrwx 1 root root  3338 Feb 24 10:52 Gruntfile.js
    -rwxrwxrwx 1 root root 10965 Feb 25 11:35 index.html
    drwxrwxrwx 1 root root     0 Feb 24 19:32 js
    drwxrwxrwx 1 root root     0 Feb 24 10:52 lib
    -rwxrwxrwx 1 root root  1075 Feb 24 10:52 LICENSE
    -rwxrwxrwx 1 root root 21146 Feb 24 23:08 linusTorvalds.jpg
    drwxrwxrwx 1 root root  4096 Feb 24 11:02 node_modules
    -rwxrwxrwx 1 root root  1111 Feb 24 10:52 package.json
    drwxrwxrwx 1 root root  4096 Feb 24 10:52 plugin
    -rwxrwxrwx 1 root root 41365 Feb 24 10:52 README.md
    -rwxrwxrwx 1 root root   364 Feb 24 19:08 session contents
    drwxrwxrwx 1 root root     0 Feb 24 19:33 temp
    drwxrwxrwx 1 root root  4096 Feb 24 10:52 test
    -rwxrwxrwx 1 root root    80 Feb 24 10:52 .travis.yml
    -rwxrwxrwx 1 root root 50809 Feb 24 22:38 TuxWallpaper.jpg
    					

Know your way around

  • pwd
    pwd command (print working directory) prints the full pathname of the current working directory
  • 
    $ pwd
    
    /media/arjun/nv1/linux_workshop/reveal/css
    
    					
  • cd
    “cd” command stands for (change directory), it change the working directory to execute, copy, move write, read, etc. from terminal itself.
  • 
    $ pwd
    /media/arjun/nv1/linux_workshop/reveal
    
    $ cd css
    
    $ pwd
    /media/arjun/nv1/linux_workshop/reveal/css
    					
  • cd ..
    changes working directory to the parent direcory
  • 
    $ pwd
    /media/arjun/nv1/linux_workshop/reveal/css
    
    $ cd ..
    
    $ pwd
    /media/arjun/nv1/linux_workshop/reveal
    					
  • cd ~
    changes working directory to the home direcory
  • 
    $ pwd
    /media/arjun/nv1/linux_workshop/reveal/css
    
    $ cd ~
    
    $ pwd
    /home/arjun/
    					
  • cd <Path to the directory>
    changes working directory to the directory given in the path
  • 
    $ pwd
    /home/arjun/
    
    $ cd /media/arjun/nv1/linux_workshop/reveal
    
    $ pwd
    /media/arjun/nv1/linux_workshop/reveal
    
    					
  • history
    prints the history of the latest issued commands
  • 
    $ history
    
     2001  ls -l
     2002  ls -a
     2003  ls -a -l
     2004  ls -l -a
     2005  ls -a
     2006  ls -a -l
     2007  pwd
     2008  ls
     2009  cd css
     2010  ls
     2011  pwd
     2012  cd .
     2013  cd ~
     2014  pwd
     2015  cd /media/arjun/nv1/linux_workshop/
     2016  ls
     2017  cd /media/arjun/nv1/linux_workshop
     2018  ls
     2019  cd /media/arjun/nv1/linux_workshop/reveal
     2020  ls
     2021  pwd
     2022  man history
     2023  history
    
    					

Viewing and manipulating

  • cat <filename>
    view the contents of the file in standard output
  • 
    $ cat text.txt
    
    Hi I am A text file
    
    					
  • more <filename>
    Allows file contents or piped output to be sent to the screen one page at a time.
  • 
    $ more largetext.txt
    
    Linux is, in simplest terms, an operating system. It is the software on a 
    computer that enables applications and the computer operator to acces
    s the devices on the computer to perform desired functions. 
    The operating system (OS) relays instructions from an application to, for instance,
     the computer's processor. The processor performs the instructed task, then sends 
     the results back to the application via the operating system.
     --More--(82%)
    					
  • less <filename>
    Similar to the more command, but the user can page up and down through the file.
  • 
    $ less text.txt
    
    
    
    					
  • mkdir <directory_name>
    Make a directory in the current working directory
  • 
    $ ls -l
    
    total 5
    -rwxrwxrwx 1 root root 3163 Feb 25 12:52 largetext.txt
    drwxrwxrwx 1 root root    0 Feb 25 12:51 temp
    -rwxrwxrwx 1 root root   20 Feb 25 12:52 text.txt
    
    $ mkdir mydirectory
    
    $ls -l 
    
    total 5
    -rwxrwxrwx 1 root root 3163 Feb 25 12:52 largetext.txt
    drwxrwxrwx 1 root root    0 Feb 25 12:53 mydirectory
    drwxrwxrwx 1 root root    0 Feb 25 12:51 temp
    -rwxrwxrwx 1 root root   20 Feb 25 12:52 text.txt
    
    
    					
  • cp <source> <destination>
    Copy file in the source to the destination path
  • 
    $ cp text.txt mydirectory/mytext.txt
    
    
    
    					
  • -r modifier is used to recursively copy files(used for directories)
  • mv <source> <destination>
    Move file from the source to the destination path
  • 
    $ mv text.txt mydirectory/movedtext.txt
    
    
    
    					

    Rename ??

    mv <initial_name> <final_name>
    rename the target from initname to finalname

    
    $ mv text.txt myrenamedtext.txt
    
    
    
    					

Manpages

man <command_name>
  • Search the manual to get documentation of the particular command.
  • The man pages are a user manual that is by default built into most Linux distributions (i.e., versions) and most other Unix-like operating systems during installation

$ man man



					

Files and processes

  • On a Linux system, everything is a file; if something is not a file, it is a process
  • A wide range of input/output resources such as documents, directories, hard-drives, modems, keyboards, printers and even some inter-process and network communications are simple streams of bytes exposed through the filesystem name space.
  • The advantage of this approach is that the same set of tools, utilities and APIs can be used on a wide range of resources.
  • Now we see some types of files available in the linux system
  • Directories : files that are lists of other files
  • Special files : the mechanism used for input and output. Most special files are in /dev.
  • Links : a system to make a file or directory visible in multiple parts of the system's file tree.
  • (Domain) sockets : a special file type, similar to TCP/IP sockets, providing inter-process networking protected by the file system's access control.
  • Named pipes: act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics
  • ls -l command shows the type of the file

$ ls -l

total 5
-rwxrwxrwx 1 root root 3163 Feb 25 12:52 largetext.txt
drwxrwxrwx 1 root root    0 Feb 25 12:51 temp
-rwxrwxrwx 1 root root   20 Feb 25 12:52 text.txt

					
Symbol Meaning
- Regular file
d directory
l link
c Special File
s Socket
p Named Pipe
b Block device

Processes

  • Processes carry out tasks within the operating system.
  • During the lifetime of a process it will use many system resources. It will use the CPUs in the system to run its instructions and the system's physical memory to hold it and its data.
  • Linux must keep track of the process itself and of the system resources that it has so that it can manage it and the other processes in the system fairly.
  • Managed using the task_struct data structure. The task vector is an array of pointers to every task_struct data structure in the system.

States of processes

  • Running- The process is either running (it is the current process in the system) or it is ready to run (it is waiting to be assigned to one of the system's CPUs).
  • Waiting- The process is waiting for an event or for a resource. Linux differentiates between two types of waiting process; interruptible and uninterruptible.
  • Stopped- The process has been stopped, usually by receiving a signal. A process that is being debugged can be in a stopped state.
  • Zombie - This is a halted process which, for some reason, still has a task_struct data structure in the task vector. It is what it sounds like, a dead process.
    ps -ef
  • List the currently running processes
  • Currently running process can be stopped by using [CTR+C]
  • 
    $ ps -ef
    
    root     26551     5  0 Feb10 ?        00:03:41 [pdflush]
    root     26570     5  0 Feb10 ?        00:00:20 [pdflush]
    root     30344  3382  0 Feb21 ?        00:00:11 sshd: root@pts/14
    root     30365 30344  0 Feb21 pts/14   00:00:02 -bash
    root     30393  3382  0 Feb21 ?        00:00:10 sshd: root@pts/15
    
    					
    top
  • Realtime list of running processes
  • 
    $ top
    
    
    
    					

Directory Structure

    bin
  • User Command binaries
  • All the essential commands executed till now present in bin directory
  • boot
  • Static files of the bootloader
  • All the files necessary to boot the system
  • dev
  • Device files
  • All the devices of the system is in this directory
    home
  • User home directory
  • "cd ~" command directs to this directory
  • etc
  • Host specific system configuration
  • Extra software that is installed is found here
  • mount
  • Mount points of removable media
  • Pendrives and other removable media is found here

Thank you

Session II

  • Redirecting Input and Output
  • Pipes
  • Filenames and Wildcards
  • Permissions
  • Installing and Removing Packages
  • Basics of using vim

Redirection of Input and Output

  • Input and output are distributed accross three streams
  • Standard Input (stdin 0)
  • Standard Input (stdout 1)
  • Standard Input (stderr 2)

Standard Output

  • Writes the data that is generated by a program
  • Generally it outputs to the terminal
  • echo "Hello World"
  • However we can redirect to anywhere - files, devices, or other commands - using
     > 
    or
     >> 
  • echo "Hello World" > hello_world.txt
    less hello_world.txt
    echo "Linux is fun" >> hello_world.txt
    less hello_world.txt

Standard Input

  • Reads data from the user usually from keyboard
  • Terminated by reaching End of file (EOF)
  • cat
  • EOF can be input by using Ctrl-d
  • Redirection using
     < 
    or
     << 
  • cat hello_world.txt

All redirection commands

      Overwrite
       
    • > - standard output
    • < - standard input
    • 2> - standard error
      Append
    • >> - standard output
    • << - standard input
    • 2>> - standard error

Pipes and Filters

Pipes

  • Pipes redirect streams from one program to another.
  • The standard output of the first command is sent to the input of second command
  • ls | less
  • It will print the files and directories line by line

Filters

  • Filters are commands that alter piped redirection and output
  • Filter commands are also standard Linux commands that can be used without pipes
  •  
    							
  • find - Returns files with filenames that match the argument passed to find
  • grep - Grep returns text that matches the string pattern passed to grep
  • tr - finds-and-replaces one string with another.
  • wc - counts characters, lines, and words.

Wildcards

  • A wildcard is a character that can be used as a substitute for any of a class of characters in a search
  • It increases the flexibility and efficiency of searches
  • Star wildcard
  • Question Mark Wildcard
  • Square Bracket wildcard

Star Wildcard

  • Represented by *
  • It matches to anything and everything
  • Represents any string of zero or more characters
  • List all html files
    ls *.html
  • Remove all files of Project X
    rm *projectX*

Question Mark Wildcard

  • Represented by ?
  • Used to represent exactly one character
  • If used in succession, represent multiple characters
  • List all files with three letter names
    ls ???
  • Can u list all files with three letter extensions

Square Brackets

  • It can represent any one of the characters in the brackets
  • Listing all files starting with x or y
    ls [xy]* 
  • Hyphen is used to represent a range
  • Listing all files starting with any character from a to g
    ls [a-g]* 
  • Ranges and individual characters can be combined
  • Listing all files starting with any character from a to g or from x or y
    ls [a-gxy]*
  • List all files that contain a three digit number
    ls *[0-9][0-9][0-9]*

Permissions

Each file has three premission groups

  • owner- owner permissions apply to only the owner of the file
  • group - It applies to the only group that has been assignedto the file
  • all - It applies to everyone else

There are three types of permissions

  • Read - User permission to read
  • Write - User premission to write
  • Execute - User premission to execute

View permissions - ls -l

Changing Permission - chmod

  • Each of the permission type is represented as r for read, w for write and x for execute
  • Each group can be represented as u for owner, g for group, a or o for all
  • To remove execute and write permissions for all users
    chmod a-wx file
  • To give read and execute permissions for group
    chmod g+rx file
  • To give all permissions to owner
    chmod u+rwx file
  • Use + to grant and - to remove permissions

Binary Refernces

  • Each of the permission type for each of the group can be 0 or 1
  • Total possible for each group are 8
  • Permissions can be represented as a number between 0 to 7
  • Example
    chmod 640
  • This would change permission to 6 for owner, 4 for group and 0 for everyone
  • 6 in binary is 110 i.e. read and write permissions are set
  • 4 in binary is 100 i.e. read only permissions

Change user and group

  • Change the owner and group via chown command
  • chown owner:group file
  • Example:
    chown skidm09:wireshark index.html
  • d in the first bit indicates directory. l indicates symbolic link
  • Set permissions with caution. Remember to set only the neccessary permissions for any directory

Installing and removing packages in Ubuntu

  • APT is the application package tool of Ubuntu
  • apt-get is a command line tool that works with APT
  • Installing package
    sudo apt-get install apache2
  • Remove a package
    sudo apt-get remove apache2
  • Update the package index
    sudo apt-get update
  • Upgrade
    sudo apt-get upgrade
  • Get help
    apt-get help

Thank You