Professional Documents
Culture Documents
Introduction and GNU Commands: Linux
Introduction and GNU Commands: Linux
Introduction
Linux at lowest level, is based on linux kernel the very low-level software that manages our computer hardware, multi-tasks the many programs that are running at any given time, and other such essential things Linux Operating System has various utilities, for example shell (that provides a command prompt), cp (a program to copy files) etc. Finally, software companies (and sometimes volunteer groups) add on lots of extra software, like KDE,GNOME,Xfree86 X Windows System, games , etc. Together, the operating system kernel, system software (such as cp, shell etc), and application software(GNOME,KDE,XFree86 etc) collectively, is called as "Linux.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL
Application Software
Like most UNIX implementations, Linux is composed of three main bodies of code; the most important distinction between the kernel and all other components. The kernel is responsible for maintaining the important abstractions of the operating system.
Kernel code executes in kernel mode with full access to all the physical resources of the computer. All kernel code and data structures are kept in the same single address space.
The system libraries define a standard set of functions through which applications interact with the kernel, and which implement much of the operating-system functionality that does not need the full privileges of kernel code. The system utilities perform individual specialized management tasks.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 4
Design Principles
Linux is a multiuser, multitasking system with a full set of UNIXcompatible tools.. Its file system adheres to traditional UNIX semantics, and it fully implements the standard UNIX networking model. Main design goals are speed, efficiency, and standardization. Linux is designed to be compliant with the relevant POSIX documents; at least two Linux distributions have achieved official POSIX certification. The Linux programming interface adheres to the SVR4 UNIX semantics, rather than to BSD behavior.
Unix Architecture 2
Kernel
Hardware is surrounded by Operating System software Operating System is often called System Kernel or Kernel Isolated from users and applications Mostly Monolithic
Unix Architecture 3
Operating System contains primitive routines that allow direct hardware access Provides interface for user interaction Users gain access to specific kernel functions through Unix commands
History
In 25th August 1991 he sent a mail to Newsgroups: comp.os.minix stating about his project (Linux), which became a huge success after wards.
Taxonomy Linux in Desktop & Enterprise
Free Applications
Development Environment Development Infrastructure
Y
Y Y
Y
Ok Ok
X
X X
Support
Price
Y
Y
Y
Y
Copyright 2004 Virtusa Corporation | CONFIDENTIAL
Ok
X
10
Linux Installation
Partitioning
File System /dev/hda1 Memory 200-500 MB Mounted On /boot
11
Installation
Linux needs about 10MB for a very minimal installation. Some popular vendors of Linux: redhat, suse, mandrake, gentoo, debian, slackware, turbo linux, Lycoris, stampede,Tiny Linux, phat linux etc.
12
RPM
Ease of installation and uninstallation Ease of upgrading already-installed packages Protection of configuration files Simple tracking of installed files
Example
To install a new software: rpm ivh pckg_name To install a software forcibly: rpm ivh force pckg_name To remove a software: rpm e pckg_name To remove a software without checking dependencies: rpm e nodep pck_name To Upgrade an existing software : rpm uvh pckg_name To query for a software: rpm a pckg_name To query for software from all list: rpm qa | grep pckg_name
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 13
GNU Commands
cd: change directory cp: copy filesCat: print out file onto Screen mv: rename or move a file mkdir: Make a Directory ls: show directory, in alphabetical order. rm: remove a file more: view a file, pausing every screenful. who: show up who you are locate: find a file passwd: cahnge password. man: shows help on specific command df:shows disk space available on system du: shows how much disk space being used up Free: display information about free and used memory Gzip/zip/bzip: to compress a file Tar: combines mulitple files into one file or vice versa.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 14
Appropos: search the what is database for string Makewhatis: create the what is datdabase Whatis: search what is database for sort: to sort files in a directory. comp: to compare files. diff: difference between two files. grep: search for a string in a file. finger: shows more information about a user find: to find a file netstat: print network connections, routine tables etc. ifconfig: configure a network interface. cmp: to compare two files. Ps: report process status Pstree: display a tree of process. Top: to display top CPU process.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 15
PATH
Contains list of all directories that hold commands or other programs that are likely to be executed $echo $PATH
Environment Variables
Environment variables are passed on to programs and other shells, and together they are said to form the environment in which the programs execute $export MYVAR
16
List files ls
$ls l $ls a $ls *.c $ls la
$w
Man
Inbuilt help $man helptopic
17
Command History
Refers to the most recent command. Refer to command n from the history. You'll use the history command to display these numbers. Refer to the current command minus n from the history. Refer to the most recent command starting with string. Refer to the most recent command containing string. Quick substitution. Repeat the last command, replacing the first occurrence of string1 with string2.
18
Cut out selected columns or fields from one or more files Frequently used options -b list Print bytes in list positions. -c list Print characters in list columns. -d delim Set field delimiter for -f. -f list Print list fields. $ cut -c 1 /etc/passwd $ cut -d: -f1 /etc/passwd
19
$join [options] file1 file2 Print a line for each pair of input lines, one each from file1 and file2, that have identical join fields. Frequently used options -j1 field Join on field of file1. -j2 field Join on field of file2. -j field Join on field of both file1 and file2. Example File 1 File2 $join j 1 File1 File2 1 one 1 11 1 one 11 2 two 2 22 2 two 22 3 three 3 33 3 three 33
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 20
Head
$head [options] files Print the first few lines of one or more files.
Nl
$nl [options] [files] Used for numbering lines in the body of the text.
Paste
Paste together corresponding lines of one or more files into vertical columns. File1 file2 $paste file1 file2 1 A 1 A 2 B 2 B 3 C 3 C
21
Paste
File1 1 2 3 File1 1 2 3 file2 A B C file2 A B C $paste d@ file1 file2 1@A 2@B 3@C $paste s file1 file2 1 2 3 A B C
Split
Splitting a file into specified number of line groups, with output going into a succession of files Frequently used option -n Split the infile into n-line segments. The default is 1000.
22
Split
Example File1 1 one 2 two 3 three 4 four 5 five 6 six $split 2 file1 splitout_ yields three new files splitout_aa, splitout_ab, splitout_ac
Tac
23
Translate characters from string1 to the corresponding characters in string2. Frequently used options -d Delete characters in string1 from the output. -s Squeeze out repeated output characters in string1 $ cat file1 | tr a-z A-Z $ cat file1 | tr -s a cat file1 | tr -d abc
24
Wc
Print counts of characters, words, and lines for files. Frequently used options -c Print the character count only. -l Print the line count only. -w Print the word count only $ wc -l file1 $wc file1
25
Copy Files
$cp [options] file1 file2 $cp [options] files directory
Make Directory
$mkdir source $mkdir good bad ugly $mkdir good bad ugly
Move Files
$mv src tgt
Remove Files
$rm [options] files
26
Remove Directories
$rmdir [options] direcotories
Move Files
$mv src tgt
Remove Files
$rm [options] files
27
Process Monitoring 1
$ps [options]
This command generates a one-time snapshot of the current processes on standard output. $ps
$ ps -aux | grep httpd
Process Monitoring 2
$mozilla &
$bg [jobspec] Place jobspec in the background, as if it had been started with & $fg [jobspec] This command places the specified job in the foreground, making it the current job.
29
Grep Search files or standard input for lines containing a match to regular expression regex. $grep [options] regex [files] Frequently used options -c Display only a count of matched lines, but not the lines themselves. -h Display matched lines, but do not include filenames for multiple file input. -i Ignore uppercase and lowercase distinctions, allowing abc to match both abc and ABC. -n Display matched lines prefixed with their line numbers. When used with multiple files, both the filename and line number are prefixed. -v Print all lines that do not match regex.
30
Regular Expression
Description
Match at the beginning of a line. This interpretation makes sense only when the ^ character is at the lefthand side of the regex. Match at the end of a line. This interpretation makes sense only when the $ character is at the righthand side of the regex.
31
[abc][a-z]
Single-character groups and ranges. In the first form, match any single character from among the enclosed characters a, b, or c. In the second form, match any single character from among the range of characters bounded by a and z. The brackets are for grouping only and are not matched themselves.
[^abc] [^a-z]
Inverse match. Match any single character not among the enclosed characters a, b, and c or in the range a-z. Be careful not to confuse this inversion with the anchor character ^, described earlier. Match words. Words are essentially defined as being character sets surrounded by whitespace and adjacent to the start of line, the end of line, or punctuation marks. The backslashes are required and enable this interpretation of < and >. Match any single character except a newline. As mentioned in the section on quoting earlier, turn off (escape) the special meaning of the character that follows, turning met characters in to literals.
Copyright 2004 Virtusa Corporation | CONFIDENTIAL 32
\<word\>
33
Further References.
34