Professional Documents
Culture Documents
Linux Commands
Linux Commands
Types of OS:
1. Single user OS
a. Single Tasking Ex: MS - DOS
b. Multi Tasking Ex: Ms Windows
95/98/me/xp/vista
2. Multi user OS Ex: Unix, Linux
3. Network OS Ex: Windows NT/2000/2003
Linux: linux is a multi user/multi tasking operating
system which is developed by linus trovalds, when he
was a university student. HE made source code available
in internet so that every body can access it with out any
cost.
Features:
Multi User Capability
Multi Tasking
Security
User level
File level
Encryption / decryption
Virus Free
Communication
Scheduling tasks
Terminals:
Dump Terminals
Intelligent Terminals
Dial-Up Terminals
Linux Kernel:
appworld
^d
2. cat >> filename
^d
3. cat filename(s)
rose lilly jasmine
Root
cd: to change directory
Syn: cd <dir name>
Ex: cd max
Pwd
/home/satish/max
cd .. takes back to parent directory
cd to come back to default directory.
cp: 1. to copy files Syn: cp file1 file2
2. to copy files to directory Syn: cp file1 file2 file3
file4 directory.
mv:
1. To rename a file/directory
Ex: mv
oldname newmame
2. To move files into a directory Syn: mv file1
file2 file3 file4 directory.
rm: To remove files.
DAY 3:
VI Editor:
To modify file contents and also used to create files.
Syn: vi <filename>
esc : Comes out of insert mode
:w save the file
:q quit
:wq save and quit
:q! Force quit
There are two types of commands:
r--
rwx (4+2+1)
rwr-x
r--wx
-w--x
---
date
who
cal 09 1977
^d
$ Chmod u+x prg
$ ./prg
Umask: displays umask value or sets umask value. A
umask value represents default permissions to a
directory.
$umask
0002
Default permissions of a dir is total
permissions minus umask value. Ie. 777-002 = 775
$umask 077
Default permissions of new dir is total
permissions minus umask value. Ie. 777077 = 700
$ mkdir bond drwx------
FILTER COMMANDS:
head: To displays specified no. of lines from top of
the file.
Syn: head n filename
Ex: head -5 hello displays first 5 lines from
the file hello
Tail: To display specified no. of last lines.
Syn: tail -/+n filename
manager
clerk
typist
CLERK
TYPIST
peon
8000
5000
4000
5500
3500
950
typist
CLERK
clerk
manager
TYPIST
peon
4000
5500
5000
8000
3500
950
Options:
-r: to sort data in reverse order
-km[,n]: Here m & n are numbers. Used to
sort data on specified column.
m to specify filed on which we
want to sort data.
Ex: sort -k3 emp
n: In sorting, if there is equal data in
two rows, it compares the next field
and so on.To specify where sorting
should be stopped we use -n option.
Ex: sort -k3,4 emp
-f : to ignore case wile sorting.
Sort f emp
Sort k3
f r emp
Sort k3 f emp
-n: to sort numbers
Sort k4 n emp
-t: to specify field seperator if other than
TAB is used.
sort k3 t ; emp
grep: [Globel Regular Expression Printer] To search
for specified text and display lines containing the
text.
Syn: grep [-options] text filename
Ex: grep clerk emp
Options:
-v: Displays lines those do not contain
specified text.
-i: TO ignore case
-c: Displays count of lines
-n: Displays lines along wioth line
numbers
cut c1
cur c1,4
Ex:
find ~/m*
Options:
-mtime n: searches for the files which are last
modified before n*24 hours.
Ex: Display files older than 7 days.
find ~/* -mtime 7
-type: to specify what you want to serach. Ex.
To search files we use f to serach dirs we use
d
Ex: find ~/* -type f
-exec: Used to execute a command based on
the search result.
Ex: find max/* -type f exec rm { } \;
-user: To search files which are owned by a
user. Ie. To search for files which are created
by specified user.
Ex: find ~/* -user root
Sed: 1. To replace a text with another text in a file
2. To delete lines containing specified text
Syn 1: sed s/text/rtext/g <filename>
Ex: sed s/madhu/kumar/g emp
Syn 2:
sed /text/d <filename>
Ex: sed /typist/d emp
awk: pattern scanning and processing language
Syn: awk {commands} filename
Ex:
awk { print $1} emp gets first filed in file
emp and displays them with print command.
awk { print $2 + $4 } emp
awk '{ print "Employee name " $1 }' emp
awk -F: { print $2 + $4 } emp2 [useinf -F we
can specifiy field seperator]
^d
Execute the above scrip as follows:
$ sh prog &
Communication Commands
write:
To write a message on another user
terminal.
Syn: write <username> <terminal>
Ex: write hyma
Message(s)
^d
Write satish pts/4
Message(s)
^d
Mesg: To enab;e/disable/view message status
$ mesg
is y
$mesg n To disable messages
$mesg y To enable messages.
who T: Displays list of user along with
message status. Message status will be either
+ or -. If it is +, mean user have messages
enabled.
mail: To send or view mails.
Syn to Send mail:
$ mail <username>
Sub:
.
Cc:
^d
Syn: To view
$ mail
Scheduling Commands:
at: Used to execute a command/shell script in future
time.
Syn:$ at hh:mm
at> command
at> ^d
Ex: at 17:45
at>cp hello hi
at> ^d
atq: Displays list of jobs pending
atrm: to remove jobs. Ex: atrm 2 here 2 is job id
batch: to execute a batch of commands at system free
times. Executes commands if system load average is
less than 0.8.
Syn:batch
at> command
^d
Ex: batch
cp hello king
^d
crontab: Executes command/shell script at regular
intervals of time.
Syn:
Crontab
Min hours day month weekday
command
^d
Ex:
Crontab
28 12 27 7 * cp
/home/madhu/max/hello /home.madhu/max/hi
^d
Every year on 27th july at 12:28
executes the cp command
Example patterns:
30 10 1 * * command
30 * * * * command
crontab -l: to view list of cron jobs
crontab -e: To edit/add/remove jobs
crontab r: to remove all jobs