055 Ubuntu

16 Nov 2013

Ubuntu is a user-friendly Linux distribution. In this episode, we will explore some very common Linux commands for file or text manipulation, networking, file compression in terminal, so that next time we come across a unix-like or linux-like operating system with no GUI, we will be able to get around it.

Download video: mp4

Sample code: Github

Version: 13.10, 32-bit

Similar episodes: 002 Terminal, 019 Bash, 025 VirtualBox

Background on Ubuntu

  1. Linux - wikipedia
  2. What is a [Kernel](http://en.wikipedia.org/wiki/Kernel_(computing)) vs operating system - an image search in Google
  3. Linux distribution timeline + list of linux distro
  4. Graphical interfaces - GNOME, KDE, Kubuntu
  5. Ubuntu and download 13.10 32-bit

Things to learn with Ubuntu

download Ubuntu

  1. download Ubuntu *.iso file for 32-bit
  2. use VirtualBox and start Ubuntu
  3. Open Terminal application

commands

  1. What is a progam, option and an argument?

    $ ls                         # program
    $ ls -l                      # with option
    $ man ls
    $ ls -l examples.desktop     # with an argument to the option
    $ ls -l -a                   # 2 options
    $ ls -al                     # combined options
    
  2. type of command - linux program vs. a built-in shell command

    $ type cd
    $ type pwd
    $ type cat
    

super user and ordinary user

  1. current user name

    $ whoami
    myusername
    
  2. change to super user to several execute commands

    $ sudo su
    # whoami
    root
    # exit
    
    $ whoami
    myusername
    
  3. command prompt

    $ #for normal users
    # #for super users
    
  4. execute just one command as a super user

    $ sudo ls -al
    

host info

  1. uname or uname -a for info on kernel, version, operating system, etc
  2. hostname name of computer

echo

  1. printing in the standard output

    $ echo hello
    $ echo $USER
    $ echo hello $USER
    
  2. environment variables

    $ printenv
    $ printenv HOME
    

io redirection

  1. output to a file instead

    $ ls > distro.txt
    $ cat distro.txt
    
  2. output and append to a file instead

    $ ls >> o.txt
    $ cat o.txt
    
  3. output to standard output and append to a file instead

    $ ls 2> o.txt
    $ cat o.txt
    

quotation

  1. single quotes will not evaluate

    $ echo 'I am $USER'
    I am $USER
    
  2. double quotes will evaluate

    $ echo "I am $USER"
    I am sayanee
    

multi tasking

  1. start a job in the background top &
  2. list all on going jobs jobs
  3. bring a job to the foreground with job id %ID

file operations

  1. list files ls
  2. copy files cp input/path destination/path
  3. rename files mv original/path final/path
  4. delete files rm file or delete folder rm -r folder
  5. linking files ln -s original/path linked/path

folder operations

  1. Change your current directory cd
  2. print working directory pwd
  3. create folder mkdir
  4. create nested folder mkdir -p path/to/folder
  5. delete empty folder rmdir
  6. delete non empty folder rm -r

file viewing

  1. view full file cat filename
  2. view files page by page less filename
  3. view first lines head filename
  4. view last lines tail filename
  5. continuously watch new last lines tail -f filename
  6. view iwht line number nl filename

file editing

  1. create file touch filename E.g. touch distro.txt
  2. add content to it echo hello > filename. Make file distro.txt contain a list of Linux distro
  3. edit in a text editor nano nano filename
  4. word count wc filname
  5. disk space of current directory du, in bytes du -b, in kb du -k, in mb du -m

file ownership

  1. change ownership to a user chmod username filename
  2. change permission chmod u+x filename

file location

  1. locate files find path/to/dir -name filename -type d

text manipulation

  1. find lines with a certain match grep linux distro.txt
  2. find first word of each line awk '{print $1}' distro.txt -- learning grep, sed, awk

file compression

  1. tape archive
    • compress tar -czvf name.tar.gz directory
    • list tar -tzvf name.tar.gz
    • uncompress tar -xzvf name.tar.gz
  2. gnu zip format
    • compress gzip filename
    • uncompress and delete gunzip filename.gz
  3. windows zip format
    • compress several files zip file1 file2 fil3
    • uncompress unzip file1.zip

storage and processes

  1. list running process ps
    • start firefox
    • find out if firefox is running and its ID ps -aux | grep firefox and check the PID number
    • find out the PID with pidof firefox
    • quit firefox with kill [PID]
  2. how long the systen has been running uptime
  3. monitor active process top`
  4. memory usage free
  5. list disks df

scheduling

  1. wait and then execute sleep 10 && echo 'hello!!'
  2. execute every interval watch -n 2 date
  3. cronjob

networking

  1. ip addr show or ip addr show eth0 for the default network
  2. host google.com or with options for nameserver with host -t A google.com and host -t MX google.com
  3. ping google.com checks if remote host is available

package manager

  1. learn about apt-get
  2. upgrade and update with sudo apt-get update && sudo apt-get upgrade
  3. install with sudo apt-get install [package-name] and sudo apt-get install whois
  4. remove with sudo apt-get remove [package-name] and sudo apt-get remove whois

More Resources on Ubuntu

  1. Learn to code the Hard Way (Linux) by Zed Shaw
  2. Linux pocket guide

Build Link of this episode

Security Now Illustrated