AOS Lab 1: Hello, Linux!
-
Upload
zubair-nabi -
Category
Technology
-
view
373 -
download
1
description
Transcript of AOS Lab 1: Hello, Linux!
Unix
• Multi-task, multi-user OS out of Bell Labs in 19691
• Initially in Assembly but later in C (1973)2
• Code recycling!
• Ken Thompson, Dennis Ritchie, Brian Kernighan, DouglasMcIlroy, Michael Lesk and Joe Ossanna
• Branched into BSD (FreeBSD, NetBSD, etc.)
1http://www.youtube.com/watch?v=tc4ROCJYbm02Dennis M. Ritchie and Ken Thompson. 1974. The UNIX time-sharing system.
Commun. ACM 17, 7 (July 1974), 365-375. DOI=10.1145/361011.361061
Linux
• Linux (circa 1991) is a Unix-clone under FOSS
• Comes in many flavours/distributions (distros): Linux kernel3 +GUI (optional) + application/software suite
• bash (shell) + GCC + GDB + coreutils• 600+ distros• Popular ones: Ubuntu, Fedora, Debian, Gentoo, SUSE, etc.
• Now being used atop desktops, servers, and mobile/embeddedsystems
Linus Torvalds: comp.os.minix mailing list (1991-08-25)
I’m doing a (free) operating system (just a hobby, won’t be big andprofessional like gnu) for 386(486) AT clones.
3http://www.kernel.org/
Ubuntu
• Built on top of Debian and developed/distributed by CanonicalLtd.
• Most popular desktop/laptop distribution
• Applications: LibreOffice, Firefox (web browser), Thunderbird(email/chat/news), Empathy (IM/VoIP), etc.
• Variants: Ubuntu Deskop, Ubuntu Server, Ubuntu for Phones, etc.
Linux guide(s)
• Introduction to Linux: A Hands on Guide; Achtelt Garrels;CreateSpace Independent Publishing PlatformAvailable online:http://www.tldp.org/LDP/intro-linux/html/
Common commands
Command Descriptionls List the contents of a directorycd Change directory (jump across the filesystem tree)file Display file typecat Send file contents to standard outputpwd Display current working directoryman Display manual pagelogout/exit Close the current session
Files
Everything is a file
On a UNIX system, everything is a file; if something is not a file, it is aprocess.
Type DescriptionRegular (-) Ordinary filesDirectory (d) To list other filesSpecial (c) Used for input/outputLinks (l) Pointers to other filesDomain sockets (s) IPC through TCP/IP-like socketsNamed pipes (p) IPC enablersBlock device files (b) To represent block devices
Partitioning
• Divides the disk device into multiple logical storage units
• Data partitions contain regular user data
• Swap partitions house the swap space
• Attached to the file system at mount points
• df displays free disk space in active partitions
Filesystem layout
Type Description/bin Programs shared by users, administrators,
and the system itself/boot Start-up files/dev Hardware devices/etc Configuration files/home Home directories of users/lib Library files for programs and the system/lost+found Files saved in case of failure/media Mount point for removable media/mnt Mount point for external filesystems/opt Third-party software/proc Information about system resources (user-
space window into kernel data structures)
Filesystem layout (2)
/sbin Programs shared by administrators and thesystem
/tmp Temporary space/usr User processes and libraries/var Files which change size regularly, e.g. log
files, etc.
Paths, environment variables, and home directories
• Two types of paths:1 Relative: Relative to the current working directory
• ∼: Relative to home directory
2 Absolute: Starting from the root directory
• Environment variables: Contain dynamic values that change thebehaviour of running programs, e.g. PATH, HOME, etc.
• Each user has a home directory
Manipulating files/directories
• Create directory: mkdir
• Move file/directory: mv
• Copy file/directory: cp
• Remove file/directory: rm
• Find file/directory: find <path> -name <filename>
Manipulating files and their contents
• Filter results: grep• Invert: -v
• Display values from the top: head
• Display values from the bottom: tail
• Display unique values: uniq• Change file permissions: chmod
• Permissions: -, r, w, x (bit masks)• Permission categories: owner, group, everyone else
• Count number of lines (-l), words (-w), and bytes(-c): wc
Pipes and input/output redirection
• Pipe (|): Redirect standard output to standard input• Input/output redirection (<>): Redirect standard input or output
to a file• Appending redirection: << or >>• Replacing a string in place:sed -i s/<original_string>/<new_string>/<file>
• Replacing a string and copying into a new file:sed s/<original_string>/<new_string>/<input_file> > <output_file>
Shell scripts
• Shell commands can be put into a file and executed as a script
• A file can be made executable through chmod
Today’s Task
• Write a bash script that:1 Creates two folders in your home directory: 1) temp, and 2)results,
2 Copies both dictionaries into temp and renames them toamerican-english-dictionary andbritish-english-dictionary,
3 Counts the total number of lines in both dictionaries and storesthem in count-british-english-dictionary andcount-american-english-dictionary in theresults folder,
4 Stores unique American English words (not present in the BritishEnglish dictionary) in unique-american-english andunique British English words (not present in the American Englishdictionary) in unique-british-english in the resultsfolder,
5 Stores common words (present in both dictionaries) incommon-english in the results folder.