Thursday, February 28, 2019

UNIX COMMAND

1. Find the current time and date.
[cs@localhost~]$ date
Thu Aug 23 09:54:15 EDT 2018
[cs@localhost ~]$
2. Create a blank file.
[cs@localhost ~]$ touch dip.txt
[cs@localhost ~]$
3. Create a file and write some sentences in the file.
[cs@localhost~]$ cat>find1.txt
today is thursday
i am a student
bhairabganguly college
[cs@localhost ~]$
4 . Display the content of the file find1.txt.
[cs@localhost~]$ cat find1.txt
today is thursday
i am a student
bhairabganguly college
[cs@localhost ~]$
5. Append some line in atext file.
[cs@localhost~]$ cat>>find1.txt
Tomorrow  isfriday
[cs@localhost ~]$
6. Create a directory.
[cs@localhost~]$mkdir dip
[cs@localhost ~]$
7. Display all files and directories under current date.
[cs@localhost~]$dir
13.sh  assignment100.sh~  Downloads rina
13.sh~  assignment1.sh     exam     source
1.sh  assignment1.sh~    f1     source.txt
1.sh~  assignment1.txt    f3.txt     source.txt~
2.sh  assignment1.txt~   file.sh     student.txt
2.sh~  assignment2.sh     file.sh~ sudip\ 246
3.sh  assignment2.sh~    find1.txt sudip\ 2461
3.sh~  assignment2.txt    Music suvo\ saha
4.sh  assignment2.txt~   Pictures     tanima.txt~
4.sh~  assignment3.sh~    Public     Templates
5934.sh  Desktop     purbasha.sh     unix.txt
5.sh  destination.txt    purbasha.sh~ unix.txt~
5.sh~  dip purbasha.sp     Untitled\ Document
a  dip.txt     question6.sh    Untitled\ Document~
aritra  dip.txt~     question6.txt   Untitled\ Document\ 2
assignment100.sh  Documents     question6.txt~  Videos
[cs@localhost ~]$
8. Display all files and directories under current date.
[cs@localhost~]$ ls
13.sh             assignment100.sh~ Downloadsrina
13.sh~            assignment1.sh exam            source
1.sh              assignment1.sh~ f1              source.txt
1.sh~             assignment1.txt f3.txt          source.txt~
2.sh              assignment1.txt~ file.sh         student.txt
2.sh~             assignment2.sh file.sh~        sudip 246
3.sh              assignment2.sh~ find1.txt       sudip 2461
3.sh~             assignment2.txt Music           suvosaha
4.sh              assignment2.txt~ Pictures        tanima.txt~
4.sh~             assignment3.sh~ Public          Templates
5934.sh           Desktop purbasha.sh     unix.txt
5.sh              destination.txt purbasha.sh~    unix.txt~
5.sh~             dip purbasha.sp     Untitled Document
a                 dip.txt question6.sh    Untitled Document~
aritra            dip.txt~ question6.txt   Untitled Document 2
assignment100.sh  Documents question6.txt~  Videos
[cs@localhost ~]$
9. Details of all processes which are currently executing.
[cs@localhost~]$ps
 PID TTY          TIME CMD
1317 pts/0    00:00:00 bash
16042 pts/0    00:00:00 ps
[cs@localhost~]$


Date: 28.08.2018
10. Count the total number of lines, words, characters of a file f3.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$wc f3.txt
3 10 59 f3.txt
[cs@localhost ~]$
11. Count the total number of lines, words, characters of file f3.txt and f4.txt.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$ cat>f4.txt
i am a student.
bhairabganguly college.
[cs@localhost~]$wc f3.txt f4.txt
3  10 59 f3.txt
 2  7 41 f4.txt
5  17 100 total
[cs@localhost ~]$
12. Count the total number of characters of a file f3.
[cs@localhost~]$wc -c f3.txt
59 f3.txt
[cs@localhost ~]$
13. Count the total number of characters of file f3.txt f4.txt.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$ cat>f4.txt
i am a student.
bhairabganguly college.
[cs@localhost~]$wc -c f3.txt f4.txt
59 f3.txt
41 f4.txt
100 total
[cs@localhost ~]$
14. Count the total number of words of a file f3.txt.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$wc -w f3.txt
10 f3.txt
[cs@localhost ~]$
15. Count the total no of words of file f3.txt f4.txt.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$ cat>f4.txt
i am a student.
bhairabganguly college.
[cs@localhost~]$wc -w f3.txt f4.txt
10 f3.txt
 7 f4.txt
17 total
[cs@localhost ~]$
16. Count the total number of lines of a file f3.txt.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$wc -l f3.txt
3 f3.txt
[cs@localhost ~]$

17. Count the total number of lines of file f3.txt and f4.txt.
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$ cat>f4.txt
i am a student.
bhairabganguly college.
[cs@localhost~]$wc -l f3.txt f4.txt
 3 f3.txt
 2 f4.txt
 5 total
[cs@localhost ~]$
18.Create  folder and file mentioned in the tree. [cs@localhost~]$ cat>f1.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$ cat>f2.txt
iam a student.
today is tuesday.
bhairabgangulycolege.
[cs@localhost~]$wc f2.txt
3  9 57 f2.txt
[cs@localhost~]$ cat>f3.txt
i am a student.
today is tuesday.
bhairabganguly college.
[cs@localhost~]$wc f3.txt
3 10 59 f3.txt
[cs@localhost~]$ cat>f4.txt
i am a student.
bhairabganguly college.
[cs@localhost~]$wc f3.txt f4.txt
3  10 59 f3.txt
 2  7 41 f4.txt
5  17 100 total
[cs@localhost~]$wc -c f3.txt
59 f3.txt
[cs@localhost~]$wc -c f3.txt f4.txt
59 f3.txt
41 f4.txt
100 total
[cs@localhost~]$wc -w f3.txt
10 f3.txt
[cs@localhost~]$wc -w f3.txt f4.txt
10 f3.txt
 7 f4.txt
17 total
[cs@localhost~]$wc -l f3.txt
3 f3.txt
[cs@localhost~]$wc -l f3.txt f4.txt
 3 f3.txt
 2 f4.txt
 5 total
[cs@localhost~]$mkdir Day
[cs@localhost~]$ cd Day
[cs@localhostDay]$mkdirsunday
[cs@localhostDay]$mkdirmonday
[cs@localhostDay]$mkdirfriday
[cs@localhostDay]$ cd sunday
[cs@localhostsunday]$mkdir 1
[cs@localhostsunday]$mkdir 2
[cs@localhostsunday]$ cd ..
[cs@localhostDay]$ cd monday
[cs@localhostmonday]$mkdir 1
[cs@localhostmonday]$mkdir 2
[cs@localhostmonday]$mkdir 3
[cs@localhostmonday]$ cd ..
[cs@localhostDay]$ cd friday
[cs@localhostfriday]$mkdir 1
[cs@localhostfriday]$mkdir 2
[cs@localhostfriday]$mkdir 3
[cs@localhostfriday]$mkdir 4
[cs@localhostfriday]$ cd ..
[cs@localhostDay]$ cd sunday
[cs@localhostsunday]$ cd 1
[cs@localhost 1]$ touch f1.txt
[cs@localhost 1]$ touch f2.txt
[cs@localhost1]$ cd ..
[cs@localhostsunday]$ cd 2
[cs@localhost 2]$ touch f1.txt
[cs@localhost 2]$ touch f2.txt
[cs@localhost2]$ cd ..
[cs@localhostsunday]$ cd ..
[cs@localhostDay]$ cd monday
[cs@localhostmonday]$ cd 1
[cs@localhost 1]$ touch f1.txt
[cs@localhost 1]$ touch f2.txt
[cs@localhost1]$ cd ..
[cs@localhostmonday]$ cd 2
[cs@localhost 2]$ touch f1.txt
[cs@localhost 2]$ touch f2.txt
[cs@localhost2]$ cd ..
[cs@localhostmonday]$ cd 3
[cs@localhost 3]$ touch f1.txt
[cs@localhost 3]$ touch f2.txt
[cs@localhost3]$ cd ..
[cs@localhostmonday]$ cd ..
[cs@localhostDay]$ cd friday
[cs@localhostfriday]$ cd 1
[cs@localhost 1]$ touch f1.txt
[cs@localhost 1]$ touch f2.txt
[cs@localhost1]$ cd ..
[cs@localhostfriday]$ cd 2
[cs@localhost 2]$ touch f1.txt
[cs@localhost 2]$ touch f2.txt
[cs@localhost2]$ cd ..
[cs@localhostfriday]$ cd 3
[cs@localhost 3]$ touch f1.txt
[cs@localhost 3]$ touch f2.txt
[cs@localhost3]$ cd ..
[cs@localhostfriday]$ cd 4
[cs@localhost 4]$ touch f1.txt
[cs@localhost 4]$ touch f2.txt
[cs@localhost4]$ cd ..
[cs@localhostfriday]$ cd ..
[cs@localhostDay]$ cd ..
[cs@localhost ~]$

19. Delete a file.
[cs@localhost1]$ ls
f1.txt  f2.txt
[cs@localhost1]$ rm f1.txt
[cs@localhost1]$ ls
f2.txt
[cs@localhost 1]$
20. Copy a file.
[cs@localhost1]$ ls
f2.txt
[cs@localhost1]$ cp f2.txt f3.txt
[cs@localhost1]$ ls
f2.txt  f3.txt
[cs@localhost 1]$
21. Move a file.
[cs@localhost1]$ ls
f2.txt  f3.txt
[cs@localhost1]$ mv f3.txt f4.txt
[cs@localhost1]$ ls
f2.txt  f4.txt
[cs@localhost 1]$
                                                                 Date: 29.08.2018
22. Show the lines in which the word "student" is present.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep "student" file2.txt
I am a student
You are not a student
[bgc@localhost ~]$

23. Show the lines and line no. in which the word "student" is present.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -n "student" file2.txt
1:I am a student
2:You are not a student
[bgc@localhost ~]$

24. Show the lines in which the word "student" is present ignoring case-sensitive.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -i "student" file2.txt
I am a student
You are not a student
Student life is the best life
[bgc@localhost ~]$

25. Show the lines and line no. in which the word "student" is present ignoring case-sensitive.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -ni "student" file2.txt
1:I am a student
2:You are not a student
4:Student life is the best life
[bgc@localhost ~]$

26. Show the total no. of lines in which the word "student" is present.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -c "student" file2.txt
2
[bgc@localhost ~]$


27. Show the total no. of lines in which the word "student" is present ignoring case-sensitive.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -nci "student" file2.txt
3
[bgc@localhost ~]$

28. Show the lines in which the word "student" is not present.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -v "student" file2.txt
Today is wednesday
Student life is the best life
[bgc@localhost ~]$

29. Show the lines in which the word "student" is not present ignoring case-sensitive.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ -vi "student" file2.txt
bash: -vi: command not found...
[bgc@localhost ~]$

30. Show the lines and line no. in which the word "student" is not present ignoring case-sensitive.
[bgc@localhost ~]$ cat>file2.txt
I am a student
You are not a student
Today is wednesday
Student life is the best life
[bgc@localhost ~]$ grep -nvi "student" file2.txt
3:Today is wednesday
[bgc@localhost ~]$

No comments:

Post a Comment