Sunteți pe pagina 1din 29

UNIX COMMANDS

Simple UNIX Commands

File Related Commands

Directory related Commands


Simple UNIX Commands

logname prints the login name of the user


who details of the all the user currently logged in
who am i identifies the user
date tells the current date and time
cal displays current month calendar
uname finds the name of UNIX system
bc best calculator is invoked. To exit type ‘quit’
expr allows expressions to be evaluated in command
prompt
tty prints the name of the terminal
factor finds the factors of a number
Simple UNIX Commands

$ logname
cs2k4b01

$ who

cs2k4b01 tty1 Jan 16 10:02


cs2k4b01 tty2 Jan 16 10:05

$ who am i
cs2k4b01 tty1 Jan 16 10:02
Simple UNIX Commands

$ date
Mon Jan 2 10:15:09 IST 2007

$ uname
Linux

$ expr 3 \* 2
6
Simple UNIX Commands

$ tty
/dev/tty1

$ factor 15
15: 3 5
28
28: 2 2 7
$ banner Operating Systems Lab
Operating
Systems
Lab

$ banner “Operating Systems Lab”


Operating
Simple UNIX Commands

$ cal
January 2006
Su Mo Tu We Th Fr Sa
1234567
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

$ cal 4 2004
April 2004
Su Mo Tu We Th Fr Sa
123
4 5 6 7 8 9 10
11 12 13 1415 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
Simple UNIX Commands

$ 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+2
4
sqrt(196)
14
s(3.14)
Runtime error (func=(main), adr=8): Function s not defined.
quit
Simple UNIX Commands

$ bc -l

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’.
scale = 2
s(3.14)
0
quit
File Related Commands

cat creates a file


ls lists current directory
head displays first ten lines of the file
tail displays last ten lines of the file
cp copies the contents of the file
rm removes file
file * prints the type of each file in the current directory
touch creates multiple files
wc counts the number of words, lines and characters
chmod allows to modify permission
sort sorts the datas
uniq eliminates duplicate values
ln link created
File Related Commands
$ touch f1

$ touch f2 f3 f4 f5

$ cat >f6
this is file 6

$ cat f6
this is file 6

$ cat >f7
this is file 7
File Related Commands

$ cat f6 f7>f8

$ cat f8
this is file 6
this is file 7

$ cat > f9
this is file 9

$ cat f6 f7>>f9
this is file 9
this is file 6
this is file 7
File Related Commands

$ head -2 f9
this is file 9
this is file 6
$ tail -2 f9
this is file 6
this is file 7
vi file1.a
this is file1.a

cp file1.a file2.a

cat file2.a
this is file1.a

cat>f10
this is file 10
File Related Commands

$ cat >.f11
this is file 11
$ ls
f1 …….. f10
file1.a file2.a
$ ls f1?
f10

$ ls -a
f1 …….. f11

$ ls f1*
f10 f1
File Related Commands
$ rm f9

$ ls f1 …….. f8

chmod [who] [+/-/=] [permission] filename


$ chmod 777 f8
$ chmod 444 f8 (OR) $ chmod ugo-wx f8

$ rm f8
rm: remove write-protected regular file ‘f8’? n

$ rm f8 -f
$ ls f1 …….. f7
File Related Commands

$ rm f7 -i
rm: remove regular file ‘f7’? y

$ ls f1 …….. f6

$ mv f2 f3

$ cat f3
this is file 2

$ ls
f1 f3 …….. f7
File Related Commands

$ file *
f1: ASCII text
.
.

$ wc –lc f1
1 15 f1

$ cat >>f3

$ ls
f1 f3 …….. f7
File Related Commands

$ ls
-l long listing
-s display with file sizes
-i displays with the inode number

ln f1 f15
total 22
ls -l -rwxrwxr-- 2 cs2k5a01 cs2k5a 4 2 Jan 07 10:15 f1
-rw-rw-r-- 1 cs2k5a01 cs2k5a 5 2 Jan 07 10:16 f5
-rwxrwxr-- 2 cs2k5a01 cs2k5a 4 2 Jan 07 10:15 f15
$ cat > s1
def
abc
File Related Commands

$ sort s1
abc
def
$ sort s1 s3

$ sort
–r reverse order
-u unique output
-o filename sorted output to a file
-f ignoring case
-n sort numbers
-m merge
- keyboard input with a file
File Related Commands

$ cat > s2
4 abc 50 51 52
3 ghi 60 61 62
2 def 70 71 72
1 wef 80 81 82
abc 51
$ cut –f 2,4 s2 ghi 61
def 71
wef 81

abc 50 51
$ cut –f 2-4 s2 ghi 60 61
def 70 71
wef 80 81
File Related Commands

$ cat > s2
4:abc:50:51:52
3:ghi:60:61:62
abc 51
2:def:70:71:72
ghi 61
1:wef:80:81:82 def 71
$ cut –f 2,4 –d”:” s2 wef 81

abc
ghi
$ cut –c 2-4 –d”:” s2 def
wef

$ sort –r +1 -2 s2 wef
ghi
def
abc
File Related Commands

$ grep a* s2
1 abc 16

$ grep [D-G]?f -i -n s2
3:2 def 24

$ grep ‘^[def]’ s2 $ grep ‘[def]$’ s2

$ uniq f3
-d remove duplicate data
-u display unique data
-c count number of times the word is present
in the file
Directory Related Commands

pwd prints present working directory


mkdir creates a directory
cd changing over to new directory
cd .. brings you back to home directory
rm removes all contents of directory
mv renames the directory name
ls long listing of directory
Directory Related Commands

$ pwd
/home/cs2k4b/cs2k4b01

$ mkdir d1

$ cd d1

$ cd ..

$ mv d1 d2
COMMANDS TO EXECUTED

1. Command to print the login name of the use


2. To display the Users
3. To display the present user alone
4. Print the current date
5. Print the present working directory
6. Print the calendar
7. Print the calendar for October 2003
8. Print the name of the UNIX system
9. Create a file
10. Print the terminal name
11. Create multiple files
12. List all the files and directories in the current directory
COMMANDS TO EXECUTED

13. To create a file fn in write mode


14. To display the contents of the file fn
15. Copy the contents of two files into a third file
16. Append the contents of two file into a third file
17. Display the first n lines of a filename fn
18. Display the last n lines of a filename fn
19. Create a file in vi editor mode
20. Copy the contents of one file into another
21. Create a directory
22. Copy files into the directory
23. To change directory
24. To move to the parent directory
COMMANDS TO EXECUTED

 25. Copy a file from one directory to another


26. Remove a file
27. Remove with confirmation
28. Remove without confirmation (forcibly)
29. Move contents from one file to another file
30. To create a hidden file
31. To view the hidden file
32. To view all the files starting with the given letter
33. To view all the files starting with either of the given letters (aeiou)
34. To view all the files starting with the letters other than (aeiou)
35. Long listing
36. To list file types
COMMANDS TO EXECUTED

 37. To list the files with sizes in the particular directory


38. Give all rights for the user, for group give only write and execute
permission
39. Give only execute permission for others (both methods)
40. To list file with inode number
41. Calculator
42. Calculator with trignometric library
43. Evaluating expression
44. Factor of a number
45. Word count (lines, words & characters)
46. Sort a file fn
47. Sort a file in reverse
48. Display unique output of a file
COMMANDS TO EXECUTED

 49. To append contents to a file


50. Sort ignoring case
51. Sort numbers
52. Sort the contents of two files and store it in another file
53. Sort and merge two files
54. Sort the standard input
55. Sort the standard input with the file content
56. Rename a directory
57. Move files in a directory
58. Display the selected fields in the file
59. Search for the given pattern and print it
60. Search for the pattern ignoring case and starting with either of [a-f]
in the file and print it
COMMANDS TO EXECUTED

 61. Search for the pattern ending with either of [s-z] in the file and
print it along with the line numbers
62. Ignore duplicate data and print it
63. Print the unique data
64. Count the number of times the particular data is present in the
file
65. Create link between the two files (long list after link creation)

S-ar putea să vă placă și