Linux Fundamentals

Paul Cobbaut

lt-2.0

Mon 07 May 2012 01:00:18 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-2012 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
echo
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. variables
about variables
$ dollar sign
case sensitive
$PS1
$PATH
creating variables
quotes
set
unset
env
export
delineate variables
unbound variables
shell options
shell embedding
backticks
backticks or single quotes
practice: shell variables
solution: shell variables
13. 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
14. 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
15. redirection and pipes
stdin, stdout, and stderr
output redirection
> stdout
output file is erased
noclobber
overruling noclobber
>> append
error redirection
2> stderr
2>&1
input redirection
< stdin
<< here document
<<< here string
confusing redirection
quick file clear
swapping stdout and stderr
pipes
| vertical bar
multiple pipes
practice: redirection and pipes
solution: redirection and pipes
16. 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
17. 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
V. vi
18. 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
19. 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
20. 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
21. 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
22. more scripting
eval
(( ))
let
case
shell functions
practice : more scripting
solution : more scripting
VII. local user management
23. 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
24. groups
about groups
groupadd
/etc/group
usermod
groupmod
groupdel
groups
gpasswd
vigr
practice: groups
solution: groups
VIII. file security
25. standard file permissions
file ownership
user owner and group owner
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
26. 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
27. access control lists
acl in /etc/fstab
getfacl
setfacl
remove an acl entry
remove the complete acl
the acl mask
eiciel
28. 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. certifications
Certification
LPI: Linux Professional Institute
Red Hat Certified Engineer
MySQL
Novell CLP/CLE
Sun Solaris
Other certifications
B. keyboard settings
about keyboard layout
X Keyboard Layout
shell keyboard layout
C. 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
Index

List of Tables

18.1. getting to command mode
18.2. switch to insert mode
18.3. replace and delete
18.4. undo and repeat
18.5. cut, copy and paste a line
18.6. cut, copy and paste lines
18.7. start and end of line
18.8. join two lines
18.9. words
18.10. save and exit vi
18.11. searching
18.12. replace
18.13. read files and input
18.14. text buffers
18.15. multiple files
18.16. abbreviations
23.1. Debian User Environment
23.2. Red Hat User Environment
25.1. Unix special files
25.2. standard Unix file permissions
25.3. Unix file permissions position
25.4. Octal permissions