AOS Lab 1: Hello, Linux!

16
Lab 1: Hello, Linux! Advanced Operating Systems Zubair Nabi [email protected] January 23, 2013

description

 

Transcript of AOS Lab 1: Hello, Linux!

Page 1: AOS Lab 1: Hello, Linux!

Lab 1: Hello, Linux!Advanced Operating Systems

Zubair Nabi

[email protected]

January 23, 2013

Page 2: 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

Page 3: AOS Lab 1: Hello, Linux!

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/

Page 4: AOS Lab 1: Hello, Linux!

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.

Page 5: AOS Lab 1: Hello, Linux!

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/

Page 6: AOS Lab 1: Hello, Linux!

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

Page 7: AOS Lab 1: Hello, Linux!

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

Page 8: AOS Lab 1: Hello, Linux!

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

Page 9: AOS Lab 1: Hello, Linux!

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)

Page 10: AOS Lab 1: Hello, Linux!

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.

Page 11: AOS Lab 1: Hello, Linux!

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

Page 12: AOS Lab 1: Hello, Linux!

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>

Page 13: AOS Lab 1: Hello, Linux!

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

Page 14: AOS Lab 1: Hello, Linux!

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>

Page 15: AOS Lab 1: Hello, Linux!

Shell scripts

• Shell commands can be put into a file and executed as a script

• A file can be made executable through chmod

Page 16: AOS Lab 1: Hello, Linux!

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.