SlideShare a Scribd company logo
GNU/Linux and Bash basics 
Constantine Nosovsky 
1
Table of contents 
History. What Linux and Bash are and what they are not 
File system (structure, files/dirs, links, file types, locations) 
Users, groups, permissions 
Processes (organization, types, states, signals) 
Bash functionality 
GNU utilities and tools 
2 of 24
Bash and Utilities 
User session, bash configuration 
Bash CLI vs. scripts 
Command execution, POSIX arguments 
Variables (usage, environment) 
File streams, pipelines, command substitution 
Text processing 
Program execution, processes 
File system management 
Permissions 
Network 
3 of 24
History 
4 of 24 
1969 – Unix: multi-tasking, multi-user OS in assembly language 
1973 – Unix was rewritten to C 
1983 – GNU: GNU’s Not Unix. GPL. GCC. GRUB. Bash 
1987 – MINIX: educational OS 
1991 – Linux kernel. “I'm doing a (free) operating system (just a 
hobby, won't be big and professional like gnu)” 
1993 – Slackware Linux: the first official distribution
Linux history today 
5 of 24 
15M lines of code (excluding comments, blanks) // ohloh.net 
Around 5k commits per month // ohloh.net 
Some contributor companies: Red Hat, Intel, IBM, Nokia, 
Samsung, Oracle, Google, AMD, Microsoft // linuxfoundation.org 
75% of all kernel development is done by developers who are 
being paid for their work // linuxfoundation.org 
Hundreds of distributions, variety of platforms 
469 of 500 TOP computers use Linux // top500.org
File system (structure, files/dirs) 
Root directory “/” is required to be mounted 
Every directory contains link to itself “.” and parent directory “..” 
“~” is a user’s home directory 
Refer to the file by its 
Absolute path – starting from the root directory: /bin/bash 
Relative path: ~/.bashrc, ./hello.sh, ../hello.sh 
File is a sequence of bytes. 
Directories contain file metadata: length, timestamps, type, 
owner, permissions, etc. 
6 of 24
File system (links) 
Symbolic (soft) link (ln -s) 
Dir1 
File1 metadata 
File2 metadata 
… 
File1 content on disk 
Hard link (ln) 
Dir2 
File3 metadata 
File4 metadata 
… 
File3 content on disk 
File1 content on disk 
Dir1 
File1 metadata 
File2 metadata 
… 
Dir2 
File1 metadata 
File3 metadata 
… 
7 of 24
File system (file types, pseudo fs) 
Regular file (text, binary), directory, symbolic link, socket, pipe 
/dev – Devices related files 
Block, character devices (storage, sound, input, net, tty) 
Pseudo files (urandom, null) 
/proc – Processes related files 
/proc/<PID>/ - information related to the process with PID 
cpuinfo, meminfo, version, modules, uptime, etc 
8 of 24
File system (some locations) 
9 of 24 
/boot – loader, kernel images 
/bin – base programs (shell, system-utils), /sbin – for super user 
/etc – system configuration, service management scripts 
/home – home directories of regular users 
/lib, /lib64 – basic system shared libraries 
/tmp – temporary file system (cleaned after reboot) 
/media, /mnt – mounted storage devices 
/lost+found – used for recovery 
/var – often changed files: logs, cache, locks 
/usr – user space software related: executables, libs, docs, src, 
headers, resources
Users, groups, permissions 
10 of 24 
/etc/passwd,group,shadow – user, group, passwords storage 
File permissions: read, write, execute 
Dir perm: read(metadata), write(metadata), execute(change dir) 
Each file has user and group owners 
Rules applied in order user-group-others (e.g. rwx r-x r--) 
root (UID=0) has all permissions 
SUID/GUID – bits to run as user/group owner 
Sticky bit is used to grand permissions exclusively to the owner 
Default permissions are set up with umask or mounting fs
Processes (organization, types) 
Organization 
Each process has PID and parent PID (PPID) 
Each process belongs to a process group 
Groups are associated with a terminal session 
Types 
11 of 24 
System processes are run from kernel in a special way (e.g. init) 
Daemon – process detached from the session attached 
Regular user space processes
Processes (states, signals) 
Process states (ps) 
R - Running or runnable (on run queue) 
D - Uninterruptible sleep (usually IO) 
S - Interruptible sleep (waiting for an event to complete) 
T - Stopped, either by a job control signal or because it is being 
traced 
Z - Zombie process, terminated but not reaped by its parent 
Signals (kill) 
KILL, TERM, STOP, CONT, CHLD 
12 of 24
User session, bash configuration 
Terminal session is created 
/bin/login is run for authentication 
User data are read from /etc/passwd, group (home dir, shell) 
Specified shell is run for user (parent process of the session) 
Shell is set up with global settings /etc/bashrc, /etc/profile 
Shell is set up with user configuration ~/.bashrc, ~/.bash_profile 
Do your stuff… 
Exiting from shell will end up terminal session 
13 of 24
Bash CLI vs. scripts 
Execute script 
#! /bin/bash 
command1 
command2 
... 
$ ./script.sh 
Run commands 
$ command1 
$ command2 
$ … 
Interpret script 
command1 
command2 
... 
$ bash ./script.sh 
14 of 24
POSIX command line arguments 
15 of 24 
An option is a hyphen followed by a single character, e.g. -o 
An option may require an argument, e.g. 
-o argument or -oargument 
Options that do not require arguments can be grouped, e.g. 
-lst is equivalent to -t -l -s 
Options can appear in any order, e.g. -lst is equivalent to -tls 
Options can appear multiple times. 
Options precede other nonoption arguments: -lst nonoption 
The -- argument terminates options 
grep -RE '^s*<([a-z]+)>.*$' /usr -i --line-number
Variables (usage, environment) 
Usage 
VAR=value – declaration (script scope) 
$VAR – access value 
export VAR – accessible outside the script (session scope) 
Command line arguments may be accessed like $0, $1,… 
Environment variables 
SHELL, USER, HOME, PATH, PWD 
Use env to list all variables and their values 
16 of 24
File streams, pipelines, command 
substitution 
File streams >, >>, < 
echo ‘hello, world!’ > file 
grep hello < file 
find –name file 2>/dev/null 1>find_result 
find –name file 2>&1 
Pipelines stream output of one command to the input of another 
ps aux | grep ^gptest | tr -s ' ' | cut -f2 -d ' ' | xargs 
Command substitution 
echo Current time is `date` 
17 of 24
Text processing 
Use less to view/navigate the large text files 
Count symbols, words, lines with wc 
Print file(s) with cat file1 file2 file3 
Use cut to filter columns out, e.g. cut –f5 –d ‘:’ 
Use grep to match text by pattern 
Use simple text editor nano for interactive file editing 
Use tr and sed for stream editing, e.g. 
sed s/regexp/replacement/ file > file_modified 
Use head/tail for specific line range, e.g. 
head –n 10000 dev.log | tail –n 100 
18 of 24
Program execution, process 
management 
19 of 24 
Use & to run program in background 
Use Ctrl+Z to pause the execution in foreground 
Use bg/fg to continue execution 
Use Ctrl+C to kill program in foreground 
Use disown to detach background program from current 
session. Or run programs in a way nohup <executable> & 
List processes with ps, top, htop 
Send signal to process with kill <signal> <pid> 
Run commands as different user using sudo
File system management 
20 of 24 
Mount volumes to file system like mount /dev/sda1 /mnt/d, 
mount -o loop file.iso /mnt/cdrom 
Get volume/file(dir) size with df –h / du -sh dir 
Create new directories with mkdir 
Change current directory using cd 
Print current directory using pwd 
List directories and access file metadata with ls 
Use find to locate files by name, type, size, timestamps, etc 
Copy files with cp , move/rename with mv, remove with rm 
Create links with ln and soft links with ln -s
Permissions management 
21 of 24 
Set file permissions with chmod, e.g. chmod o+rw dir -R 
Change file user/group owner with chown/chgrp 
Set default permission mask with umask 
Get your identity with id 
Use ls –l to read file permissions, e.g. ls -l file 
-rw-r--r-- 1 root root 30608 Nov 26 2010 file 
Use su, sudo to run as user 
Know your limits: mounting options (/etc/fstab), file types
Network 
Check server availability with ping, traceroute 
Get your network configuration with ifconfig, netstat 
Use download utilities wget, scp 
You do even have a text browser links 
22 of 24
Learn stuff 
23 of 24 
Use man <cmd> and <cmd> --help to read documentation 
Some commands are just obvious: sort, uniq, date 
Google command line solutions for common problems 
“How to capture screen in bash” 
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 f.mpg
Thanks for you attention 
Questions? 
24 of 24

More Related Content

PDF
PPT
Unix/Linux Basic Commands and Shell Script
PDF
Unix Shell Scripting
PDF
Complete Guide for Linux shell programming
PDF
Module 02 Using Linux Command Shell
PDF
Basic linux commands
PPT
Basic 50 linus command
PPT
Linux commands and file structure
Unix/Linux Basic Commands and Shell Script
Unix Shell Scripting
Complete Guide for Linux shell programming
Module 02 Using Linux Command Shell
Basic linux commands
Basic 50 linus command
Linux commands and file structure

What's hot (20)

PDF
Unix Shell Script
PPT
Shell programming
PDF
Basic Linux commands
PPTX
Linux command for beginners
PPTX
Basic commands of linux
PPT
Shell Scripting in Linux
PDF
Basic linux commands for bioinformatics
PDF
Basic commands
PPT
Basic command ppt
PDF
Linux Basic Commands
PPTX
Bash shell scripting
ODP
Linux commands
PPT
Linux shell scripting
PPTX
Know the UNIX Commands
PPT
Linux basic commands
PPTX
Unix - Filters/Editors
PPTX
Unix slideshare
PPTX
Linux basic commands
PPTX
Linux powerpoint
PDF
Unix Command Line Productivity Tips
Unix Shell Script
Shell programming
Basic Linux commands
Linux command for beginners
Basic commands of linux
Shell Scripting in Linux
Basic linux commands for bioinformatics
Basic commands
Basic command ppt
Linux Basic Commands
Bash shell scripting
Linux commands
Linux shell scripting
Know the UNIX Commands
Linux basic commands
Unix - Filters/Editors
Unix slideshare
Linux basic commands
Linux powerpoint
Unix Command Line Productivity Tips
Ad

Viewers also liked (16)

PPT
Linux command ppt
PDF
Booting & shut down,
PPTX
Linux shell env
PPTX
Shell scripting
PPT
Booting Up And Shutting Down Computer
PDF
Principles of management report
PPTX
Network_Administration_PPT
PPT
Bash shell
PPT
Unix Shell Scripting Basics
PDF
Getting Started With Linux Administration
PDF
Intro to Linux Shell Scripting
DOC
RedHat Linux Administrator
PPTX
Linux commands
PDF
Shell Scripting
PPT
Basic Linux Internals
PPTX
Linux Administrator - The Linux Course on Eduonix
Linux command ppt
Booting & shut down,
Linux shell env
Shell scripting
Booting Up And Shutting Down Computer
Principles of management report
Network_Administration_PPT
Bash shell
Unix Shell Scripting Basics
Getting Started With Linux Administration
Intro to Linux Shell Scripting
RedHat Linux Administrator
Linux commands
Shell Scripting
Basic Linux Internals
Linux Administrator - The Linux Course on Eduonix
Ad

Similar to Linux Shell Basics (20)

PPTX
An Introduction to Linux
PDF
Lesson 2 Understanding Linux File System
ODP
Nguyễn Vũ Hưng: Basic Linux Power Tools
PPT
8.1.intro unix
PDF
Linux Fundamentals and how to use linux.pdf
ODP
Linux introduction-commands2338
ODP
Linux Introduction (Commands)
ODP
Linux introduction-commands2338
PPTX
Linux Presentation
PPT
2ab. UNIX files.ppt JSS science and technology university
PPT
Host security
PPT
Host security
PPT
Linux Commands
PPTX
Linux 4 you
PPT
Unix fundamentals
PDF
Linux Getting Started
PDF
Basics of Linux
PPT
linux-lecture4.ppt
PPTX
Unix Linux Commands Presentation 2013
PPT
Linux: Basics OF Linux
An Introduction to Linux
Lesson 2 Understanding Linux File System
Nguyễn Vũ Hưng: Basic Linux Power Tools
8.1.intro unix
Linux Fundamentals and how to use linux.pdf
Linux introduction-commands2338
Linux Introduction (Commands)
Linux introduction-commands2338
Linux Presentation
2ab. UNIX files.ppt JSS science and technology university
Host security
Host security
Linux Commands
Linux 4 you
Unix fundamentals
Linux Getting Started
Basics of Linux
linux-lecture4.ppt
Unix Linux Commands Presentation 2013
Linux: Basics OF Linux

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
System and Network Administration Chapter 2
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
assetexplorer- product-overview - presentation
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
System and Network Administraation Chapter 3
PDF
top salesforce developer skills in 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
System and Network Administration Chapter 2
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Designing Intelligence for the Shop Floor.pdf
Digital Systems & Binary Numbers (comprehensive )
Computer Software and OS of computer science of grade 11.pptx
Nekopoi APK 2025 free lastest update
Navsoft: AI-Powered Business Solutions & Custom Software Development
assetexplorer- product-overview - presentation
Softaken Excel to vCard Converter Software.pdf
Transform Your Business with a Software ERP System
iTop VPN Free 5.6.0.5262 Crack latest version 2025
System and Network Administraation Chapter 3
top salesforce developer skills in 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms I-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
Operating system designcfffgfgggggggvggggggggg
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

Linux Shell Basics

  • 1. GNU/Linux and Bash basics Constantine Nosovsky 1
  • 2. Table of contents History. What Linux and Bash are and what they are not File system (structure, files/dirs, links, file types, locations) Users, groups, permissions Processes (organization, types, states, signals) Bash functionality GNU utilities and tools 2 of 24
  • 3. Bash and Utilities User session, bash configuration Bash CLI vs. scripts Command execution, POSIX arguments Variables (usage, environment) File streams, pipelines, command substitution Text processing Program execution, processes File system management Permissions Network 3 of 24
  • 4. History 4 of 24 1969 – Unix: multi-tasking, multi-user OS in assembly language 1973 – Unix was rewritten to C 1983 – GNU: GNU’s Not Unix. GPL. GCC. GRUB. Bash 1987 – MINIX: educational OS 1991 – Linux kernel. “I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu)” 1993 – Slackware Linux: the first official distribution
  • 5. Linux history today 5 of 24 15M lines of code (excluding comments, blanks) // ohloh.net Around 5k commits per month // ohloh.net Some contributor companies: Red Hat, Intel, IBM, Nokia, Samsung, Oracle, Google, AMD, Microsoft // linuxfoundation.org 75% of all kernel development is done by developers who are being paid for their work // linuxfoundation.org Hundreds of distributions, variety of platforms 469 of 500 TOP computers use Linux // top500.org
  • 6. File system (structure, files/dirs) Root directory “/” is required to be mounted Every directory contains link to itself “.” and parent directory “..” “~” is a user’s home directory Refer to the file by its Absolute path – starting from the root directory: /bin/bash Relative path: ~/.bashrc, ./hello.sh, ../hello.sh File is a sequence of bytes. Directories contain file metadata: length, timestamps, type, owner, permissions, etc. 6 of 24
  • 7. File system (links) Symbolic (soft) link (ln -s) Dir1 File1 metadata File2 metadata … File1 content on disk Hard link (ln) Dir2 File3 metadata File4 metadata … File3 content on disk File1 content on disk Dir1 File1 metadata File2 metadata … Dir2 File1 metadata File3 metadata … 7 of 24
  • 8. File system (file types, pseudo fs) Regular file (text, binary), directory, symbolic link, socket, pipe /dev – Devices related files Block, character devices (storage, sound, input, net, tty) Pseudo files (urandom, null) /proc – Processes related files /proc/<PID>/ - information related to the process with PID cpuinfo, meminfo, version, modules, uptime, etc 8 of 24
  • 9. File system (some locations) 9 of 24 /boot – loader, kernel images /bin – base programs (shell, system-utils), /sbin – for super user /etc – system configuration, service management scripts /home – home directories of regular users /lib, /lib64 – basic system shared libraries /tmp – temporary file system (cleaned after reboot) /media, /mnt – mounted storage devices /lost+found – used for recovery /var – often changed files: logs, cache, locks /usr – user space software related: executables, libs, docs, src, headers, resources
  • 10. Users, groups, permissions 10 of 24 /etc/passwd,group,shadow – user, group, passwords storage File permissions: read, write, execute Dir perm: read(metadata), write(metadata), execute(change dir) Each file has user and group owners Rules applied in order user-group-others (e.g. rwx r-x r--) root (UID=0) has all permissions SUID/GUID – bits to run as user/group owner Sticky bit is used to grand permissions exclusively to the owner Default permissions are set up with umask or mounting fs
  • 11. Processes (organization, types) Organization Each process has PID and parent PID (PPID) Each process belongs to a process group Groups are associated with a terminal session Types 11 of 24 System processes are run from kernel in a special way (e.g. init) Daemon – process detached from the session attached Regular user space processes
  • 12. Processes (states, signals) Process states (ps) R - Running or runnable (on run queue) D - Uninterruptible sleep (usually IO) S - Interruptible sleep (waiting for an event to complete) T - Stopped, either by a job control signal or because it is being traced Z - Zombie process, terminated but not reaped by its parent Signals (kill) KILL, TERM, STOP, CONT, CHLD 12 of 24
  • 13. User session, bash configuration Terminal session is created /bin/login is run for authentication User data are read from /etc/passwd, group (home dir, shell) Specified shell is run for user (parent process of the session) Shell is set up with global settings /etc/bashrc, /etc/profile Shell is set up with user configuration ~/.bashrc, ~/.bash_profile Do your stuff… Exiting from shell will end up terminal session 13 of 24
  • 14. Bash CLI vs. scripts Execute script #! /bin/bash command1 command2 ... $ ./script.sh Run commands $ command1 $ command2 $ … Interpret script command1 command2 ... $ bash ./script.sh 14 of 24
  • 15. POSIX command line arguments 15 of 24 An option is a hyphen followed by a single character, e.g. -o An option may require an argument, e.g. -o argument or -oargument Options that do not require arguments can be grouped, e.g. -lst is equivalent to -t -l -s Options can appear in any order, e.g. -lst is equivalent to -tls Options can appear multiple times. Options precede other nonoption arguments: -lst nonoption The -- argument terminates options grep -RE '^s*<([a-z]+)>.*$' /usr -i --line-number
  • 16. Variables (usage, environment) Usage VAR=value – declaration (script scope) $VAR – access value export VAR – accessible outside the script (session scope) Command line arguments may be accessed like $0, $1,… Environment variables SHELL, USER, HOME, PATH, PWD Use env to list all variables and their values 16 of 24
  • 17. File streams, pipelines, command substitution File streams >, >>, < echo ‘hello, world!’ > file grep hello < file find –name file 2>/dev/null 1>find_result find –name file 2>&1 Pipelines stream output of one command to the input of another ps aux | grep ^gptest | tr -s ' ' | cut -f2 -d ' ' | xargs Command substitution echo Current time is `date` 17 of 24
  • 18. Text processing Use less to view/navigate the large text files Count symbols, words, lines with wc Print file(s) with cat file1 file2 file3 Use cut to filter columns out, e.g. cut –f5 –d ‘:’ Use grep to match text by pattern Use simple text editor nano for interactive file editing Use tr and sed for stream editing, e.g. sed s/regexp/replacement/ file > file_modified Use head/tail for specific line range, e.g. head –n 10000 dev.log | tail –n 100 18 of 24
  • 19. Program execution, process management 19 of 24 Use & to run program in background Use Ctrl+Z to pause the execution in foreground Use bg/fg to continue execution Use Ctrl+C to kill program in foreground Use disown to detach background program from current session. Or run programs in a way nohup <executable> & List processes with ps, top, htop Send signal to process with kill <signal> <pid> Run commands as different user using sudo
  • 20. File system management 20 of 24 Mount volumes to file system like mount /dev/sda1 /mnt/d, mount -o loop file.iso /mnt/cdrom Get volume/file(dir) size with df –h / du -sh dir Create new directories with mkdir Change current directory using cd Print current directory using pwd List directories and access file metadata with ls Use find to locate files by name, type, size, timestamps, etc Copy files with cp , move/rename with mv, remove with rm Create links with ln and soft links with ln -s
  • 21. Permissions management 21 of 24 Set file permissions with chmod, e.g. chmod o+rw dir -R Change file user/group owner with chown/chgrp Set default permission mask with umask Get your identity with id Use ls –l to read file permissions, e.g. ls -l file -rw-r--r-- 1 root root 30608 Nov 26 2010 file Use su, sudo to run as user Know your limits: mounting options (/etc/fstab), file types
  • 22. Network Check server availability with ping, traceroute Get your network configuration with ifconfig, netstat Use download utilities wget, scp You do even have a text browser links 22 of 24
  • 23. Learn stuff 23 of 24 Use man <cmd> and <cmd> --help to read documentation Some commands are just obvious: sort, uniq, date Google command line solutions for common problems “How to capture screen in bash” ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 f.mpg
  • 24. Thanks for you attention Questions? 24 of 24