Вы находитесь на странице: 1из 12

To display the system date, month, time 1

[first23@cc1 ~]$ date


Wed Apr 20 18:03:19 IST 2011
[first23@cc1 ~]$ date +"%M"
03
[first23@cc1 ~]$ date +"%S"
52
[first23@cc1 ~]$ date +"%H"
18
[first23@cc1 ~]$ date +"%H -%M -%S"
18 -04 -29
[first23@cc1 ~]$ date +"%m"
04

To display the logged users in the unix system

[first23@cc1 ~]$ who


first23 pts/1 2011-04-20 17:42 (192.168.7.24)
first21 pts/2 2011-04-20 17:54 (192.168.7.16)
first19 pts/2 2011-04-20 17:57 (192.168.7.16)
first01 pts/2 2011-04-20 18:00 (192.168.7.16)
first07 pts/2 2011-04-20 18:02 (192.168.7.16)
first33 pts/2 2011-04-20 18:02 (192.168.7.16)
first17 pts/2 2011-04-20 18:03 (192.168.7.16)
first48 pts/2 2011-04-20 18:03 (192.168.7.16)

To display the logged user in the current system

first23 pts/1 2011-04-20 17:42 (192.168.7.24)

Display the same content typed in the command prompt

[first23@cc1 ~]$ echo god is love


god is love

To display the calendar with year and month

[first23@cc1 ~]$ cal


April 2011
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
[first23@cc1 ~]$ cal 2010
2010

January February March


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3 4 5 6
3 4 5 6 7 8 9 7 8 9 10 11 12 13 7 8 9 10 11 12 13
10 11 12 13 14 15 16 14 15 16 17 18 19 20 14 15 16 17 18 19 20
17 18 19 20 21 22 23 21 22 23 24 25 26 27 21 22 23 24 25 26 27
24 25 26 27 28 29 30 28 28 29 30 31
31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 1 2 3 4 5
4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12
11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19
18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26
25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30
30 31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4
4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11
11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18
18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25
25 26 27 28 29 30 31 29 30 31 26 27 28 29 30

October November December


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3 4
3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11
10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18
17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25
24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31
31

To do binary calculation

[first23@cc1 ~]$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
2+6
8
5*5
25
64 /8
8
1245 * 6
7470
Ctrl + D to exit

To display the manual for various commands

[first23@cc1 ~]$ man cal

CAL(1) BSD General Commands Manual CAL(1)

NAME
cal - displays a calendar

SYNOPSIS
cal [-smjy13] [[month] year]

DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the cur-
rent month is displayed. The options are as follows:

-1 Display single month output. (This is the default.)

-3 Display prev/current/next month output.

-s Display Sunday as the first day of the week. (This is the


default.)

-m Display Monday as the first day of the week.

-j Display Julian dates (days one-based, numbered from January 1).

-y Display a calendar for the current year.

To display the history of commands typed

1022 date
1023 date +"%M"
1024 date +"%S"
1025 date +"%H"
1026 date +"%H -%M -%S"
1027 date +"%m"
1028 who
1029 echo god is love
1030 cal
1031 cal 2010
1032 $bc
1033 bc 1.06
1034 $ bc
1035 $bc
1036 man bc
1037 clear
1038 bc
1039 man cal

To clear the screen

[first23@cc1 ~]$ clear


To display the present working directory 2

[first23@cc1 ~]$ pwd


/home/firstyear/first23

To create a new directory

[first23@cc1 ~]$ mkdir unix


[first23@cc1 ~]$

To list the files and directories with option

[first23@cc1 ~]$ ls
durga15.c factorial.sh k3.c m.k.sh unix
[first23@cc1 ~]$ ls –l
-rw-r--r-- 1 first23 users 0 Apr 9 20:25 durga15.sh
-rw-r--r-- 1 first23 users 213 Mar 14 17:16 factorial.sh
-rw-r--r-- 1 first23 users 54 Apr 7 16:35 m.k.sh
drwxr-xr-x 2 first23 users 4096 Apr 20 20:05 unix
[first23@cc1 ~]$

To remove a directory

[first23@cc1 ~]$ rmdir unix


[first23@cc1 ~]$ ls
durga15.c factorial.sh k3.c m.k.sh
[first23@cc1 ~]$

To create a new file

[first23@cc1 ~]$ cat >fruit.txt


apple
mango
pineapple[first23@cc1 ~]$ cat >fruit1.txt
goa
orange
grapes[first23@cc1 ~]$

To remove a file

[first23@cc1 ~]$ rm fruit.txt


[first23@cc1 ~]$ ls
durga15.c factorial.sh k3.c m.k.sh fruit1.txt
[first23@cc1 ~]$

Concatinating two files to the third files


[first23@cc1 ~]$ cat fruit.txt fruit1.txt >> fruits.txt
[first23@cc1 ~]$ cat fruits.txt
apple
mango
pineapple
goa
orange
grapes[first23@cc1 ~]$

Sorting the contents of the file

[first23@cc1 ~]$ sort fruits.txt


Apple
goa
grapes
mango
orange
pineapple
[first23@cc1 ~]$

Sorting in descending order

[first23@cc1 ~]$ sort -r fruits.txt


pineapple
orange
mango
grapes
goa
apple
[first23@cc1 ~]$

Copying one file to the another:

[first23@cc1 ~]$ cat > games1.txt


wrestling
rugby
chess
[first23@cc1 ~]$ cp games1.txt games2.txt
[first23@cc1 ~]$ cat games2.txt
wrestling
rugby[first23@cc1 ~]$

Moving or renaming one file to the another

[first23@cc1 ~]$ mv games2.txt games3.txt


[first23@cc1 ~]$ cat games3.txt
wrestling
rugby
chess
[first23@cc1 ~]$ cat games2.txt
cat: games2.txt: No such file or directory
[first23@cc1 ~]$

Counting the number of words, characters, and lines in a file

[first23@cc1 ~]$ wc games3.txt


3 3 22 games3.txt
[first23@cc1 ~]$ wc -l games3.txt
3 games3.txt
[first23@cc1 ~]$ wc -c games3.txt
22 games3.txt
[first23@cc1 ~]$ wc -w games3.txt
3 games3.txt
[first23@cc1 ~]$

Changing the read, write, execute permissions to the files

[first23@cc1 ~]$ ls -l games3.txt


-rw-r--r-- 1 first23 users 22 Apr 20 20:34 games3.txt
[first23@cc1 ~]$ chmod 777 games3.txt
[first23@cc1 ~]$ ls -l games3.txt
-rwxrwxrwx 1 first23 users 22 Apr 20 20:34 games3.txt
[first23@cc1 ~]$ chmod 744 games3.txt
[first23@cc1 ~]$ ls -l games3.txt
-rwxr--r-- 1 first23 users 22 Apr 20 20:34 games3.txt
[first23@cc1 ~]$
Usage of pipe command 3

[first23@cc1 ~]$ who am i


first23 pts/19 2011-04-20 20:18 (192.168.7.24)
[first23@cc1 ~]$ who am i | wc -c
54
[first23@cc1 ~]$ who am i | wc
1 5 54
[first23@cc1 ~]$ who am i | wc -l >> new
[first23@cc1 ~]$ cat new
1
[first23@cc1 ~]$

Usage of tee command with pipes

[first23@cc1 ~]$ date | tee time.txt


Wed Apr 20 21:03:57 IST 2011
[first23@cc1 ~]$ cat time.txt
Wed Apr 20 21:03:57 IST 2011
[first23@cc1 ~]$

Filter commands (head and tail)

[first23@cc1 ~]$ cat> year


january
february
march
april
may
june
july
august
september
october
novermber
december
[first23@cc1 ~]$ head -7 year
january
february
march
april
may
june
july
[first23@cc1 ~]$ tail -7 year
june
july
august
september
october
november
December

Cut command

[username@linux]$ cat> year


january
february
march
april
may
june
july
august
september
october
novermber
december
[first23@cc1 ~]$ cut -c1 year
j
f
m
a
m
j
j
a
s
o
n
d

Paste Command

[first23@cc1 ~]$ cat> dept


it
cse
ece
[first23@cc1 ~]$ cat> dept1
mech
eee
[first23@cc1 ~]$ paste dept dept1
cse
it
mech
ece
eee

uniq command
[first23@cc1 ~]$ cat name
ramesh
rajesh
dinesh
suresh
suresh
harish
[first23@cc1 ~]$ uniq name
ramesh
rajesh
dinesh
suresh
harish
[first23@cc1 ~]$ uniq -d name
suresh
[first23@cc1 ~]$ uniq -D name
suresh
suresh
[first23@cc1 ~]$

tr command

[first23@cc1 ~]$ cat name | tr [a-z] [A-Z]


RAMESH
RAJESH
DINESH
SURESH
SURESH
HARISH
[first23@cc1 ~]$
Using vi editor and grep, sed, awk commands

Create text file in vi editor

This is the second semester computer lab


In this lab we are learning about unix operating system
Unix is a multiuser and multitasking operating system
Unix is the secured operating system
The visual editor is used to edit the program
visual editor is the standard editor in unix
~
:wq
"unix" [New] 7L, 280C written
[first23@cc1 ~]$

Grep filter

[first23@cc1 ~]$ grep multiuser unix


Unix is a multiuser and multitasking operating system
[first23@cc1 ~]$ grep multiuser -n unix
3:Unix is a multiuser and multitasking operating system
[first23@cc1 ~]$ grep -n ope unix
2:In this lab we are learning about unix operating system
3:Unix is a multiuser and multitasking operating system
4:Unix is the secured operating system

Sed filter

[first23@cc1 ~]$ vi basket.txt


reds
pines
~
"basket.txt" [New] 3L, 14C written
[first23@cc1 ~]$

[first23@cc1 ~]$ cat basket.txt | sed -e "s/s/apple/"


redapple
pineapple

awk filter

[first23@cc1 ~]$ vi integers.txt


x = 10;
y = 47;
z = 86;
c = a+b+c;
~
"integers" [New] 5L, 36C written
[first23@cc1 ~]$
[first23@cc1 ~]$ cat integers | awk -F= '{print $1}'
x
y
z
c
[first23@cc1 ~]$ cat integers | awk -F= '{print "int :" $2}'
int : 10;
int : 47;
int : 86;
int : a+b+c;
int :
[first23@cc1 ~]$

Вам также может понравиться