Linux Shell
Linux Shell
Linux Shell
Linux OS Layers
Shell
User
Hardware
Kernel
1. Shells are designed to handle short, simple tasks. They lack the
rigid structure and semantic checking of a high-level language. Shell scripts can be written quickly because they assume the programmer knows what he or she is doing, and for short scripts, this is usually true.
Installing Bash
Bash is the standard shell on most Linux distributions. However, there are other Linux shells available and theres no requirement that Bash should be present on any particular distribution. The Bash shell is open source software released under the GNU Pubic License (GPL). If you need to install Bash, the C language source code is freely available from the Free Software Foundation at www.gnu.org or through one of its download mirrors.
10
Installing Bash
The Bash installation procedure can vary over time. Complete instructions are found in the README file that accompanies the sources. However, the installation is largely automated. The basic procedure is as follows:
2. Run make to build Bash. 3. Run make tests. This will run diagnostic tests to ensure Bash was
built properly.
11
12
13
/dev /bin and /usr/bin /lib and /usr/lib /var /etc /usr/local/bin /opt /tmp /sbin and /usr/sbin
Contains device drivers Contains standard Linux commands Contains standard Linux libraries Contains configuration and log files Contains default configuration files Contains commands not a part of the distribution, added by your administrator Contains commercial software Stores temporary files Contains system administration commands (/sbin stands for safe bin)
14
Directories
Root directory Home directory (~) Current directory (.) Parent directory (..)
15
16
Hard Links
A hard link is a reference to another file in the current directory or a different directory. Whenever some action is performed to the hard link, it is actually done to the file the hard link refers to. Hard links are accessed quickly because they do not have to be dereferenced, but Linux limits where a hard link can be placed. As long as a file is being referred to by at least one directory entry, it wont be deleted. For example, if a file has one hard link, both the link and the original file have to be deleted to remove the file.
17
Symbolic Links
The second and more common link is the symbolic link. This link is a file that contains the pathname of another file. Unlike hard links, symbolic links have no restrictions on where they can be used. They are slower and some commands affect the link file itself instead of the file the link points to. Symbolic links are not hard because they have to be dereferenced: When Linux opens the symbolic link file, it reads the correct pathname and opens that file instead. When the file being referred to is deleted, the symbolic link file becomes a dangling link to a non-existent file.
18
Inodes
Using links means that two different pathnames can indicate the same file. To identify a particular file, Linux assigns a number to each file. This number is called the inode (or index node) and is unique to any storage device. If two pathnames refer to a file with the same inode, one of the paths is a hard link.
19
Inodes
In the ext2 file system, there is a limited number of inodes, which in turn places an upper limit to the number of files that can be stored on a disk. The number of inodes compared to the amount of disk space is called the inode density. The density is specified when a disk or partition is initialized. Most Linux distributions use an inode density of 4K, or one node per every 4096 bytes of disk space.
20
21
Device Files
The last common kind of nonregular file is a device file. Keeping with the file-oriented design of Linux, devices are represented by files. Device files allow direct communication to a particular device attached to a computer. There are actually two kinds of device files, but shell programmers are mainly interested in the type called character device files.
22
Device Files
All devices files are located in the /dev directory. Even though many files are listed in /dev, not all of these devices might actually be present. Rather, /dev contains a list of devices that can be attached to your computer because the Linux kernel was configured to recognize them if they were attached. Most of these files are not accessible to regular users, but there are a few that are open to general use.
23
Device Files
/dev/null One important device file available to all users is /dev/null. This file represents an imaginary black hole device attached to your computer that consumes anything sent to it. This is useful for discarding unwanted responses from a shell command. /dev/null can also be read, but the file is always empty.
24
Device Files
/dev/zero Another device file is /dev/zero. This file contains an endless stream of zeros, and can be used to create new files that are filled entirely with zeros.
25
Device Files
There are a variety of other devices that might appear in /dev, depending on your distribution and computer hardware. Common device files include:
/dev/fd0: The first floppy drive /dev/hda1: The first IDE drive partition /dev/sda1: The first SCSI drive partition
26
Assignment (5 points)
Make a list of similarities and differences between inodes in various Linux file systems such as ext-2 and ext-3. Deadline: November 13th, 10:00 AM How to Via email to memarypour@gmail.com This assignment is mandatory! deliver?!
27