Thursday, March 20, 2014

Assignment 3: Questinos & Answer upto 122 ( Operating System )

1.
--> cal

2.
--> date -A4

3.
--> date -B2

4.
--> date

5.
--> date "+%d-%B-%y"

6.
--> echo -e "Mer Maitri"
    printf "Mer Maitri\n"


7.
--> a=50

8.
--> printf "Value of A:%d\n" $a
    echo -e "Value of A:" $a

9.
--> printf "Value of A in octal %o" $a
    printf "Value of A in hexadecimal %x" $a

10.
--> script testfile
    cal
    date
    exit                                  

11.
--> mkdir tempdir

12.
--> mkdir rootdir rootdir/dir1 rootdir/dir2

13.
--> cp testfile rootdir rootdir/dir1 rootdir/dir2

14.
--> cat > file1

15.
--> cp file1 rootdir/dir1 rootdir/dir2

16.
--> pwd
    $HOME

17.
--> ls

18.
--> ls -a

19.
--> ls -R rootdir

20.
--> cp rootdir duplicatedir

21.
--> mv testfile filetest

22.
--> wc filetest

23.
--> rm filetest

24.
rm -R duplicatedir

25.
cat > friendlist1

26.
cat >friendlist2

27.
cat dupfriend

28.
cmp friendlist[1,2]

29.
cmp friendlist1 dupfriend

30.
comm friendlist[1,2]

31.
comm -12 friendlist[1,2]

32.
diff friendlist[1,2]

33.
passwd

34.
sudo add.user testuser

35.
sudo add.user testuser

36.


37.
who

38.
ls /bin

39.Remove all files & directories created so far from the home directory.
rm dup* *list* file1
rm -R *dir

Assignmnet-2
1.Create a new file 'file1' and check its default permission.
cat > file1
ls -l file1

2.Create a new directory dir1 and check its default permissions.
mkdir dir1
ls -ld dir1

3.Create directories rootdir,rootdir/dir1,rootdir/dir2 with a single command
mkdir rootdir rootdir/dir1 rootdir/dir2

4.Create two more files newfile and testfile using either script or cat command
cat > newfile
cat> testfile

5.Copy file1 in rootdir
cp file1 rootdir

6.Copy both the files newfile and testfile in root/dir1 and rootdir/dir2 respectivly
cp newfile rootdir/dir1
cp testfile rootdir/dir2

7.Compress the file1 using gzip command
gzip file1

8.Check the contents of home directory
ls

9.Uncompress the file file1 using gzip command
gzip -d file1.gz

10.Compress multiple files newfile and testfile using a single command
gzip newfile testfile rootdir/dir1/newfile rootdir/dir2/testfile

11.Uncompress files newfile and testfile using gunzip
gunzip newfile testfile rootdir/dir1/newfile rootdir/dir2/testfile

12.Compress all files of rootdir usinf gzip
gzip -r rootdir

13.Check the entire tree structure of rootdir using ls
ls -R rootdir

14.Uncompress all files of rootdir
gunzip -r rootdir

15.Display the contents of file file1
cat file1

16.Make some modifications to the contents of file ‘file1’.
cat >> file1

17.Remove the read permission from ‘file1’ for category user and try to list the contents of ‘file1’.
chmod u-r file1
cat file1

18.Once again assign read permission to ‘file1’ for category user.
chmod u+r file1

19.Remove the write permission from ‘file1’ for category user and try to modify the contents of ‘file1’.
chmod u-w file1
cat >> file1

20.Once again assign write permission to ‘file1’ for category user.
chmod u+w file1

21.Remove the execute permission from ‘RootDir’ for category user.
chmod u-x rootdir
Then attempt:
-    Checking the contents of ‘RootDir’.
-    Creating a file within ‘RootDir’.
-    Modifying the contents of file within ‘RootDir’.

22.Once again assign execute permission to ‘RootDir’ for category user.
chmod u+x rootdir

23.Remove the write permission from ‘RootDir’ for category user.
chmod u-w rootdir
Then attempt:
-    Checking the contents of ‘RootDir’.
-    Creating a file within ‘RootDir’.
-    Modifying the contents of file within ‘RootDir’.
24.Once again assign write permission to ‘RootDir’ for category user.
chmod u+w rootdir

25.Remove the read permission from ‘RootDir’ for category user.
chmod u-r rootdir
Then attempt:
-    Checking the contents of ‘RootDir’.
-    Creating a file within ‘RootDir’.
-    Modifying the contents of file within ‘RootDir’.
26.Once again assign read permission to ‘RootDir’ for category user.
chmod u+r rootdir

27.Compress the file ‘file1’ using tar.  Check the contents of home directory. (additional tar file will be there).
tar -cvf file1.tar file1
ls

28.Remove the file ‘file1’.
rm file1

29.Uncompress the file ‘file1’ using tar. Check the contents of home directory as well as ‘file1’.
tar -xvf file1.tar
ls
cat file1

30.Compress all files of ‘RootDir’ using tar. Check the contents of home directory.
tar -cvf rootdir.tar rootdir

31.Remove the entire original directory structure of ‘RootDir’.
rm -R rootdir

32.Check all the files and subdirectories that are compressed in ‘RootDir.tar’ using tar.
tar -tvf rootdir.tar

33.Uncompress the contents of ‘RootDir’ using tar.
tar -xvf rootdir.tar

34.Create multiple files – ‘file2’, ‘file3’, ‘file5’ and ‘file6’ with different contents in the home directory.
cat > file2
cat > file3
cat >file5
cat > file6

35.List all files having names starting with characters ‘file’.
ls file*

36.List all files having names ending with characters ‘file’.
ls *file

37.List all files having names starting with characters ‘file’ and the last character ‘1’ or ‘2’.
ls file[1-2]

38.List all files having names starting with characters ‘file’ and the last character must not be ‘1’ or ‘2’.
ls file[!1-2]

39.List all files having names starting with characters ‘file’ and the last character in the range of ‘1’ to ‘5’.
ls file[1-5]

40.Write some arithmetic expressions in file ‘file1’. (after removing original contents)
cat>>file1
2+5
2^3

41.Make use of file ‘file1’ as input for bc command.
bc < file1

42.Store the output of bc command using ‘file1’ to ‘file2’.
bc < file1 > file2

43.Transfer the output of ‘ls’ command to file ‘file3'
ls > file3

Assignment-3

44.Transfer the output of ‘ls –l’ command to the file ‘file4’, and display the output on terminal as well.
ls -l | tee file4

45.Create a file ‘numfile’ with numbers from 1 to 20. (Each number on separate line)
cat > numfile

46.Create a file ‘employee’ with ‘|’ as a separator for each field on each record.  (The file exists as a notepad file in this directory.)
ls -d"|" emp

47.Prepare the file ‘employee’ for printing.
pr employee

48.Prepare the file ‘employee’ for printing without any header and footer.
pr -t employee

49.Prepare the file ‘employee’ for printing including line numbers to the left.
pr -t -n employee

50.Prepare the file ‘employee’ for printing with one blank line in between two records.
pr -t -d employee

51.Prepare the file ‘employee’ for printing with 8 blank spaces on the left of each line.
pr -t -o8 employee

52.Prepare the file ‘numfile’ for printing without any header and footer.
pr -t numfile

53.Prepare the file ‘numfile’ for printing so that there are 4 columns on each line.
pr -t -4 numfile

54.Display the first 10 lines of ‘employee’.
pr -t employee | head -10

55.Display the first 4 lines of ‘employee’.
pr -t employee | head -4

56.Display the first 4 lines of ‘employee’ with line numbers to the left.
pr -t -n employee | head -4

57.Display the first 3 lines of ‘employee’ with one blank line in between two records.
pr -t -d employee | head -3

58.Display the last 10 lines of ‘employee’.
pr -t employee | tail -10

59.Display the last 3 lines of ‘employee’ on terminal and save the same output in file ‘file5’.
pr -t empolyee | tail -3 |tee file5

60.Display the last 3 lines of ‘employee’ with 10 spaces on the left of each line/record.
pr -t -o10 employee | tail -3

61.Display 5th to 10th record of file ‘employee’.
pr -t employee | tail -10 |head -6

62.Display 7th to 12th record of file ‘employee’ on terminal and save the same output in file ‘emp’.
pr -t employee |tail -8 |head -6 | tee emp

63.Add the first 6 records to the ‘emp’ file.
pr -t employee | head 6 | tee emp

64.Display the character on 2nd column of each line of ‘employee’.
cut -d"|" -f 2 employee

65.Display the characters on 2nd, 5th and 12th column of each line of ‘employee’ ensuring that only the first 4 records are included on the terminal.
cut -d"|" -f 2,5,12 employee | head -4

66.Display the 6th to 10th characters of each line of ‘employee’ on the terminal.
cut -c 6-10 employee

67.Display the 6th to 10th, as well as 18th to 25th characters of each line of ‘employee’ on the terminal and save the same output in file ‘file6’.
cut -c 6-10 18-25 employee| tee file6

68.Include the last 5 lines of the 6th to 10th, as well as 18th to 25th characters from file ‘employee’ in a new file ‘file7’.  (Output must not be displayed on the terminal.)
cut -c 6-10 18-25 employee |tail 5| tee file6

69.Display the first three fields of ‘employee’ on the terminal.
cut -d"|" -f 1-3 employee

70.Display the 1st, 3rd, 5th and 6th fields of ‘employee on terminal and save the same output in file ‘emp1’.
cut -d"|" -f 1,3,5,6 employee | tee emp1

71.Transfer the fields 1, 2 and 3 of ‘employee’ to file ‘emp1’. (Overwrite the file.)
cut -d"|" -f 1,3,5 employee | tee emp1

72.Transfer the fields 4, 5 and 6 of ‘employee’ to file ‘emp2’.
cut -d"|" -f 4,5,6 employee | tee emp2

73.Include first five lines of the first three fields of ‘employee’ to be displayed on the terminal.
cut -d"|" -f 1-3 | tail -5 employee

74.Display the first four fields of ‘employee’ on the terminal.  Include line / record numbers on the left.
pr -t -n employee | head -4 employee

75.Combine the contents of files ‘emp1’ and ‘emp2’ so that all six fields are included on each record.
paste emp1 emp2

76.Include a separator character “|” while combining the contents of files ‘emp1’ and ‘emp2’ so that all six fields are included on each record.
paste -d "|" emp1 emp2

77.Combine the contents of three lines on a single line in ‘numfile’ and display it on the terminal.  Use ‘*’ as a separator character.
head -3 numfile | paste -s -d "*"

78.Arrange the records of ‘employee’ file in ascending order of 2nd field (name).
sort -t"|" -k2 employee

79.Arrange the records of ‘employee’ file in ascending order of 6th field (salary).
sort -t"|" -n -k6 employee

80.Display only the contents of 2nd field (from employee file) in ascending order.
cut -d"|" -f2 employee | sort -t"|"

81.Display only the unique values from the above result.
cut -d"|" -f2 employee | sort -t"|" -u

82.Arrange the contents of ‘numfile’ in descending order and display it on the terminal.
sort -n -r -u numfile

83.Display the contents of ‘employee’ sorted first on job and then on department number field in ascending order.
sort -t"|" -k8 employee | sort -t"|" -k3

84.Transfer the contents of 3rd field job from employee file to a new file named ‘job’.  Ensure that the contents are also displayed on the terminal.
cut -d"|" -f3 employee | tee job

85.Transfer the contents of 6th field salary from employee file to a new file named ‘salary’.Ensure that the contents are also displayed on the terminal.
cut -d"|" -f6 employee | tee salary

86.Sort the contents of ‘job’ in ascending order.
sort job

87.Sort the contents of ‘salary’ in descending order.
sort -n -r salary

88.Display the contents of ‘job’ file in ascending order with numbering on the left.
sort job | pr -t -n

89.Display the contents of ‘job’ file in descending order with numbering on the left and three job values on a single line.
sort job | pr -t -n -3

90.Create a file ‘names1’ that contains names of first 7 employees in ascending order.
sort -t"|" -k2 employee | head -7  | tee names1

91.Create a file ‘names2’ that contains names of last 5 employees in ascending order.
sort -t"|" -k2 employee | tail -5  | tee names2

92.Display the contents of files ‘names1’ and ‘names2’ so that all names appear in ascending order.
sort -m names1 names2

93.Display only the duplicate values from ‘job’ file.
uniq -d job

94.Display only the unique values from ‘job’ file.
sort job | uniq -u

95.Display the number of times each value is present in ‘job’ file.
uniq -c job

96.Through a single command replace characters ‘ABC’ with ‘123’ respectively in ‘employee’ file.  Ensure that only last three lines are displayed on the terminal.
tr "ABC" "123" < employee | tail -3

97.Convert the case of all characters in ‘employee’ file from upper to lower.
tr '[A-Z]' '[a-z]' < employee

98.Remove all ‘7’ and ‘0’ from ‘employee’ file.
tr -d '70' < employee

99.Remove all tabs from ‘employee’ file.
tr -d '\t' < employee

100.Compress all trailing zeros in ‘employee’ file.
tr -s "0" < employee

101.Replace all ‘0’ and ‘1’ with ‘*’ and ‘#’ in ‘employee’ file.
tr "01" "*#" < employee

102.Replace all ‘A’ and ‘B’ with ‘0’ and ‘1’ in ‘employee’ file.
tr "AB" "01" <employee

103.Create a file ‘emphardlink’ which is a hard link to ‘employee’ file in the current directory.
ln employee emphardlink

104.Check the inode number and number of links for the files – ‘employee’ and ‘emphardlink’.
ls -i employee emphardlink
ls -li employee emphardlink

105.List the contents of file ‘emphardlink’.
cat emphardlink

106.Shift the file ‘emphardlink’ from current directory to ‘rootdir’.
mv emphardlink rootdir

107.Now once again list the contents of file ‘emphardlink’.
cat emphardlink

108.Create a file ‘empbackup’ that is a backup of file ‘employee’.
cat employee | tee empbackup

109.Delete the file ‘employee’.
rm employee

110.Check the inode number and number of links for the file ‘emphardlink’.
ls -li rootdir/emphardlink

111.Now once again list the contents of file ‘emphardlink’.
cat rootdir/emphardlink

112.Change the name of file ‘empbackup’ to ‘employee’.
mv empbackup employee

113.Create a file ‘empsoftlink’ which is a soft link to ‘employee’ file in the current directory.
ln -s employee empsoftlink

114.Check the inode number and number of links for the files – ‘employee’ and ‘empsoftlink’.
ls -i employee empsoftlink
ls -li employee empsoftlink

115.List the contents of file ‘empsoftlink’.
cat empsoftlink

116.Shift the file ‘empsoftlink’ from current directory to ‘rootdir’.
mv empsoftlink rootdir

117.Now once again list the contents of file ‘empsoftlink’.
cat rootdir/empsoftlink

118.Move back the file ‘empsoftlink’ from ‘rootdir’ to current directory.
mv rootdir/empsoftlink user1

119.Create a file ‘empbackup’ that is a backup of file ‘employee’.
cat employee | tee empbackup

120.Delete the file ‘employee’.
rm employee

121.Check the inode number and number of links for the file ‘empsoftlink’.
ls -li rootdir/empsoftlink

122.Now once again list the contents of file ‘empsoftlink’.
cat empsoftlink

No comments:

Post a Comment