GA2Ko

    GUI-ded partitioning scheme.
    (GUI as Graphic User Interface)

I. JUGGLING BALLS
+++++++++++++++++

FOLDERS AS PRONOUNS
===================

  .  - Current folder
         Example:
             $ sh myscript
             $ ./myscript
             $ sudo mv myscript /usr/local/bin/

  .. - Parent folder
         Example:
             $ pwd
             /home/virtu
             $ cd ../../usr/local/bin
             $ pwd

  ~  - home directory
         Example:
             $ cd ~; pwd
             /home/virtu
             $ sudo -i; pwd
             /root
             # exit
             $ sudo -s; pwd
             /home/virtu
             # cd ~; pwd
             # exit

  /  - root directory
        Example:
            $ pwd
            /home/virtu
            cd ../../../../../../../
            pwd
            /

FILESYSTEM TREE:
================

Install "tree"

  sudo apt-get install tree

Show root folder via "ls" (Censored):

  drwxr-xr-x   2 root root  4096 sept  15 11:41 bin/
  drwxr-xr-x  19 root root  4260 sept  24 11:26 dev/
  drwxr-xr-x 133 root root 12288 sept  24 11:27 etc/
  drwxr-xr-x   3 root root  4096 aug   30 15:08 home/
  drwxr-xr-x  22 root root  4096 aug   30 15:11 lib/
  drwxr-xr-x   4 root root  4096 sept  23 11:36 mnt/
  drwxr-xr-x   3 root root  4096 sept  16 21:33 opt/
  dr-xr-xr-x 192 root root     0 sept  24 11:25 proc/
  drwx------   3 root root  4096 juuli 19 23:52 root/
  drwxr-xr-x   2 root root 12288 sept  23 11:28 sbin/
  drwxrwxrwt   9 root root  4096 sept  24 11:39 tmp/
  drwxr-xr-x  10 root root  4096 juuli 19 23:42 usr/
  drwxr-xr-x  15 root root  4096 sept  23 11:28 var/

Let's have a closer look to some folders

  /home -- users' home subfolders:

    root@VBOX:/# tree -L 2 -d -f /home

    /home
    └── /home/virtu
        ├── /home/virtu/Desktop
        ├── /home/virtu/Documents
        ├── /home/virtu/Downloads
        ├── /home/virtu/Music
        ├── /home/virtu/Pictures
        ├── /home/virtu/Public
        ├── /home/virtu/Templates
    └── /home/virtu/Videos

  /usr subfolders:

    root@VBOX:/# tree -L 1 -d -f /usr
    /usr
    ├── /usr/bin
    ├── /usr/games
    ├── /usr/include
    ├── /usr/lib
    ├── /usr/local
    ├── /usr/sbin
    ├── /usr/share
    └── /usr/src

  /var subfolders (censored):

root@VBOX:/# tree -L 2 -d -f /var

  /var
  ├── /var/backups
  ├── /var/cache
  ├── /var/lib
  ├── /var/local
  ├── /var/log
  ├── /var/run -> /run
  └── /var/www
      └── /var/www/html

Under some older Unixes, directories are files, specially marked, but still files. You used to be able to read a directory with cat under SunOS, for example. A lot of modern filesystems might have directories as B+ trees, or some other on-disk data structure*.

--------
*) http://unix.stackexchange.com/questions/118085
        /transform-a-directory-into-file-or-a-file-into-directory/

13 PERMISSION BITS
==================

  421 d 4 2 1  4 2 1  4 2 1
  │││ │ │ │ │  │ │ │  │ │ │
  │││ │ r w x  r w x  r w x
  │││ │ owner  group  others
  │││ └ is directory?
  ││└── STICKY
  │└──  SGID
  └──   SUID

USERS AND GROUPS
================

  # adduser u123
  Adding user `u123' ...
  Adding new group `u123' (1001) ...
  Adding new user `u123' (1001) with group `u123' ...
  Creating home directory `/home/u123' ...
  Copying files from `/etc/skel' ...
  Enter new UNIX password:
  Retype new UNIX password:
  passwd: password updated successfully
  Changing the user information for u123
  Enter the new value, or press ENTER for the default
    Full Name []: ufn
    Room Number []: uroom
    Work Phone []: uwphone
    Home Phone []: uhphone
    Other []: uother
  Is the information correct? [Y/n] y
  # cat /etc/passwd | grep u123
  u123:x:1001:1001:ufn,uroom,uwphone,uhphone,uother:/home/u123:/bin/bash
       ^ ^    ^
       │ └UID └GID
       └──password in /etc/shadow

  # cat /etc/shadow

  root:!:17076:0:99999:7:::
  virtu:$6$CrWMUenx$hR5siRvkJIKwGBy3GU4TCATgrONwOm5h3rFbkHVC.dg3lWLxiUSKlX8lbdNY9Q6iGrB1wXCK/gO6CPWfHeP5l1:17076:0:99999:7:::
  ...
  u123:$6$NooGiADi$.bk8OJYtpeqDlR7Ndrkf72qmbMr/zAQzXdh81gN3MYcviRWTuTel0.AkVYXzA8QPgwooaVCDrZ31nGoHYWoV01:17076:0:99999:7:::

Note: ubuntu specific: no root account

Example:

  # apt install whois
  ...
  # mkpasswd --method=sha-512 --salt=NooGiADi u123
  $6$NooGiADi$.bk8OJYtpeqDlR7Ndrkf72qmbMr/zAQzXdh81gN3MYcviRWTuTel0.AkVYXzA8QPgwooaVCDrZ31nGoHYWoV01

  # cat /etc/shadow
  ...
  u123:$6$NooGiADi$.bk8OJYtpeqDlR7Ndrkf72qmbMr/zAQzXdh81gN3MYcviRWTuTel0.AkVYXzA8QPgwooaVCDrZ31nGoHYWoV01:17076:0:99999:7:::

Links

1. http://www.aychedee.com/2012/03/14/etc_shadow-password-hash-formats/

/etc/group
----------

  # cat /etc/group
  root:x:0:
  ...
  adm:x:4:syslog,virtu
  ...
  virtu:x:1000:
  ...
  sambashare:x:128:virtu
  vboxsf:x:999:
  u123:x:1001:

/etc/sudoers
------------

  # User privilege specification
  root    ALL=(ALL:ALL) ALL
  virtu   ALL=(ALL) NOPASSWD:ALL
  # Members of the admin group may gain root privileges
  %admin  ALL=(ALL) ALL
  # Allow members of group sudo to execute any command
  %sudo   ALL=(ALL:ALL) ALL

Note: The first ALL is the users allowed
      The second one is the hosts
      The third one is the user as you are running the command
      The last one is the commands allowed

Creating users with script

  #!/bin/sh
  group=demo
  exec < demo_people
  while read user pass surname name
  do
      useradd $user -g demo -c $surname"_"$name
      echo $user":"$pass | chpasswd
      mkdir /home/$user/public_html
      chown $user:$group /home/$user
      chown $user:$group /home/$user/public_html
      chmod 755 /home/$user
      chmod 755 /home/$user/public_html
      cp index.php /home/$user/public_html/
      chmod 755 /home/$user/public_html/index.php
      chown $user:$group /home/$user/public_html/index.php
  done

Links

1. http://unix.stackexchange.com/questions/201858/what-does-all-all-all-all-mean-in-sudoers
2. http://askubuntu.com/questions/192050/how-to-run-sudo-command-with-no-password

EXECUTABLES
===========

  input: from arguments: $1.. $9, $@, $0, $#

    $0 name of the script
    $* all args as single string
    $@ all args as array
    a=$@; echo $(a[1])
    $# number of arguments

  input:  from STDIN <

  output: to STDOUT >
          to STDERR 2>
          returned to $? (exit code)

--------
From

  http://ryanstutorials.net/bash-scripting-tutorial/bash-variables.php

We read:

  $0        - The name of the Bash script.
  $1 - $9   - The first 9 arguments to the Bash script.
  $#        - How many arguments were passed to the Bash script.
  $@        - All the arguments supplied to the Bash script.
  $?        - The exit status of the most recently run process.
  $$        - The process ID of the current script.
  $USER     - The username of the user running the script.
  $HOSTNAME - The hostname of the machine the script is running on.
  $SECONDS  - The number of seconds since process (bash) was started.
  $RANDOM   - Returns a different random number
              each time is it referred to.
  $LINENO   - Returns the current line number in the Bash script.

QUOTATION
=========

  Weak:   echo "$HOSTNAME"
          ls -l "my File With spaces.txt"

  Strong: echo '$SECONDS'
          ls -l "my File With spaces.txt"

  Command substitution: echo `time`

  Escaping with backslash:
          # Prevent the shell from interpreting a character
          # by placing a \ in front of it.
          ls -l ./my\ File\ With\ spaces.txt

BASH FLOW CONTROL
=================

  if list then list fi
  if list then list else list fi
  if list then list elif list then list fi

  case word in esac
  case word in pattern ) list;; esac
  case word in pattern | pattern ) list;; esac

  while list do list done
  until list do list done
  for variable in list do list done

  break
  continue

UNIX COMMANDS
=============

Historical approach:
--------------------

  Use commands available on Unix v.1 (SIMH)

II Wave: (Those who can't remember the past are condemned to repeat it*)
------------------------------------------------------------------------

  $ busybox
  some early build (http://spblinux.de/2.0/doc/commands.html) : basename, cat, chgrp, chmod, chown, chroot, chvt, clear, cp, cut, date, dc, dd, df, dirname, dmesg, du, dumpkmap, echo, false, fbset, fdflush, find, free, freeramdisk, grep, gunzip, gzip, halt, head, hostname, id, init, insmod, kill, killall, ln, loadfont, loadkmap, logger, ls, lsmod, makedevs, mkdir, mkfifo, mknod, mkswap, more, mount, mv, nc, nslookup, ping, poweroff, ps, pwd, reboot, renice, reset, rm, rmdir, rmmod, sed, setkeycodes, sh, sleep, sort, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet, test, touch, tr, true, tty, umount, uname, uniq, update, uptime, usleep, uudecode, uuencode, wc, which, whoami, yes, zcat, [
--------
ARQ, 2016, 0:08:16

Selection from tldr: (simplified man pages)
-------------------------------------------

ar, arp, awk, base64, basename, bash, bg, cat, cd, chgrp, chmod, chown, cmp, cp, curl, cut, date, deluser, df, diff, dig, echo, ed, env, fg, file, find, for, fsck, gcc, gdb, git, grep, gzip, history, if, ifconfig, jobs, kill, less, ln, ls, make, man, mkdir, mkfifo, more, mount, mv, nice, nmap, passwd, paste, patch, ping, printf, ps, pv, pwd, rm, rmdir, route, rsync, scp, sed, seq, sh, sleep, sort, su, sudo, sum, tail, tar, tee, test, time, touch, tr, traceroute, umount, uname, uniq, vim, wait, wc, wget, which, while, who, whoami, xargs

Usage frequency:
----------------
  See "Important Linux commands (recovered from my 2008 homepage)" (EAUAU-commands.txt)

ANNEX A. BUILD UBUNTU-G VIRTUAL MACHINE
=======================================

  # apt-get update
  # apt-get upgrade
  # apt-get install build-essential vim openssh-server man-db

ANNEX B. SCRIPT EXAMPLES
========================

minuip

  root@U-GNOME:~# sh minuip.sh
  Minu IP aadress on: 10.0.2.4
  root@U-GNOME:~# cat minuip.sh
  #!/bin/bash
  MINUIP=`ifconfig | grep Bcast | sed 's/.*inet addr://' | sed 's/  Bcast.*//'`
  echo "Minu IP aadress on: $MINUIP"

myhost # (based on [3], doesn't work in 16.10, use # hostname MYHOST)

  #!/bin/bash

  if [ $# -eq 0 ]
  then
    echo kasutamine: $0 hostname
  else
    NEW_HOSTNAME=$1
    echo $NEW_HOSTNAME > /proc/sys/kernel/hostname
    sed -i 's/127.0.0.1.*/127.0.0.1\t'"$NEW_HOSTNAME"'/g' /etc/hosts
    echo $NEW_HOSTNAME > /etc/hostname
    /etc/init.d/hostname.sh start
    su $SUDO_USER -c "xauth add $(xauth list | sed 's/^.*\:/'"$NEW_HOSTNAME"'\/unix:0'/g | awk 'NR==1')"
  fi

By the way (forward to the past :),

  root@virtu-PC:~# systemctl start hostname.service
  Failed to start hostname.service: Unit hostname.service is masked.
  root@virtu-PC:~# service hostname start
  Failed to start hostname.service: Unit hostname.service is masked.
  root@virtu-PC:~# /etc/init.d/hostname.sh start
  root@virtu-PC:~#

Annex C. GRUB2 RESCUE
=====================

How to Rescue a Non-booting GRUB 2 on Linux [4]
(tested: restore Ubuntu 16.04 dual boot)

  grub> ls
  (hd0,gpt6) (hd0,gpt5) .. (hd0,gpt2) ..
  grub> set root (hd0,gpt5)
  grub> linux /vmlinuz root=/dev/sda5
  grub> initrd /initrd.img
  grub> boot

  # update-grub
  # grub-install /dev/sda

Annex D. ADVENTURES WITH REDSTONE II/UBUNTU-GNOME DUAL BOOT
===========================================================

Install W14956 on raw HD. EPM shrink /dev/sda4. Install Ubuntu Gnome 16.04.1 alongside with Windows 14936.1000 on GPT (/dev/sda)

  nemo@nautilus:~$ sudo fdisk /dev/sda -l
  [sudo] password for nemo:
  Disk /dev/sda: 223,6 GiB, 240057409536 bytes, 468862128 sectors
  Units: sectors of 1 * 512 = 512 bytes
  Sector size (logical/physical): 512 bytes / 4096 bytes
  I/O size (minimum/optimal): 4096 bytes / 4096 bytes
  Disklabel type: gpt
  Disk identifier: 18A2F49C-B28E-4E69-8A87-9116E9CF7C43

  Device         Start       End   Sectors   Size Type
  /dev/sda1       2048    923647    921600   450M Windows recovery environment
  /dev/sda2     923648   1128447    204800   100M EFI System
  /dev/sda3    1128448   1161215     32768    16M Microsoft reserved
  /dev/sda4    1161216 337545239 336384024 160,4G Microsoft basic data
  /dev/sda5  337547264 401997823  64450560  30,8G Linux filesystem
  /dev/sda6  401997824 468860927  66863104  31,9G Linux swap
  nemo@nautilus:~$

Unable to access activities menu in Gnome-3? Press Win key!

Don't forget almost every app have it's own menu on desktop's title bar (like MacOS)

Plank
.....

Use CTRL + Rclick to configure

Use $ dconf-editor to add Dock-icon on Plank [1] (with some crashes)

  net -> launchpad -> plank -> docks -> dock1 -> show-dock-item [v]

Links
-----

  [1]. http://compizomania.blogspot.com/2016/03/plank-eddy-0110.html
  [2]. http://askubuntu.com/questions/9540/how-do-i-change-the-computer-name
  [3]. http://askubuntu.com/questions/87665/how-do-i-change-the-hostname-without-a-restart
  [4]. https://www.linux.com/learn/how-rescue-non-booting-grub-2-linux
