29
UNIX COMMANDS Simple UNIX Commands File Related Commands Directory related Commands

Unix Commands

Embed Size (px)

Citation preview

Page 1: Unix Commands

UNIX COMMANDS

Simple UNIX Commands

File Related Commands

Directory related Commands

Page 2: Unix 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

Page 3: Unix Commands

Simple UNIX Commands

$ logname

$ who

$ who am i

cs2k4b01

cs2k4b01 tty1 Jan 16 10:02cs2k4b01 tty2 Jan 16 10:05

cs2k4b01 tty1 Jan 16 10:02

Page 4: Unix Commands

Simple UNIX Commands

$ date

$ uname

$ expr 3 \* 2

Mon Jan 2 10:15:09 IST 2007

Linux

6

Page 5: Unix Commands

Simple UNIX Commands

$ tty

$ factor

$ banner Operating Systems Lab

$ banner “Operating Systems Lab”

/dev/tty1

1515: 3 52828: 2 2 7

Operating Systems Lab

Operating

Page 6: Unix Commands

Simple UNIX Commands

$ cal

$ cal 4 2004

January 2006Su Mo Tu We Th Fr Sa1 2 3 4 5 6 78 9 10 11 12 13 1415 16 17 18 19 20 2122 23 24 25 26 27 28 29 30 31

April 2004Su Mo Tu We Th Fr Sa1 2 3 4 5 6 7 8 9 1011 12 13 1415 16 17 18 19 20 21 22 23 2425 26 27 28 29 30

Page 7: Unix Commands

Simple UNIX Commands

$ bc

bc 1.06Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type ‘warranty’.2+24sqrt(196)14s(3.14)Runtime error (func=(main), adr=8): Function s not defined.quit

Page 8: Unix Commands

Simple UNIX Commands

$ bc -l

bc 1.06Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.This is free software with ABSOLUTELY NO WARRANTY.For details type ‘warranty’.scale = 2s(3.14)0quit

Page 9: Unix Commands

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

Page 10: Unix Commands

$ touch f1

$ touch f2 f3 f4 f5

$ cat >f6

this is file 6

$ cat f6

$ cat >f7

this is file 7

this is file 6

File Related Commands

Page 11: Unix Commands

$ cat f6 f7>f8

$ cat f8

$ cat > f9

this is file 9

$ cat f6 f7>>f9

this is file 6 this is file 7

File Related Commands

this is file 9this is file 6 this is file 7

Page 12: Unix Commands

$ head -2 f9

$ tail -2 f9

vi file1.a

cp file1.a file2.a

cat file2.a

cat>f10

this is file 10

this is file 9 this is file 6

File Related Commands

this is file 6 this is file 7

this is file1.a

this is file1.a

Page 13: Unix Commands

$ cat >.f11

this is file 11

$ ls

$ ls f1?

$ ls -a

$ ls f1*

File Related Commands

f1 …….. f10 file1.a file2.a

f10

f1 …….. f11

f10 f1

Page 14: Unix Commands

$ rm f9

$ ls

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

File Related Commands

f1 …….. f8

f1 …….. f7

Page 15: Unix Commands

$ rm f7 -i

rm: remove regular file ‘f7’? y

$ ls

$ mv f2 f3

$ cat f3

$ ls

File Related Commands

f1 …….. f6

f1 f3 …….. f7

this is file 2

Page 16: Unix Commands

$ file *

$ wc –lc f1

$ cat >>f3

$ ls

File Related Commands

f1: ASCII text..

f1 f3 …….. f7

1 15 f1

Page 17: Unix Commands

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

ln f1 f15ls -l

$ cat > s1defabc

File Related Commands

total 22-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

Page 18: Unix Commands

$ sort s1

$ 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

abcdef

Page 19: Unix Commands

$ cat > s2

4 abc 50 51 52

3 ghi 60 61 62

2 def 70 71 72

1 wef 80 81 82

$ cut –f 2,4 s2

$ cut –f 2-4 s2

File Related Commands

abc 51ghi 61def 71wef 81

abc 50 51ghi 60 61def 70 71wef 80 81

Page 20: Unix Commands

$ cat > s2

4:abc:50:51:52

3:ghi:60:61:62

2:def:70:71:72

1:wef:80:81:82

$ cut –f 2,4 –d”:” s2

$ cut –c 2-4 –d”:” s2

$ sort –r +1 -2 s2

File Related Commands

wefghidefabc

abc 51ghi 61def 71wef 81

abcghidefwef

Page 21: Unix Commands

$ grep a* s2

$ grep [D-G]?f -i -n s2

$ 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

File Related Commands

1 abc 16

3 : 2 def 24

Page 22: Unix Commands

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

Page 23: Unix Commands

$ pwd

$ mkdir d1

$ cd d1

$ cd ..

$ mv d1 d2

/home/cs2k4b/cs2k4b01

Directory Related Commands

Page 24: Unix Commands

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

Page 25: Unix Commands

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

Page 26: Unix Commands

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

Page 27: Unix Commands

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

Page 28: Unix Commands

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

Page 29: Unix Commands

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)