Introduction To Linux
By Owen Stampflee <owen@stampflee.com>
http://www.stampflee.com/vlug-intro2linux.pdf
File System Hierarchy
/bin - Core Applications
/boot - Contains Kernels and Boot loader Components
/dev - Device files
/etc - Global System Configuration Files
/home - User data files
/lib - Core Libraries
/mnt - Directories where secondary file systems and media are mounted.
/opt - Commercial software and sometimes KDE and Gnome.
/proc - Special kernel file system
/root - The super user's data files. Should remain nearly empty.
/sbin - Core Applications for the Super User.
/tmp - Temporary Files
File System Hierarchy Cont.
/usr
/var - Various files data files.
File Utilities
ls options path - Lists Files.
cd options path - Change Directory
cp options source destination - Copy source file to destination file.
mv options source destination - Move (or rename) source file to destination file.
File Utilities Cont.
chmod options mode path - Changes the permissions the path to the specified mode.
chown options user.group path - Changes the owner and group of a path to the specified user.group
File Utilities Cont.
du options path - summarizes disk usage
df options - Calculates disk usage on mounted partitions.
find path options - Finds files in path that satisfy the options.
Text Utilities
cat file - Outputs the specified file to Standard Output (stdout).
head -n file - Outputs the first the n lines of the specified file to stdout.
tail -n file - Outputs the last the n lines of the specified file to stdout.
grep options pattern file - Outputs lines from the specified file that match the pattern.
Text Utilities Cont.
sed s:old:new:g file - Replaces all occurrences of "old" with "new"
Pipes
A pipe "|" will take the output of the first command and pass it to the second on standard input.
Redirectors
The ">" redirector, will write the output of the command before it and write it to the file specified after it.
The "<" redirector, will take the contents of the file after it and write as standard input to the application run before it.
Users & Groups
useradd options user - Creates a new user.
usermod options user - Modifies user account
userdel options user - Deletes user account.
passwd user - Changes the password of the specified user.
Users & Groups Cont.
groupadd group - Creates a group.
groupmod options group - Modifies a group.
groupdel group - Deletes the specified group.
sudo command - Runs command as root.
"%wheel ALL=(ALL) ALL". This can be achieved but uncommenting
that line in the standard /etc/sudoers.
Networking
ifconfig interface - Shows information about the specified interface, if no interface is specified, shows information about all active interface.
ifconfig interface ip_addr up - Configures the specified interface with ip_addr.
ifconfig interface down - Takes down interface. Akin to unplugging the cable.
route - Show routing table.
route add default gw ip_addr - Makes the specified ip_addr one of the default gateways.
route del default gw ip_addr - Removes the specified default gateway.
ping host - Test network connection to see if you can "talk to" the specified host.
Networking Cont.
/etc/resolv.conf is used by Glibc to determine how to look up Internet names. It contains the domain name to lookup as well as the name servers.
Sample /etc/resolv.conf:
domain lan.stampflee.com
nameserver 192.168.0.254
search lan.stampflee.com
/etc/hosts defines names of hosts and their IP addresses. Instead of looking up the name of the specified host with a name server, the IP address defined in /etc/hosts is used.
Example /etc/hosts:
127.0.0.1 localhost.localdomain localhost
192.168.0.1 tsunami.lan.stampflee.com tsunami
192.168.0.2 whitefusion.lan.stampflee.com whitefusion
192.168.0.254 fred.lan.stampflee.com fred
Networking
dhcpcd interface - Try to fetch a DHCP lease.
dhcpcd -k interface - Kill dhcpcd and release your DHCP lease.
dhcpcd is not the only DHCP client that exists, if your system doesn't have it, pump and dhclient are popular alternatives.
netstat options - Show various network statistics.
Backup Tools
tar jxvf mytarball.tar.bz2 - Extract files from mytarball.tar.bz2
tar zxvf mytarball.tar.gz - Extract files from mytarball.tar.gz
Gzip compression is used for tarballs with the extensions .tar.gz, .tgz, and .tar.Z. Bzip2 compression which is slightly better but requires more CPU is used in tarballs with the extensions .tar.bz2 and .tbz2.
tar jcvf mytarball.tar.bz2 my_files - Creates a tarball mytarball.tar.bz2 with the specified files.
Backup Tools Cont.
gzip file - Will compress file using gzip compression and will rename "file" to "file.gz"
gunzip file.gz - Will uncompress file compressed using gzip compression and will rename "file.gz" to "file"
bzip2 file - Will compress file using bzip2 compression and will rename "file" to "file.bz2"
bunzip2 file.bz2 - Will uncompress file compressed using bzip2 compression and will rename "file.bz2" to "file"
rsync options user@host:remote_directory local_directory - Will sync the remote_directory on the remote host with the local_directory.
Package Management
Using RPM
To install or upgrade a package:
rpm -Uvh package-1.0.i386.rpm
To remove a package:
rpm -e package-1.0
To determine what version of a package you have installed:
rpm -qa | grep package_name
To determine what package a file "belongs" to:
rpm -qf file
Package Management Cont.
Using Apt
To update your package lists:
apt-get update
To install all updated packages:
apt-get dist-upgrade
To install a package:
apt-get install package
To upgrade a package:
apt-get upgrade package
To then remove that package (and all packages that depend on it):
apt-get remove package
To search for a package:
apt-cache search search_string
Compiling Software From Source
Compiling an Application:
Compiling a single source file:
gcc -o myexecutable myfile.c - Compiles myfile.c naming the executable, myexecutable. Use g++ for C++ source files.
System Resource Management
uptime - Shows the computer uptime, but more importantly shows your load average.
free - Shows memory usage.
ps options - Process List
kill -signal pids - Sends signal to specified PIDs
killall -signal processes - Sends specified signal to specified processes.
System Resource Management
top - Show vital system information including uptime, load average, CPU & memory usage as well as a sorted process list.
xkill - Run and click on the X application that doesn't want to die. Right click if you change your mind about wanting to terminate an application.
nice priority command - Runs a program with modified scheduling priority.
renice priority options - Alters scheduling priority
Miscellaneous
Environment Variables:
printenv - Prints all environment variables.
echo $ENVAR - Prints specified the specified environment variable.
export ENVAR="foo" - sets $ENVAR to "foo".
Getting Help:
command --help; command -h - Will summarize basic options for the command. This is application dependent and doesn't always work. More detailed help can be found in the man/info pages.
man arguments - Manual Tool
info arguments - Manual Tool
Page 21
Introduction To Linux - By Owen Stampflee <owen@stampflee.com>
http://www.stampflee.com/vlug-intro2linux.pdf