Sunteți pe pagina 1din 26

Lesson3-4

We shall look at Linux shells Running commands at the shell prompt Commonly used CLI commands and utilities Shell: A shell is a command interpreter that allows you to type commands from the keyboard to interact with the operating system kernel. In addition,many shells provide features like job control, managing several processes at once, input and output redirection Shell Script: A shell script is a program in the shells command language and is analogous to a MS-DOS batch file. Types of shells: The most important difference between shells is the command language. Some of the shell include
sh (Bourne Shell): The sh shell was the earliest shell, being developed for UNIX back in the late 1970s. While not widely used on Linux systems, it is still very widely used on UNIX systems. bash (Bourne-Again Shell): The bash shell is an improved version of the sh shell and is one of the most popular shells today. Its the default shell used by most Linux distributions. If youre using the command line on a Linux system, more than likely youre using the bash shell.

csh (C Shell) :The csh shell was originally developed for BSD UNIX. It uses a syntax that is very similar to C programming. tsch: The tsch shell is an improved version of the C Shell. It is the default shell used on FreeBSD systems. zsh (Z Shell):The Z Shell is an improved version of the bash shell. You can identify which shell youre using by entering env at the current shell prompt. Note: While graphical user interfaces are generally easier to use, many, if not most, of the tasks you must perform to administer and support a Linux system must be done from the command line. Basically, end users use the GUI; administrators use the command line.

The X Window System. The X Window System, or simply X, is a standard graphical user interface (GUI) for UNIX machines and is a powerful environment which supports many applications. Using the X Window System, you can have multiple terminal windows on the screen at once,each having a different login session. Using the Shell Prompt The default prompt for a regular user is simply a dollar sign: $ The default prompt for the root user is a pound sign (also called a hash mark): # In most Linux systems, the $ and # prompts are preceded by your username, system name, and current directory name. For example sa-idowu@Toshiba-sa:~$ root@Toshiba-sa:~# In most Linux systems, your default shell is the bash shell. To find out what your current login shell is, type the following command: echo $shell You can activate a different one by simply typing the new shells command (ksh, tcsh, csh, sh, bash, and so forth) from the from the current shell.If you dont like your default shell, simply type the name of the shell you want to try out temporarily.(more on the use of shell later)

Checking Your Login Session When you log in to a Linux system, Linux views you as having a particular identity, which includes your username, group name, user ID, and group ID. Linux also keeps track of your login session: it knows when you logged in, how long you have been idle, and where you logged in from. To find out information about your identity, use the id command as follows: $ id You can see information about your current login session by using the who command. In the following example, the -u option says to add information about idle time and the process ID and -H asks that a header be printed: $ who -uH NAME LINE TIME IDLE PID COMMENT sa-idowu tty7 2010-10-03 16:52 old 1274 (:0) sa-idowu pts/0 2010-10-03 19:15 . 23699 (:0.0)

Ubuntu Linux Installation


Installation of Ubuntu implies that Somehow, all the files necessary to run Ubuntu are going to be put onto your hard disk. The PC will be configured so that it knows where to find these files when it first boots up. The Ubuntu operating system will be set up so that you can use it.

Understanding Partitioning
Linux generally isnt able to use the same file system as Windows, and it needs its own separately defined part of the disk, which is referred to as a partition. All of this can be handled automatically by the any given Linux distribution installation routine, but its important that you know what happens Note:Not all Linux distributions have the ability to repartition the hard disk. Most expect to simply take over the entire hard disk, wiping Windows in the process The ability to repartition a disk is just one of the reasons that Ubuntu is among the best Linux distributions currently available Partitioning the Harddisk(HD) The storage provided by HD is addressed through a continuous range, like a huge array. This storage can be split into a couple smaller address ranges, so called partitions. This is useful to separate data for example if you want to install different operating systems onto one HD

-Definition: Partitions are logical Harddisk residing on a physical disk. PC Systems define three types of partitions: Primary Partitions Extended Partitions (container of logical partitions) Logical Partitions -A PC disk can hold up to 4 primary partitions, or up to three primary partition plus an extended partition. -The extended partition, if there, counts as primary partition. It is used to hold logical partitions (many). -Partitions are usually identified by symbolic names. -MS Windows uses drive letters C:, D:, ... -Linux uses more complex symbols, like hda1, hda2,... for IDE partitions, sda1, sda2, ... for SCSI or SATA partitions hda1 |||| | | | Number of Partition (1 through 63) | | Identifies hard disks (a first disk, b second disk, ...) |Stands for disk, does never change Defines the type of controller system, h for IDE, s for SCSI or for SATA (Serial ATA)

Step-by-Step Installation Guide Step1:Prepare the Windows Partition for Resizing If your computer doesnt contain Windows, or if youre installing Ubuntu onto a second hard disk, then you can skip straight to stage 2. Step2: Boot from the DVD-ROM Step3: Select from the Boot Menu Start or Install Ubuntu from the menu Step4: Start the Install Program To install Ubuntu, double-click the Install icon on the desktop. Step5: Select Your Language Step6: Select Your Country and Time Zone Step7: Confirm Your Keyboard Layout Step8: Enter a Username. The username is how the computer itself will identify you.the username cannot begin with an uppercase letter, although you can use uppercase in the rest of the username.

Step9: Repartition Your Hard Disk The Ubuntu installation routine offers up to six options when it comes to disk partitioning: 1. Use the entire disk, if there is nothing else installed therein (that is, if the computeror hard disk is new). 2. Erase the existing partition(s), and use the entire hard disk. 3. Resize the existing Windows partition on the hard disk, and install Ubuntu alongside it in the newly created free space.

4. Use any free space that might already exist on the hard disk (perhaps if youve already manually repartitioned the disk earlier).
5. Manually edit the partition table, that is, resize/delete any existing partitons by hand and create the Ubuntu partitions. 6. Perform any of the previous options on a second hard disk that you have installed in your computer, leaving the first hard disk untouched.

IDE Hard Disk Identifiers Identifier Hardware Description Notes /dev/hda: Primary master The main hard disk in the computer and the on that is booted by default. /dev/hdb: Primary slave A hard disk connected to the same IDE cable as the main hard disk. On some budget computers, the CD/DVD drive is connected to the primary slave. /dev/hdc: Secondary master Usually, this is the CD/DVD drive. /dev/hdd: Secondary slave A hard disk connected to the same IDE cable as the CD/DVD drive. There are essentially two stages to work through if you choose OPTION 5 in Step 9. 1. Youre given the chance to repartition the disk manually, using a utility called GParted. Using this tool, you can resize or delete any existing partitions and create the partitions Ubuntu needs. 2. After partitioning has taken place, youll be asked to assign mount pointsyoull be prompted to tell Ubuntu which of the partitions on the disk it should use for the root file system (that is, the main partition for Ubuntus use), and which should be used for the swap partition(virtual memory in Windows). The swap partition acts as additional memory shouldthe main memory become full.

Step 10:Confirm Installation Choices


Step11:Wait During Installation Step12:Reboot and Enjoy Ubuntu!

Debian Software Management Debian comes with a couple of software management tools for downloading, installing and configuration of additional software packages for your system Software comes mostly precompiled bundled in packages, hence the name package manager. The Debian package manager is able to resolve dependencies between packages automatically. The package manager is able to update the system without operator interaction. The most important Debian package tools are: apt and dpkg

Debian Package tools dpkg (Debian package manager) Is the Package Manager Installs packages removes packages configures packages keeps track of the installed packages using a database apt (Advanced package tool) Connects to package sources (CD-Rom, Internet, ...) Auto downloads packages to a cache directory Solves dependencies between packages Apt is a frontend tool to dpkg Provides software search functionalities

Debian Software Management: dpkg # dpkg list List all installed packages # dpkg S <filename> Find the packages owning the file # dpkg install <filename.deb> Install the package # dpkg remove <filename.deb> Remove the package # dpkg-reconfigure <filename.deb> Configure the package Debian Software Management: apt # apt-cache search <text> Search all packages related to text # apt-get install <package> Auto download and install a package and its dependent packages # apt-get remove <package> Remove the package with or without dependencies # apt-get update Reload the list of all available software from the source directories (CD-Rom, Internet) # apt-get upgrade Upgrade all installed packages

# apt-get dist-upgrade Upgrade the entire system from one version to the newest one. (Ex: from sarge to etch). Use with care! # tasksel Select multiple packages to install at once. (Ex: the Task Desktop Environment will install all packages required for desktop computing, like gnome and

Lab Exercises II In this exercise, you learn how to access the shell prompt, change shells, and access alternate console screens. Complete the following: 1. Boot your Linux system to a shell prompt . If your system booted into a graphical system, log in and then press crtl+alt+F1 2. At your login prompt, authenticate to the system. 3. View your default shell by entering echo $SHELL at the prompt. Your default shell is displayed. On most systems, this will be /bin/bash. 4. Open an alternate console window by pressing alt+F2. A new login prompt is displayed 5. Authenticate again to the system. 6. Return to the first console screen by selecting alt+F1 7. Load the zsh shell by entering zsh at the prompt. 8. Return to your default shell by entering exit at the prompt.

Common Linux commands and utilities

halt: This command shuts down the operating system, but can only be run by the root reboot: This command shuts down and restarts the operating system. It also can init 0: This command also shuts down the operating system, and can only

user.

only be run by root.

be run by your root user.

init 6: This command also shuts down and restarts the operating system. It
man: This command opens the manual page for the command or utility

also can only be run by root.

specified. The man utility is a very useful tool. If you are unsure how to use

any command, use man to access its manual page. For example, you could
enter man ls at the shell prompt to learn how to use the ls utility.

date: Displays the current date and time according to the computer. Example:sa-idowu@Toshiba-sa:~$ date Sun Oct 24 22:10:38 WAT 2010 cal: Display a calendar for a specific month

Example: sa-idowu@Toshiba-sa:~$ cal 3 2010 March 2010 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31


Filters Filters are UNIX commands that take input or the contents of a file, modify that content and then display the result on output.

cat
The simplest filter, cat doesn't perform any modification on the information passed through it

head and tail head and tail allow you to view the first few lines or the last few lines of a file .

Examples head chap1.html Display the first 10 lines of chap1.html tail chap1.html display the last 10 lines of chap1.html head -c 100 chap1.html display the first 100 bytes of chap1.html head -l 50 chap1.html display the first 50 lines of chap1.html tail -c 95 chap1.html display the last 100 bytes of chap1.html sort

uniq
uniq is used to find or remove and duplicate lines from a file and display what is left onto the screen.

uniq names
remove duplicate lines from names and display them on the screen uniq names uniq.names remove duplicates lines from names and put them into uniq.names uniq -d names display all duplicate lines

tr
Used to translate specified characters into other characters. tr is used in conjunction with I/O redirection which will be discussed later!

Examples
tr a z < /etc/passwd translate all a's to z's in /etc/passwd and display on the screen tr '[A-Z]' '[a-z]' < /etc/passwd translate any character in between A-Z into the equivalent character between a-z. (make all upper-case characters lower case) tr -d ' ' < /etc/passwd delete any single space characters from the file Note: In the example shown above the < character is an I/O redirection character. grep grep stands for Global Regular Expression Pattern match. It is used to search a file for a particular pattern of characters. grep david /etc/passwd display any line from /etc/passwd that contains david To get the real power out of grep you need to be familiar with regular expressions which are discussed in more detail in a later.

info: The info utility also displays a help page for the indicated command or utility. The information displayed tends to be more in-depth than that displayed in the man page for the same command. su: This command switches the current user to a new user account. For example, if youre logged in as ezra and need to change to user account tolu, you can enter su tolu at the shell prompt. This command is most frequently used to switch to the superuser root account. env: This command displays the environment variables for the currently logged-in user.

echo: This command is used to echo a line of text on the screen. Its frequently used to display environment variables. For example, if you wanted to see the current value of the PATH variable, you could enter echo $PATH.

Note: The su command is many times mistakenly thought to stand for super user. It doesnt. It stands for switch user.
top: This command is a very useful command that displays a list of all applications and processes currently running on the system. You can sort them by CPU usage, memory usage, process ID number, and which user owns them. which: This command is used to display the full path to a shell command or utility. For example, if you wanted to know the full path to the ls command, you would enter which ls.

whoami:This command displays the username of the currently logged-in user. netstat: This command displays the status of the network, including current connections, routing tables, etc
route:This command is used to view or manipulate the systems routing table. ifconfig: This command is used to manage network boards installed in the system. It can be used to display or modify your network board configuration parameters. This command can only be run by the root user. Exercise III(Using Linux Shell) 1.Boot your Linux system to a shell prompt If your system booted into a graphical system, log in and then press ctrl +T to enter the terminal window or ctrl +Alt+F1 2. At your login prompt, authenticate to the system. 3. At the shell prompt, determine your current directory by entering pwd. What is the current directory? 4. Determine the current user by entering whoami. Who is the current user? 5. Create a directory listing of the files in the current directory by entering ls. 6. Get more information about the ls utility by entering man ls at the shell prompt. 7. Use the key to scroll through the man page. Which option can you use with ls to use a long listing format? 8. Press q. 9. Create a long listing with the ls command by entering ls l at the shell prompt.

Using the Linux Graphical User Interface In addition to the shell prompt, most Linux systems also offer a graphical user interface (GUI).The X Window System provides the base system for the graphical interface on Linux. It allows programmers to run applications in windows. However, the X Window System alone isnt enough. You have to have three additional components to create a fully functional Linux GUI system: Window Managers: The role of the window manager is to control the appearance of the windows on the screen. It also determines how they are arranged on the screen. Commonly used window managers include the following: Enlightenment Window Maker Sawfish fvwm IceWM Xfwm twm GUI Toolkits: GUI toolkits are libraries used by programmers to create X Window applications. On Linux, the GTK+, Motif, and Qt toolkits are commonly used.

Desktop Environments: The desktop environment is used to actually present the GUI desktop to the end user. It allows you to place icons on the desktop, customize the appearance of your windows, add wallpaper to the desktop background, and so on. Two very popular Linux desktop environments include the K Desktop Environment (KDE) and GNOME.

Note: When you put these three components together, you create a graphical user interface on your Linux system that works in a very similar manner as Microsoft Windows.
Within the KDE desktop environment, there are Trash, My Computer, and Network Browsing icons, These three desktop elements correspond to the Recycle Bin, My Computer, and My Network Places elements in Microsoft Windows

Scenario and Solution: Scenario I You want to start using Linux on your users desktops. What issues should you consider before doing so? Solution First of all, Linux can be intimidating to the average end user. You may want to consider implementing an extensive training program. Second, you should make sure you install software packages that will allow them to complete their day-to-day tasks. Scenario II Youve been tasked with implementing a Linux system in your organization that will run a network- based database application. What type of distribution should you choose. Solution Because the system will be used to provide a network-based service to client systems, you should consider using a distribution that has been optimized to function as a network server. Scenario III Youre installing a new Linux system. This system will host mission-critical applications. This system must perform as fast as possible. It must protect the integrity of the server data if the system goes down unexpectedly. If it does go down, the system needs to be back up and running as quickly as possible. Which file system would be the best choice? Solution Because of the requirements specified, the Reiser file system would be the best choice. Reiser is considered to be the fastest Linux file system. It also uses journaling to protect data and to speed up crash recovery.

Study Questions 1. Which of the following are applications? (Choose two.) a).Linux b).MySQL c).VMware

2.Your company recently purchased 12 new computer systems. The computers have Intel Pentium IV 2.5 GHz CPUs and 40MB hard drives. Your supervisor wants to install Linux on them, but is concerned that it cant be done because they already have Windows XP Professional installed. Can this be done? a). Yes, but you must install a new hard drive for Linux. b).No, Windows is embedded in the system hardware. You must purchase systems without an operating system installed. c). No, modern motherboards are hard-coded to recognize your Windows Certificate of Authority. If it doesnt find this, the system wont boot. d). Yes, you can erase the hard drive and install Linux
3 Which of the following is the true operating system component within Linux? a).Linux libraries b).Linux kernel c).X Window System d).bash shell 4.Which shell is the default shell for most Linux distributions? a).sh b).csh c).bash d).zsh

5.You need to find out what directories in the Linux file system are parts of the path. What command can you use? (Choose two.) a). env b).show $PATH c). man path d). echo $PATH 6.Which Linux utility can be used to display a list of all running processes on your system? a).env b).procman c).processes d).top 7.Which Linux utility can be used to change to a different user account at the shell prompt? a).user b).chuser c).swuser d).su

S-ar putea să vă placă și