+ All Categories
Home > Business > Tutorial 2

Tutorial 2

Date post: 15-May-2015
Category:
Upload: tech2click
View: 2,284 times
Download: 0 times
Share this document with a friend
Popular Tags:
29
Linux Overview
Transcript
Page 1: Tutorial 2

Linux Overview

Page 2: Tutorial 2

Outline

• Linux file system (FS)– Useful commands for manipulating the FS

• Linux vs. Windows• What did you learn from Assignment #1

– sudo– Apt-get– Pipes– Command prompt

Page 3: Tutorial 2

Linux Filesystem

Everything is a File

Page 4: Tutorial 2

Linux Filesystem

• Filesystem is a method for storing and organizing computer files and the data they contain to make it easy to find and access.

• Different operating systems normally use different file systems.

Page 5: Tutorial 2

Linux Filesystem

• The filesystem in Linux stores – the kernel– the executable commands supported by the OS– configuration information– user data– and special files that are used to give controlled

access to system hardware and OS functions.

Page 6: Tutorial 2

Linux Filesystem

• Items stored in the filesystem are of four types:– Ordinary files contain text, data, or program

information. Files can not contain other files or directories.

– Directories containers that hold files, and other directories.

– Devices are used in the same way as ordinary files providing applications with easy access to the hardware devices.

– Links which is a pointer to another file

Page 7: Tutorial 2

Linux Filesystem

• The system is laid out as a hierarchical tree structure. The top-level directory is the 'root' designated by a slash '/'.

• Each directory can have many child directories, but only one parent directory.

Page 8: Tutorial 2

Linux Filesystem

Page 9: Tutorial 2

Linux Filesystem

• The path to a certain location can be specified as:– Absolute path from root

e.g./root/home/will

– Relative pathe.g.

Accessing play from user “zeb”../will/play

Page 10: Tutorial 2

Root Common Subdirectories

Page 11: Tutorial 2

Common SubdirectoriesDirectory Stands for Content

/ root Top-level directory in the hierarchical tree

/bin Binaries Contains binaries used by both the system administrator and non-privileged user e.g. command ‘ls’ is stored here

/dev Devices Contains hardware devices directories. It is a virtual directory

/etc Et cetra Contains configuration files for running applications

/home Contains user subdirectories

/lib Libraries Contains shared libraries e.g. C, Perl, Python general libraries

/mnt Mount

/proc Processes Contains information about the system e.g. process that are running. It is a virtual directory

/root Default home directory for the system administrator. Isolated to increase security

Page 12: Tutorial 2

Common Subdirectories

Directory Stands for Content

/sbin Secure Binaries

Contains secured binaries that are only accessed by privileged users e.g. fdisk, partitioning tool is kept here

/tmp Temporaries Contains temporary files

/usr Unix System Resources

Contains subdirectories such as /usr/doc which contains system documentations, /usr/local the local hosts directory

/var Variables Contains log and spool files

/boot Contains Linux kernel

Page 13: Tutorial 2

Useful Commands

Page 14: Tutorial 2

CD

• $ cd path– changes your current working directory to path (which can

be an absolute or a relative path). One of the most common relative paths to use is '..' (i.e. the parent directory of the current directory).

• $ cd – resets your current working directory to your home

directory (useful if you get lost). • $ cd -

– If you change into a directory and you subsequently want to return to your original directory, use

Page 15: Tutorial 2

pwd

• pwd - Displays the current directory ("working directory").

• pwd displays the full absolute path to your current location in the filesystem.

• $ pwd /usr/bin • implies that /usr/bin is the current working

directory.

Page 16: Tutorial 2

Filesystem Comparison

Linux vs. Window

Page 17: Tutorial 2

Filesystem ComparisonLinux Filesystem Windows Filesystem

Hierarchal Structure

Only a single hierarchal directory structure. Everything starts from the root directory and then expanded to subdirectories. It also has various partitions, but under the root directory. They are ‘mounted’ under specific directories(Unified scheme)

Various partitions, with directories under those partitions(Volume based file hierarchy)

Detection Partition will not be detected unless it has been mounted.

All partitioned detected and booted, then each assigned a drive letter.

Crossover Can read/write FAT16 , FAT32 Can not unless with third party support

Hidden Files Implement with a name that starts with a dot.

Tracks it as a file attribute

Types ext2, ext3 FAT12, FAT16, FAT32, and or NTFS

Page 18: Tutorial 2

Filesystem ComparisonLinux Filesystem Windows Filesystem

Case Sensitivity

Case sensitive. File.txt is not the same as file.txt

Not case sensitive

Confirmation Messages

Non existent e.g. when deleting, user will not be promoted whether to continue with the operation or not

User will be prompted with each action

Search Path Does not look into the current directories. It looks at the PATH environment variable. To run program in current directory:./ program

Checks current directory first then looks at the PATH environment variable

Slashes Uses a forward slash “/” Uses a backward slash “\”

Switch Indication

Switches are preceded by “-” Switches are preceded by “\”

Page 19: Tutorial 2

Default Directory

• The default working directory is your user home directory.– /home/ubuntu

• /home is equivalent to My documentsUser name

Page 20: Tutorial 2

Running Privileged Commands

• How to run privileged commands as a normal user?– Use sudo command

• Sudo is a program which can be used by normal users to execute as super users or any other users.

Page 21: Tutorial 2

Running Privileged Commands Example

Running the following statement sudo –l

Then entering password will produce a listing of command that the user may execute as well as how and as who they maybe executed.

Page 22: Tutorial 2

Beware of the dark side of root

• root user privileges are only needed for very specific tasks with security risks: mounting, creating device files, loading drivers, starting networking,changing file ownership, package upgrades...

• Even if you have the root password, your regular account should be sufficient for 99.9 % of your tasks(unless you are a system administrator).

• In assignments, it is acceptable to use root.In real life, you may not even have access to this account, or put your systems and data at risk if you do.

Page 23: Tutorial 2

Using the root account

In case you really want to use root...

• If you have the root password:su - (switch user)

• In modern distributions, the sudo command gives you access to some root privileges with your own user password.Example: sudo mount /dev/hda4 /home

Page 24: Tutorial 2

Live process activity• top - Displays most important processes, sorted by cpu

percentagetop - 15:44:33 up 1:11, 5 users, load average: 0.98, 0.61, 0.59

Tasks: 81 total, 5 running, 76 sleeping, 0 stopped, 0 zombieCpu(s): 92.7% us, 5.3% sy, 0.0% ni, 0.0% id, 1.7% wa, 0.3% hi, 0.0% siMem: 515344k total, 512384k used, 2960k free, 20464k buffersSwap: 1044184k total, 0k used, 1044184k free, 277660k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND3809 jdoe 25 0 6256 3932 1312 R 93.8 0.8 0:21.49 bunzip22769 root 16 0 157m 80m 90m R 2.7 16.0 5:21.01 X3006 jdoe 15 0 30928 15m 27m S 0.3 3.0 0:22.40 kdeinit3008 jdoe 16 0 5624 892 4468 S 0.3 0.2 0:06.59 autorun3034 jdoe 15 0 26764 12m 24m S 0.3 2.5 0:12.68 kscd3810 jdoe 16 0 2892 916 1620 R 0.3 0.2 0:00.06 top

• You can change the sorting order by typingM: Memory usage, P: %CPU, T: Time.

• You can kill a task by typing k and the process id.

Page 25: Tutorial 2

Updating and installing packages

• Debian-based distros use a software installer called apt-get, which uses the Debian dpkg system to retrieve, unpack, and install software.

• Apt-get is the command you use to get that software.

• Synaptic is the GUI for apt-get

Page 26: Tutorial 2

Pipes• Unix pipes are very useful to redirect the

standard output of a command to the standard input of another one.

• Examples–cat *.log | grep -i error | sort

–grep -ri error . | grep -v “ignored” | sort -u \ > serious_errors.log

• This one of the most powerful features in Unix shells!

Page 27: Tutorial 2

Command prompt

• User_name@device_name:~$– ubuntu@ubuntu:~$

• Use UP arrow key to invoke previous commands

• Use TAB to auto-complete commands

Page 28: Tutorial 2

Conclusion

• You need to know the difference between relative and absolute path when dealing with Linux directories

• You need to know how Linux FS is different from Windows FS

• You need to know when to switch to super user privileges

Page 29: Tutorial 2

References

• The basic similarities between Linux and DOS– http://www.control-escape.com/linux/lx-basics.ht

ml• Introduction to Unix

– http://wwwhomes.doc.ic.ac.uk/~wjk/UnixIntro/• Windows-to-Linux Roadmap

– http://www.ibm.com/developerworks/linux/library/l-roadmap1.html


Recommended