1 of 21

Unix SIG

https://tinyurl.com/rm7pskd

2 of 21

What is Unix, Linux etc.?

Many OS like MacOS/OSX and Ubuntu, have similar features to AT&T Unix. Hence called “Unix-like OS”.

Shell is the basic user interface. It may be graphical(GUI) or terminal interface.

Unix shell is the interface with ‘unix-like’ commands!

Bash is the language for the shell scripting. I.e, language to communicate with the “shell”.

Ubuntu is an operating system which is built on the Linux Kernel. It is based on Debian (another OS).

DistrOS is just the same as OS (or different versions of linux OS).

Difference between Unix and Linux

  • AT&T ‘s Unix was originally commercial networking OS
  • GNU (GNU’s Not Unix) - Free Software alternative to AT&T Unix OS
  • Linux - Originally, the kernel for the GNU software

Today, “Linux” is used to refer to the whole GNU/Linux System.

2

Things to Note-

Commands are “CASE sensitiVe” in the command line.

GNOME Shell (GUI) on Ubuntu

3 of 21

Manpages

Use the man command wherever possible.

Start with man man !

If you already know the command and want to know it’s usage,

Check out tldr , you can install it by using

sudo apt install nodejs npm

sudo npm install -g tldr

(you could also use yarn)

To get a breakdown of the command checkout,

explainshell.com

And paste the command in the search box!

3

4 of 21

Why use Linux and GNU software?

  • A lot easier to find free and more productive software because of the app store(or package manager)
  • Being able to try out random new software directly from someone’s github/gitlab account.
  • Linux Ecosystem greatly boosts productivity for programming/development.
  • No dialog boxes or auto-updates
  • Very secure and stable

Why use free software?

Some Notable Linux Software which are available on Windows,

  • STEAM Games
  • Gimp (Photo Editor)
  • Blender (Video Editing / Animation)
  • VLC

4

Most windows applications can work on linux with the help of wine and playonlinux.

#JustAMeme

5 of 21

Some Basic CLI Commands/Tools

  • cd
  • ls
  • cat
  • sudo
  • pwd
  • mkdir/rmdir
  • cp
  • mv
  • chmod
  • echo
  • grep
  • man
  • diff

5

  • Change Directory
  • LiSt files/content of directories
  • Show content / conCATenate files
  • get admin power (SuperUser DO)
  • Print Working Directory
  • Make and remove directories
  • Copy file
  • Move file
  • Change Permissions
  • Print word/string
  • Search for line with pattern in files
  • Manual for command
  • Differences between two files

Piping will also be needed!

Install the following applications with

sudo apt install <pkgname>

Packages to install:

  • fzf
  • tree
  • fortune
  • cowsay
  • youtube-dl

6 of 21

Flags

Examples-

  • ls -A
  • ls -l
  • ls -lisa
  • ls -l --inode --size --all
  • cp -r
  • mkdir -p
  • rmdir --parents
  • grep -e
  • rm -r
  • tree -L 1
  • ln -s

6

Extra statements to the command that tell it what to do!

If man doesn’t work,

Try the ‘--help’ flag,

cat --help

Install the following applications with

sudo apt install <pkgname>

Packages to install:

  • fzf
  • fortune
  • cowsay
  • tree
  • youtube-dl

tree

Prints a tree with all the files of a folder

ln

Creates a link to folder or file

7 of 21

Different customizations

7

You can start by getting a fancy color theme for your terminal on:

http://mayccoll.github.io/Gogh/

or search ‘gnome terminal gogh colors’

or,

bash -c "$(wget -qO- https://git.io/vQgMr)"

8 of 21

8

Nested Commands & Piping

fortune

Prints a random quote/proverb

compgen

Tries to match a word with a shell commands

cowsay

Ascii art of a cow saying the output

fzf

‘Fuzzy finder’ intended to search for files.

Gedit is the default “notepad”. You could also use “code” (VSCode) or “atom”(Atom) or vi!

Nautilus is the file manager.

apt

A terminal version of an app store. With features like searching, showing installed… etc.

less

Show output in easy scrollable format. (vi keys)

9 of 21

The ~/.bashrc configuration file

9

alias ls='ls --color=auto -A'

alias egrep='egrep --color=auto'

alias pullff=’git pull --rebase’

PS1='[\W]\$ ' #ezprompt.net/ or bashrcgenerator.com/

alias cls='clear && ls'

alias fm=’nautilus .’

alias fu=’sudo’

caf (){

cd “$@” && clear && ls

}

# Change some default bash options

shopt -s autocd

shopt -s cdspell

# Extend the PATH to include more directories with “:”

export PATH="$PATH:.yarn/bin:.npm-global/bin"

# Have a stegosaurus read out a quote whenever you open a terminal

fortune -s wisdom | cowsay -f stegosaurus

#neofetch

#curl wttr.in/pilani

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

# Aliases

# Bash Prompt

# Alias

# Alias for file manager

# Sometimes swear words work?

# Simple Function with”$@”

# autocomplete cd

# autocomplete filenames

10 of 21

Links, Variables

Configuration Files

  • Making soft links with ln -s
  • Setting Variables
  • Viewing variables with env
  • The PATH variable

10

Important Configuration files (in ~),

  • .inputrc
  • .bash_profile
  • .config/ (folder)

And for advanced system-wide configuration et cetera folder in root,

/etc

For a history of all your commands, see ~/.bash_history

For a fancy/powerful terminal,

  • powerline
  • tmux (advanced)
  • neofetch

For a fancy vim editor,

  • neovim with vim-bootstrap for configuration
  • doom-emacs or spacemacs for more capabilities but with vim keys
  • Atom/VScode with vim plugins!

Vimium is an extremely efficient plugin on chrome!

For a fancy desktop,

  • GNOME-shell Extension
  • A different Desktop Environment like KDE

11 of 21

Cool Scripts

11

mkcd(){

NAME=$@;

mkdir -p "$NAME";

cd "$NAME";

}

yt-music() {

# Get the title name

TITLE=$(youtube-dl --get-title --default-search ‘ytsearch’ \”$@\”)

cowsay “Now Playing - “$TITLE

# Play the Audio in vlc

vlc "$(youtube-dl --get-url --default-search 'ytsearch' \"$@\" | tail -1)"

}

Play Music From Youtube

Create folder and switch to it

searchit(){

thingtosearch=$@;

firefox --search $thingtosearch

}

Open search in firefox

12 of 21

Bash tricks

12

cut command

cut -d":" -f1,7 hello.txt

Cut with delimiter “:” and take the 1st and 7th fields of the file ‘hello.txt’

ls -l | cut -c 1

Take the output of “ls -l” and cut the first column.

Bash is CASE-sensitive (for commands) and space-sensitive.

Press “tab” to autocomplete a word!

13 of 21

More Command Line Tools

  • fasd
  • caa (for Sophos wifi)
  • googler / ddgr
  • pandoc
  • taskwarrior
  • ranger
  • youtube-dl / youtube-viewer
  • neofetch

More CLI Tools recommended to learn,

  • git
  • xargs
  • ag
  • cURL
  • crontab
  • xdotool
  • awk
  • vim/emacs

13

For a complete list of amazing applications,

Check

Archwiki - List of Applications

find . -maxdepth 1 -type f | xargs wc -w

(print word count of all files in dir)

youtube-dl -x --audio-format mp3 --playlist-end 50 --autonumber-start 1 -o "%(title)s.%(ext)s"

(download playlist of songs from youtube)

14 of 21

Linux File System

  • /boot files for startup process, bootloader
  • /dev file-like access points to hardware devices (psuedo-filesystem)
  • /etc et cetera (Also known as ‘editing to configure’)
  • /home home directory for each users is stored as a folder
  • /media (relatively new) automatic mount
  • /mnt (mostly useless) Originally, for mounting usb/drive
  • /opt Some softwares or applications written on your own
  • /proc pseudo-fs for status of each system process, cpu processes
  • /root root user's home folder. (in emergencies; require su)
  • /run tempfs (in RAM)
  • /srv service data for servers; better security
  • /system tempfs (in RAM)
  • /tmp temporary file systems for recovering (some may not delete)
  • /usr Applications that are not essential
    • /bin or /usr/bin files for running
    • /sbin or /usr/sbin 'sudo' bin files
    • /lib or /lib64 or /usr/lib packages, libraries data files for packages
  • /var files expected to grow in size;

14

Links

15 of 21

Understanding Tee

15

Search Results

Only Numbered Lines

www.website.com]

Sr. No. + Title

Same Output is Split

Final websites

Title Only

ddgr -n 8 --np hello world

grep ^.[0-9]

tee >( ___) |

cut -d ‘[‘ -f 2

cut -d ‘]‘ -f 1

sed ‘s/\[.*]$//’

cut -d ‘[‘ -f 1

sed ‘s/\]//’

cut -c 2-

Check the command on explainshell.com

There’s a shortcut and the answer lies in the meme on slide 1

Vim Keys:

% Run on current file

! Run command in shell

ddgr -n 8 --np nalanda bits pilani | grep ^.[0-9] | tee >( cut -d '[' -f2 | cut -d']' -f1 ) | cut -d '[' -f 1

16 of 21

Resources

Archwiki - List of Applications

A more complete Awesome List of unique and cool Apps for linux. From audio-visualizers to computational-biology software

Missing CS Semester - MIT

An amazing beginner-level course to improve your basic productivity while programming.

Explain Shell

Gives you a better breakdown understanding of any shell command

It’s FOSS - Ubuntu Guide

This guide helps any beginner get acquainted with using Ubuntu more effectively.

Data Science at the Command Line

A slightly advanced usage of the command line for better efficiency as a data scientist.

Bash One-Liners

Awesome and popular one-line bash scripts!

16

If something goes wrong,

  • Ubuntu Forums
  • Archwiki
  • man
  • journalctl

17 of 21

Summary

  • man and tldr wherever possible
  • Basic cli commands
  • Commands with flags
  • Piping/Nesting different commands
  • Bash tricks
  • cut command
  • The .bashrc file
  • Aliases
  • Making a fancy bash prompt (PS1)
  • Write a simple function and adding to .bashrc
  • Making a stegosaurus read out quotes when you open the terminal
  • “$@” and “$1” in functions
  • Function to play youtube music from terminal
  • Understanding the Tee command
  • Linux File System

  • man
  • tldr
  • fortune
  • less
  • fzf
  • cowsay
  • compgen
  • apt
  • gedit
  • nautilus
  • cut
  • env
  • ln
  • tee
  • firefox
  • youtube-dl

17

Always Check man, tldr or try the --help flag. You could also search it!

18 of 21

THANKS!

Feel free to ask doubts!

Follow Me on Github: cheese-cracker

uday-singla

hedonhermdev

18

neofetch

Numix Square Icon Theme

Nordic GTK3 Theme

Checkout Slack: bitsacm.slack.com

19 of 21

Appendix - A view into the O.S.

Ubuntu - Build on Debian, Uses GNOME by default

Manjaro - Built on Archlinux, Choice of D.E.

Alternative Desktop Environments: xfce, mate, cinnamon...

19

Desktop Environment

GNOME(Ubuntu)

KDE

Some Alternatives

Display Manager

GDM

KDM

LightDM

Default File Manager

Nautilus

Dolphin

Thunar, pcmanfm

Window Manager

(Gnome)

(KDE)

Openbox, i3, awesome

Widget Toolkit

GTK

QT

Tk, kivy, wxwidget

Component

Popular(Ubuntu)

Alternatives

Bootloader

Grub

(few unimportant)

Shell Scripting Language

Bash

Zsh, Fish

Default Init System

Systemd

Runit

Network Managers

NetworkManager

ConnMan, netctl

Display Server

X.org (X11 Protocol)

Wayland Compositor (Wayland)

20 of 21

Appendix - Search Script

20

gofetch(){

local optionno # Stores the option number

local output # Stores the output URL

local tempfile=$(mktemp) # Tempfile for storing output of tee

read -p "Search: " query # Take Input from terminal

# Get option no. selected after search

optionno=$(ddgr -x -n 8 --np $query | tee >(grep http.*:// >${tempfile} ) | grep ^.[0-9] | fzf -1 -0 --no-sort +m | cut -c 2)

# Test with cat ${tempfile}, echo $optionno

local N=0

while IFS= read -r line

do

if [ $((optionno - 1)) = $N ]

then

output="$line"

echo "$N = $line"

fi

let "N= $N + 1"

done < ${tempfile}

notify-send "Search results for Query: $query" # Send a notification that the search results are ready!

firefox --new-tab $output # Open the search result in a new tab

rm ${tempfile} # Delete tempfile

}

Searches the tempfile for the url with index ‘optionno

Warning: It doesn’t always work… try finding test cases where it fails!

21 of 21

Appendix - Package Managers

21

O.S.

Package Manager

Debian/Ubuntu

apt

Mac

homebrew

ArchLinux

pacman

Windows

Chocolatey

Language Specific

Package Manager

Python

pip, anaconda

NodeJS

yarn, npm

Ruby

gems

Lua

LuaRocks

LaTex

tlmgr

Rust

cargo

Basic Operations -

  • Install
  • Uninstall
  • Update
  • Search
  • Show Info

(sometimes admin permissions ‘sudo’ are required for install/uninstall/update)

Debian Installer

(not a package manager)

dpkg