140 likes | 307 Views
Introduction to Linux. Presented by David Pithouse Termisoc Secretary. Introduction to Linux. File System Hierarchy File Utilities Text Utilities Users & Groups Networking Backup Tools Package Management Compiling Software From Source System Resource Management Miscellaneous.
E N D
Introduction to Linux Presented by David Pithouse Termisoc Secretary
Introduction to Linux • File System Hierarchy • File Utilities • Text Utilities • Users & Groups • Networking • Backup Tools • Package Management • Compiling Software From Source • System Resource Management • Miscellaneous
/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 /usr bin - User Applications include - Include files lib - User Libraries local - Locally Compiled Applications, Libraries, Shared Files, Etc. sbin - Super User Applications share - Shared files including pixmaps, menus, documentation, and man pages. src - Source code for various applications. X11R6 - Applications, Libraries, Shared files packaged in XFree86. /var - Various files data files. lock - Files that indicate if background processes (daemons) are running (or weren't stopped cleanly) log - (IMPORTANT) Log files, if something goes wrong, this is where you look! run - Files that contain process identifiers used to stop daemons. spool - Spool files for mail, print, and other servers File System Hierarchy
File Utilities • ls options path - Lists Files. • -l : Long view • -h : Human Readable Sizes (only with -l) • -a : List All files • cd options path - Change Directory • Use just cd with no arguments to change to your home directory. • cp options source destination - Copy source file to destination file. • -a : Archive, copies recursively preserving permissions. • You can have multiple source files if the destination is a directory. • mv options source destination - Move (or rename) source file to destination file. • -a is "on" by default. • As with cp you can have multiple source files if the destination is a directory. • chmod optionsmodepath - Changes the permissions the path to the specified mode. • -R : Changes Permissions Recursively • Mode is in the form of u=rwx,g=rwx,a=rwx. • "u" is the owner of the file, "g" is the group of the file, and "a" is for anyone. • "r" is for read permissions, "w" is for write, and "x" determines if the file is executable. • chown options user.grouppath - Changes the owner and group of a path to the specified user.group • ".group" does not need to be specified if the you do not want change the group. • If you don't want to change the user, just the group use chgrp instead. • du optionspath - summarizes disk usage • -h : Human readable sizes • -s : Summary • df options - Calculates disk usage on mounted partitions. • -h : Human readable sizes. • find path options- Finds files in path that satisfy the options. • -name : Name of the file. Use asterisks for a wild card. • -type : Type of the file, "f" for normal files, "d" for directories, "l" for links.
File Utilities • ls options path - Lists Files. • -l : Long view • -h : Human Readable Sizes (only with -l) • -a : List All files • cd options path - Change Directory • Use just cd with no arguments to change to your home directory. • cp options source destination - Copy source file to destination file. • -a : Archive, copies recursively preserving permissions. • You can have multiple source files if the destination is a directory. • mv options source destination - Move (or rename) source file to destination file. • -a is "on" by default. • As with cp you can have multiple source files if the destination is a directory. • chmod optionsmodepath - Changes the permissions the path to the specified mode. • -R : Changes Permissions Recursively • Mode is in the form of u=rwx,g=rwx,a=rwx. • "u" is the owner of the file, "g" is the group of the file, and "a" is for anyone. • "r" is for read permissions, "w" is for write, and "x" determines if the file is executable. • chown options user.grouppath - Changes the owner and group of a path to the specified user.group • ".group" does not need to be specified if the you do not want change the group. • If you don't want to change the user, just the group use chgrp instead. • du optionspath - summarizes disk usage • -h : Human readable sizes • -s : Summary • df options - Calculates disk usage on mounted partitions. • -h : Human readable sizes. • find path options- Finds files in path that satisfy the options. • -name : Name of the file. Use asterisks for a wild card. • -type : Type of the file, "f" for normal files, "d" for directories, "l" for links.
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. • If -n is omitted, outputs the first 10 lines. • If no file is specified, Standard Input (stdin) is used instead. • tail -n file - Outputs the last the n lines of the specified file to stdout. • If -n is omitted, outputs the last 10 lines. • If no file is specified, Standard Input (stdin) is used instead. • grep options pattern file - Outputs lines from the specified file that match the pattern. • -v : Outputs the lines that don't match the pattern. • If no file is specified, Standard Input (stdin) is used instead. • sed s:old:new:g file - Replaces all occurrences of "old" with "new" • You can specify multiple expressions by using -e • If no file is specified, Standard Input (stdin) is used instead. • 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 and Groups • useradd options user - Creates a new user. • -g : Comma separated groups the user is a member of. • -M : Create the user's home directory if doesn't exist. • -s : The user's shell. (Use /bin/false for users you wish to restrict from having shell access). • usermod options user - Modifies user account • Same options as useradd. • userdel options user - Deletes user account. • -r : Remove user's home directory. • passwd user - Changes the password of the specified user. • If no user is specified, will change the password of the current user. • groupaddgroup - Creates a group. • groupmod options group - Modifies a group. • -n : Rename group • groupdel group - Deletes the specified group. • sudo command - Runs command as root. • /etc/sudoers should have a line which contains the following: "%wheel ALL=(ALL) ALL". This can be achieved but uncommenting that line in the standard /etc/sudoers. • Then add users you wish to have access to sudo to the "wheel" group.
Networking • ifconfig • 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. • -n : Don't look up names of IP addresses in 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. • /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. • /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. • 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. • -l : List ports where a process is listening. • -t : Only show information about TCP connections and ports. • -u : Only show information about ICMP connections and ports.
Backup Tools • tar • tar jxvf mytarball.tar.bz2 - Extract files from mytarball.tar.bz2 • tar zxvf mytarball.tar.gz - Extract files from mytarball.tar.gz • -z : Use gzip compression • -j : Use bzip2 compression • -x : Extract • -v : Verbose • -f : Use file • 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. • -a : Archive, Recursive. • -v : Verbose • -z : Compress • -e : Remote shell (should use ssh)
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 filePackage 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: • Download the source. • Untar the source. • cd into the source directory. • Read the INSTALL, README, and any other files that look they contain instructions. (We'll assume this is autoconf based build process) • Run ./configure, ./configure --help will typically describe the many many options you can set. • If there are no errors run make • If there are still no errors, run sudo make install (assuming you've setup sudo :) • Run you application! If it doesn't seem to be available, check your $PATH. • Compiling a single source file: • gcc -o myexecutable myfile.c - Compiles myfile.c naming the executable, myexecutable. Use g++ for C++ source files.
System Resources • uptime - Shows the computer uptime, but more importantly shows your load average. • free - Shows memory usage. • -h : Human Readable. • ps options- Process List • RTFM, it's big! Most common options are "-ef" and "aux" • kill -signal pids- Sends signal to specified PIDs • SIGHUP used if no signal specified. • Popular signals: SIGHUP, SIGKILL, SIGUSR1, SIGUSR2 • killall -signal processes - Sends specified signal to specified processes. • SIGHUP used if no signal specified. • top - Show vital system information including uptime, load average, CPU & memory usage as well as a sorted process list. • "M" : Sort by Resident Memory Usage • "P" : Sort by CPU Usage • "k" : Kill PID. • 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. • -20 is the highest priority (real time) and 19 is lowest priority. • Only root can set a priority higher than 0. • renice priority options - Alters scheduling priority • -p pid ... : Alter priority for specified PIDs. • -u user : Alter all processes owned by the specified users.
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 • A single argument will look up the given manpage. • -k string : Find all entries that contain string. • info arguments - Manual Tool • A single argument will look up the given info page. • --apropos=subject : Find all entries that contain string.
References • Websites of Interest • www.dclug.org.uk • www.linux.org.uk • www.debian.org • Getting people help • www.expertsexchange.com • www.fluxbbs.org • Irc://irc.freenode.net • termisoc@termisoc.org