Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Linux command
Description: here linux command notes for book

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


LINUX TUTORIAL

1

LINUX
TUTORIAL

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

2

Table of Contents
1
...
4
1
...


History of UNIX
...
2
...
4

1
...


Why LINUX/UNIX
...
4
...
5

2
...
7

3
...
8
3
...


Control Keys
...
2
...
8

3
...


LINUX Command Options
...
4
...
10
3
...
1
...
10
3
...
2
...
16
3
...
3
...
20
3
...
4
...
22
3
...
5 List of User Commands
...
4
...
31

4
...
32
4
...

4
...


Commands in File System
...
3
...


Directories in LINUX
...
36

SHELL
...
1
...
44

5
...


Special Commands
...
2
...
45
5
...
2 Command Seperator
...
2
...
46

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

6
...
47
6
...


Scripting
...
2
...
47
6
...
1
...
47
6
...
2
...
47

6
...


Shell Variables
...
3
...
Scalar Variables
...
3
...
48

7
...
49
7
...


Shell Scripting in Bourne
...
2
...
49

7
...


Arithmetic Expansion
...
4
...
50

7
...


Fille Descriptors
...
6
...
53

7
...


File Archiving, Compression and Conversion
...
8
...
Error! Bookmark not defined
...
9
...
Error! Bookmark not defined
...
9
...
57
7
...
1
...
Cursor Movement
...
9
...
2
...
58
7
...
1
...
Deleting of Text
...
9
...
4
...
58
7
...
1
...
To see Multiple Files
...


KEY BOARD SHORTCUTS
...


NETWORKING IN LINUX
...
1
...
61

9
...


Network Commands
...
0
...
What is Linux?
1
...

v UNIX was developed about 40 years ago i
...
, 1969 at AT&T Bell Labs by Ken Thompson
and Dennis Ritche
...

v It was developed for the Mini-Computers as a time sharing system
...


1
...

v LINUX is a open source
...


1
...

• Can view and edit the source code of OS
v It is fully customizable
...

v High Portability
• Easy to port new H/W Platform
• Written in C which is highly portable

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

5

1
...
Layers of LINUX/UNIX
v LINUX/UNIX has three most important parts
...
1 Layers of Linux

1
...
1 Kernel:
v Kernel is the heart of the operating system
...

v Functions
• Manage Memory, I/O devices, allocates the time between user and
process, inter process communication, sets process priority

1
...
2 Shell:
v The shell is a program that sits on the as an interface between users and kernel
v It is a command interpreter and also has programming capability of its own
...
0
...
4
...
Arranged as a

directory hierarchy
...


07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

7

2
...

v Login is user unique name
...

v Password can be changed by the user at any time
...
0
...
LINUX Commands
v Commands tell the operating system to perform set of operations
...
1Control Keys:
v Control Keys performs special function
...
2Getting Help:
v In LINUX/UNIX whenever you need help with a command type “man” followed by
the command name
...

-k à Keyword list command for all keyword matches
...

command - -help

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

9

Fig
...
1man command

3
...
”)
-l à lists the size, creation date and permissions about all the files and directories in
the current directory
-d à lists the directory
-c à don’t create file if it already present
-f à force
-k à block Size
-R à recursive
-t à type
-V à version
...
0
...
4 LINUX Commands:
3
...
1Basic File Commands:
Command: ls
v To lists the files in the current directory use “ls”
...
3
...
0
...

Moves one level hierarchy down from the current directory
v cd
...
3
...
0
...

v Syntax: $ mkdir directoryname
v $mkdir –p dir1/dir2/dir3
...
dir3 will created under dir2 and dir2 is created
under dir1
...

It will point the location of dir5
...

It will create dir5 first and then point the location of dir5
...
(‘;’ called command separator, explained later)

Fig
...
4 mkdir command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

13

Command: cat
v $ cat filename
It will display the contents of the file filename
...

[Ctrl+d]
$
• The above command creates the file called file1 and you can enter the text
there only
...

• If file1 already exists then it over writes the contents of the file1
...

v $cat >>flie1
It’s a progressive journey
...
It’s a progressive journey
...

v $cat flie1 file2 >file3
• The above command is used to write contents of the file1 and file 2 into
file3

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

14

Command: cp
v Syntax $ cp [options] Source Destination
Copies Source into Destination
v $ cp file1 file2
Copies file1 into file2
v $ cp -prf /home/kacper/ /hdd/backup/
Copies all files, directories, and subdirectories inside kacper into backup
v Options:
-i
à interactive
prompts before overwriting
-f

à force
if an existing destination file cannot be opened, remove it and try again

-p

à preserve
preserve mode, ownership, and timestamps

-R, -r à recursive
copy directories recursively
-u

07/10/2009

à update
copy only when the SOURCE file is newer than the destination file or
when the destination file is missing

Linux Tutorial 1
...
doc

LINUX TUTORIAL

15

Command: mv
v
v
v
v
v

To move a file to different location use “mv”
...

$ mv filename1 filename2 (Rename file)
$mv /home/kacper/top
...
v into backup directory
v $mv -i /home/kacper/top
...

Syntax: $ rm filename
rm –i * prompts you before deleting a file
...

rm –rf * recursively removes all files and subdirectories in your current directory,
without prompting to delete files
...


07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

16

Command: rmdir
v To remove a empty directory use “rmdir”
...

v Syntax: $ pwd
Displays the present working directory

3
...
2Display Commands:
Command: less
v
v
v
v

“less” displays a file, allowing forward/backward movement within it
...

Press “q” to quit
...

+n
à starts printing from nth line

Fig
...
5 less command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

17

Command: head
v
v
v
v

“head” displays the top part of a file
...

-n allows you to change the number of lines to be shown
...
txt” displays the first 50 lines of the file
...


Fig
...
6 head command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

18

Command: tail
v Displays last 10(by default) lines of a file
...

v Syntax:$ tail filename
Displays the last 10 lines from the ending
$tail -12 filename
Displays the last 12 lines from the ending

Fig
...
7tail command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

19

Command: more
v Read files and displays the text one screen at a time
...

-n à displays the first n lines of the file
...


Fig
...
8 more command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

20

3
...
3 File Permissions:
v Each file in UNIX/LINUX has an associated permission level
...

v Use “ls –l filename ” to find permission level of that file
...

“w” means “write” permission
...

In case of directory, “x” grants permission to list directory contents
...

v Syntax:
$ chmod [user/group/others/all]+[permission] filename

Command: chgrp
v Change the group of the file
...

Example 1:
chmod 7
7
7
filename
user group others
è Gives user, group and others r, w, x permissions

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

21

Example 2: chmod 750 filename
è Gives the user read, write and execute
...

è Gives others no permissions
...
3
...
0
...
4
...

v Syntax:$ date

Fig
...
10 date command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

23

Command: chsh
v Change the user’s login shell
...
3
...
0
...

v Syntax:$ passwd [options]

Fig
...
12passwd command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

25

Command: ps
v To view the processes that you are running
...
3
...
0
...

v Syntax:$ top

Fig
...
14 top command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

27

Command: kill
v A user can only start/kill the process that have the user id
...

v Syntax: $ kill [-signal] [process id]
$kill -9 process id
It gives the guarantee that the process would be killed
...
3
...
0
...
4
...

v Syntax: $ who

Fig
...
16 who command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

29

Command: who am i
v Reports the details about the command user
...
3
...
0
...

v Syntax:$ whoami

Fig
...
18 whoami command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

31

3
...
6 List of disk Space commands
v $ du [options] [directory or file]
Gives the amount of disk space in use
v $du –sh file/dir
Gives the size of the file/dir
v $df -h or df –kh
Gives the Available space mounted on file System
v $free
Gives the free space

Fig 3
...
0
...

v There are three types of files
...

Ø Directory Files:
§ Directory file contains an entry for every file and subdirectory that it is
placed
...


Fig
...
1File System

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

33

4
...


v

Directory: /boot
/boot has all the files required for booting LINUX on system
...


v

Directory: /etc
/etc contains the configuration files of the various software
...


v

Directory: /home
/home is like My Documents in Windows
...


v

Directory: /lib
/lib contains the libraries required fo r the system files
...


v

Directory: /mnt
This is the directory in which we mount the devices and other file systems
...


v

Directory: /root
The directory for the user root

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

34

4
...

v The fgrep contains various options
...

è -v for displaying the lines that don’t match
...

v Syntax:$ fgrep [options] textfiles

Command: find
v The find command is used to find the files in the hard drive
...

v Example: $ find /user/bin –type f –atime +100 –print
v We can also use find to show the postscript files in our directory
...
pl
v Syntax :$ find directory [options] [actions]

Fig
...
2find command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

35

Command: locate
v
v
v
v

The locate command is much faster than the find command
...

The files are printed with the path if we use this command
...
4
...
0
...
3 Commands for showing file details:
Command: wc
v $ wc[options] filename
...
4
...
0
...

v Syntax:
$ sort filename

Fig
...
5 sort command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

38

Command: uniq
v Used to print the file by removing duplicate adjacent lines
...
First it
will sort the file and then passed to uniq (| is called pipe, explained later section)

Fig 4
...
0
...

v Syntax :$touch file2
It will create the file called file2 of size zero bytes, if file2 doesn’t exist
...
(i
...
dates and times of the recent modification or
access)
v For example to change the last access time of file6 to 10:10 a
...
May 2, 2009, it can
be done in the following way
...

It will change the time stamp of the file6
...

$ ls –l file6
-rw-r--r-- 1 root root 120 May 2 2009 file6
$ touch –t 08021130 file7
It can change the date and time
...
In general the expression type is MMDDhhmm
...
6 touch command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

40

Command: tee
v Sends the output in two directions at a time
v Syntax: tee [options ] filename
...


$ls –l |tee –a file2
It will append the list to file2
...
7 tee command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

41

Command: cmp
v This cmp command tests whether two files are identical and reports position of first
character
...

v Syntax:
$ cmp filename1 filename2

Fig
...
8 cmp command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

42

Command: find
v This command is used to find the location of a file
...
–name “top
...
v in the current directory
...
–type d
Finds all directories
...
*”
Finds all hidden directories
$find
...
–type f –name”
...
4
...
0
...

v $vimdiff filename1 filename2 or sdiff filename1 filename2
It will display the two files side by side

Fig
...
10vimdiff command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

44

5
...

The shell is a command interpreter and a programming language in built
...

The commonly used shells are Bourne Shell (sh), C Shell (csh or tcsh) and Korn Shell
(ksh)
...

These shells have their own built in functions which allow for the creation of the shell
scripts
...

The prompt for the Bourne shell is $ or # for the root user and the prompt for the C
shell is %
...

All shells use different syntax and provide different services
...
1 Built-in Commands:
cd
echo
eval
case
exec
exit
export
for
if
set
test
trap
unmask
unset
wait
while

07/10/2009

Change the working directory
...

Evaluating the given data
...

Executing the given command
...

Share the specified environment variable with other shells
...

If conditional loop
...

Evaluate the expression as true or false
...

Set a default file permission mask for new files
...

Wait for a specified process to terminate
...


Linux Tutorial 1
...
doc

LINUX TUTORIAL

45

5
...
2
...
This process is called piping
...

Syntax:
$ ls |wc –l
It will display number of files in the current directory
...

$cat file | head | tail -6

It will display last six lines of first of first ten lines
...
2
...

v Syntax: $ comand1 ; comand2
v Ex: $ls –l ; cat file
It will lists all files first and then displays the contents of file called file
...
0
...
2
...

v The alias can be set and it be removed by using the unalias command
...
5
...
0
...
Shell Scripting
6
...

v Here pipes and file handling are used to connect subtasks
...

6
...
2
...

v The available options for sort are
-t
-k
-n
-r

Field separator
Field to sort by
Use numeric order
Reverse direction

6
...
2 Join :
v Join combines two files based on value of common field
...

v The available options are

-1
-2
-t

07/10/2009

Field to join on first file
Field to join on second file
Field separator

Linux Tutorial 1
...
doc

LINUX TUTORIAL

48

6
...

The shell allows the user to create, assign and delete variables
...

There are two types of variables, they are
è Scalar variables
...


6
...
1 Scalar variables:
v A scalar variable can hold only one value at a time
...

v Because a variables name and its value can be thought as a pair
...
3
...

v Here we can create a single array variable and store the other variables
...
0
...
Shell Programming in Bourne Shell
v Here the Commands run from a file in a subshell
...


7
...

v Here by using the chmod we can set the file permissions for the file
...
/filename
...
2 Shell variables:
v Variables are referenced by $name
...
/filename
...
0
...
3 Arithmetic Expansion:
v Arithmetic Expansion is in the form of $((Expression))
...

v Example:
#! /bin/sh
echo $((5+5+5))
Output:
$
...
sh
15

7
...

v Both shells have different syntax
...
0
...

v Syntax:
while condition
do
command list
break
continue
done

Command: for and foreach
v One way to loop through a list of string values is with the for and foreach
commands
...
(no
need to write the script, you can directly use in command window)
$foreach i cat ( `cat list`) # list contains all files what you want run
%echo $i
% run_cmd $i
%end

It will run all the files present in list
...
0
...
5 File Descriptors :
v The file descriptor has 3 standard file descriptors
...

è Stdout, Standard output from the program
...

v The file redirections are listed below:
>

Output redirect

>!

Output redirect but overrides noclobber option of csh

>>

Append output

>>!
|

Append output but overrides noclobber option of csh and creates the file if it
doesn’t already exist
Pipe output to another command

<

Input redirection

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

53

7
...
1Text Processing Commands:
v awk/nawk [options] filename, scan for patterns in a file and process results
...

v sed [options] filename, stream editor for editing files from a script or from the
command line
...

v fgrep searches for exact strings and egrep uses “extended” regular expressions
...
v
It will look for module in top
...
7
...
0
...

sed for substitution
...

sed –i

g

It will do substitution(insert) in the file ,filename
...

(sed ‘s/oldvalue/newvalue/g’ filename )

e For multiple Substituions
(sed -e ‘s/oldvalue1/newvalue1/’ –e ‘s/oldvalue2/newvalue2/’ filename )

Fig
...
2 sed command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

55

7
...

v Example: $zip filename
...
] or [dir1 dir2 dir3
...
zip containing all the files or
directories
$unzip filename
...
zip into current
directory
v tar key[options] filename tar archive refer to man pages for details on creating,
listings and retrieving from archive files
...

v Example: $tar -cf filename
...
]
It will create a file named filename
...
tar
It will display all files in filename
...
tar
It will copy all the files or directories from filename
...
8 Applications
There are some frequently used applications or programs which may be invoked
through commands also
...
However, these commands will work only if the applications are installed
...
pdf
kpdf
filename
...
pdf

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

56

For OpenOffice
v oowriter is a viewer and editor for MS Office like document files
...
doc or filename
...
doc
oowriter
It will open new file
v ooimpress is used for preparing Power point like Presentations
v Syntax : ooimpress filename
...
pps
It will open a file called filename
...

v Syntax: oodraw filename
...
sxd
oodraw
It will open new file
v oocalc is used to open and edit Spreadsheet like xls or sxc files
...
sxc or filename
...
sxc
oocalc
It will open new file

For Mozilla Firefox
v firefox is used to open Mozilla web browser
...
systemverilog
...

$firefox
It will open the browser

For Opera Browser
v opera is used to open opera web browser
v Example:$opera www
...
in
It will open corresponding web page
...
0
...
9 Editors :
v Editors are the one by which we can edit the files
...

èGraphical editor
...
9
...

v The vi editor is most commonly used editor in the LINUX
...

è Command mode
è Insert mode
è Command line mode

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

58

7
...
1
...

v Alternative keys used for the cursor keys are h for left, j for down, k for up and
l for right
...

v ^b back one screen
...

v ^u up half screen
...

v $ end of the current file
...

v e end of the word
...
9
...
2 Inserting the Text :
v i insert text before the cursor
...

v I insert text at begging of the line
...

v o open new line after current line
...


7
...
1
...

v D deletes from cursor to the end of line
...


7
...
1
...
0
...
9
...
5 To see Multiple Files
vim –o file1 file2
We can see file1 and file2 at a time, shown below
...
3 vi –o command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

60

8
...
Functions like clear command
...
bg can be
used to find the background jobs
...

v [Ctrl] c or [ctrl] |: kill the process
...


v [Ctrl] k

: erase the line from the position of cursor

v [Ctrl] w : delete the word before the cursor
v [Esc] p

: find the last command that contains the letters you typed
...
If you want to use again no need to type the whole
command again instead yo u can type sed then press [Esc]p ,it will
display previous command
...


07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

61

9
...
1 Network Addresses:
v The IP address of a host consists of two parts, network address and host address
...

v The host address is unique and it is for the host only
...
168
...
150
Here the network address is 192
...
22 and the host address is 150
...
2 Network Commands:

Command: ifconfig
v ifconfig sets the IP address and the subnet mask of the interface
...

v Command:$ ifconfig

Fig
...
1ifconfig command

07/10/2009

Linux Tutorial 1
...
doc

LINUX TUTORIAL

62

Command: sftp
v To Transfer a file from one terminal to other through FTP
v Syntax :sftp
put
get < path_of_connected_terminal > < path_where_tobe_copied>
v Example
$ ls
and_gate
...
v Mem_ctr mux41
...
168
...
167
Connecting to 192
...
1
...

sftp> cd /hdd/backup
sftp> put fa
...
v to /home/Kacper/fa
...
xls /home/Kacper/
Uploading buglist
...
v fa
...
v SONET buglist
...
9
...
0
...

v Syntax: $ssh [-l login_name ] hostname
v Exampl: $ssh ip address
We can connect to that particular system

Command: netstat
v netstat are used to check the connectivity of the network
...
9
...
0
Title: Linux command
Description: here linux command notes for book