Linux Fundamentals

Paul Cobbaut

lt-2.0

Mon 26 May 2014 01:00:04 AM CEST

Abstract

This book is meant to be used in an instructor-led training. For self-study, the intent is to read this book next to a working Linux computer so you can immediately do every subject, practicing each command.

This book is aimed at novice Linux system administrators (and might be interesting and useful for home users that want to know a bit more about their Linux system). However, this book is not meant as an introduction to Linux desktop applications like text editors, browsers, mail clients, multimedia or office applications.

More information and free .pdf available at http://linux-training.be .

Feel free to contact the author:

  • Paul Cobbaut: paul.cobbaut@gmail.com, http://www.linkedin.com/in/cobbaut

Contributors to the Linux Training project are:

  • Serge van Ginderachter: serge@ginsys.eu, build scripts and infrastructure setup

  • Ywein Van den Brande: ywein@crealaw.eu, license and legal sections

  • Hendrik De Vloed: hendrik.devloed@ugent.be, buildheader.pl script

We'd also like to thank our reviewers:

  • Wouter Verhelst: wo@uter.be, http://grep.be

  • Geert Goossens: mail.goossens.geert@gmail.com, http://www.linkedin.com/in/geertgoossens

  • Elie De Brauwer: elie@de-brauwer.be, http://www.de-brauwer.be

  • Christophe Vandeplas: christophe@vandeplas.com, http://christophe.vandeplas.com

  • Bert Desmet: bert@devnox.be, http://blog.bdesmet.be

  • Rich Yonts: richyonts@gmail.com,

Copyright 2007-2014 Netsec BVBA, Paul Cobbaut

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled 'GNU Free Documentation License'.


Table of Contents

I. introduction to Linux
1. Linux history
Linux history
2. distributions
Red Hat
Ubuntu
Debian
Other
Which to choose ?
3. licensing
about software licenses
public domain software and freeware
Free Software or Open Source Software
GNU General Public License
using GPLv3 software
BSD license
other licenses
combination of software licenses
4. getting Linux at home
download a Linux CD image
download Virtualbox
create a virtual machine
attach the CD image
install Linux
II. first steps on the command line
5. man pages
man $command
man $configfile
man $daemon
man -k (apropos)
whatis
whereis
man sections
man $section $file
man man
mandb
6. working with directories
pwd
cd
cd ~
cd ..
cd -
absolute and relative paths
path completion
ls
ls -a
ls -l
ls -lh
mkdir
mkdir -p
rmdir
rmdir -p
practice: working with directories
solution: working with directories
7. working with files
all files are case sensitive
everything is a file
file
touch
touch -t
rm
rm -i
rm -rf
cp
cp -r
cp multiple files to directory
cp -i
cp -p
mv
rename
practice: working with files
solution: working with files
8. working with file contents
head
tail
cat
concatenate
create files
custom end marker
copy files
tac
more and less
strings
practice: file contents
solution: file contents
9. the Linux file tree
filesystem hierarchy standard
man hier
the root directory /
binary directories
/bin
other /bin directories
/sbin
/lib
/opt
configuration directories
/boot
/etc
data directories
/home
/root
/srv
/media
/mnt
/tmp
in memory directories
/dev
/proc conversation with the kernel
/sys Linux 2.6 hot plugging
/usr Unix System Resources
/usr/bin
/usr/include
/usr/lib
/usr/local
/usr/share
/usr/src
/var variable data
/var/log
/var/log/messages
/var/cache
/var/spool
/var/lib
/var/...
practice: file system tree
solution: file system tree
III. shell expansion
10. commands and arguments
arguments
white space removal
single quotes
double quotes
echo and quotes
commands
external or builtin commands ?
type
running external commands
which
aliases
create an alias
abbreviate commands
default options
viewing aliases
unalias
displaying shell expansion
practice: commands and arguments
solution: commands and arguments
11. control operators
; semicolon
& ampersand
$? dollar question mark
&& double ampersand
|| double vertical bar
combining && and ||
# pound sign
\ escaping special characters
end of line backslash
practice: control operators
solution: control operators
12. shell variables
$ dollar sign
case sensitive
creating variables
quotes
set
unset
$PS1
$PATH
env
export
delineate variables
unbound variables
practice: shell variables
solution: shell variables
13. shell embedding and options
shell embedding
backticks
backticks or single quotes
shell options
practice: shell embedding
solution: shell embedding
14. shell history
repeating the last command
repeating other commands
history
!n
Ctrl-r
$HISTSIZE
$HISTFILE
$HISTFILESIZE
(optional)regular expressions
(optional)repeating commands in ksh
practice: shell history
solution: shell history
15. file globbing
* asterisk
? question mark
[] square brackets
a-z and 0-9 ranges
$LANG and square brackets
preventing file globbing
practice: shell globbing
solution: shell globbing
IV. pipes and commands
16. I/O redirection
stdin, stdout, and stderr
output redirection
> stdout
output file is erased
noclobber
overruling noclobber
>> append
error redirection
2> stderr
2>&1
output redirection and pipes
joining stdout and stderr
input redirection
< stdin
<< here document
<<< here string
confusing redirection
quick file clear
practice: input/output redirection
solution: input/output redirection
17. filters
cat
tee
grep
cut
tr
wc
sort
uniq
comm
od
sed
pipe examples
who | wc
who | cut | sort
grep | cut
practice: filters
solution: filters
18. basic Unix tools
find
locate
date
cal
sleep
time
gzip - gunzip
zcat - zmore
bzip2 - bunzip2
bzcat - bzmore
practice: basic Unix tools
solution: basic Unix tools
19. regular expressions
regex versions
grep
print lines matching a pattern
concatenating characters
one or the other
one or more
match the end of a string
match the start of a string
separating words
grep features
preventing shell expansion of a regex
rename
the rename command
perl
well known syntax
a global replace
case insensitive replace
renaming extensions
sed
stream editor
interactive editor
simple back referencing
back referencing
a dot for any character
multiple back referencing
white space
optional occurrence
exactly n times
between n and m times
bash history
V. vi
20. Introduction to vi
command mode and insert mode
start typing (a A i I o O)
replace and delete a character (r x X)
undo and repeat (u .)
cut, copy and paste a line (dd yy p P)
cut, copy and paste lines (3dd 2yy)
start and end of a line (0 or ^ and $)
join two lines (J) and more
words (w b)
save (or not) and exit (:w :q :q! )
Searching (/ ?)
replace all ( :1,$ s/foo/bar/g )
reading files (:r :r !cmd)
text buffers
multiple files
abbreviations
key mappings
setting options
practice: vi(m)
solution: vi(m)
VI. scripting
21. scripting introduction
prerequisites
hello world
she-bang
comment
variables
sourcing a script
troubleshooting a script
prevent setuid root spoofing
practice: introduction to scripting
solution: introduction to scripting
22. scripting loops
test [ ]
if then else
if then elif
for loop
while loop
until loop
practice: scripting tests and loops
solution: scripting tests and loops
23. scripting parameters
script parameters
shift through parameters
runtime input
sourcing a config file
get script options with getopts
get shell options with shopt
practice: parameters and options
solution: parameters and options
24. more scripting
eval
(( ))
let
case
shell functions
practice : more scripting
solution : more scripting
VII. local user management
25. users
identify yourself
whoami
who
who am i
w
id
users
user management
/etc/passwd
root
useradd
/etc/default/useradd
userdel
usermod
passwords
passwd
/etc/shadow
password encryption
password defaults
disabling a password
editing local files
home directories
creating home directories
/etc/skel/
deleting home directories
user shell
login shell
chsh
switch users with su
su to another user
su to root
su as root
su - $username
su -
run a program as another user
about sudo
setuid on sudo
visudo
sudo su
practice: users
solution: users
shell environment
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
~/.bash_logout
Debian overview
RHEL5 overview
26. groups
about groups
groupadd
/etc/group
usermod
groupmod
groupdel
groups
gpasswd
vigr
practice: groups
solution: groups
VIII. file security
27. standard file permissions
file ownership
user owner and group owner
listing user accounts
chgrp
chown
list of special files
permissions
rwx
three sets of rwx
permission examples
setting permissions (chmod)
setting octal permissions
umask
mkdir -m
practice: standard file permissions
solution: standard file permissions
28. advanced file permissions
sticky bit on directory
setgid bit on directory
setgid and setuid on regular files
practice: sticky, setuid and setgid bits
solution: sticky, setuid and setgid bits
29. access control lists
acl in /etc/fstab
getfacl
setfacl
remove an acl entry
remove the complete acl
the acl mask
eiciel
30. file links
inodes
inode contents
inode table
inode number
inode and file contents
about directories
a directory is a table
. and ..
hard links
creating hard links
finding hard links
symbolic links
removing links
practice : links
solution : links
IX. Appendices
A. keyboard settings
about keyboard layout
X Keyboard Layout
shell keyboard layout
B. hardware
buses
about buses
/proc/bus
/usr/sbin/lsusb
/var/lib/usbutils/usb.ids
/usr/sbin/lspci
interrupts
about interrupts
/proc/interrupts
dmesg
io ports
about io ports
/proc/ioports
dma
about dma
/proc/dma
C. License
Index

List of Tables

20.1. getting to command mode
20.2. switch to insert mode
20.3. replace and delete
20.4. undo and repeat
20.5. cut, copy and paste a line
20.6. cut, copy and paste lines
20.7. start and end of line
20.8. join two lines
20.9. words
20.10. save and exit vi
20.11. searching
20.12. replace
20.13. read files and input
20.14. text buffers
20.15. multiple files
20.16. abbreviations
25.1. Debian User Environment
25.2. Red Hat User Environment
27.1. Unix special files
27.2. standard Unix file permissions
27.3. Unix file permissions position
27.4. Octal permissions