OSLAB1
OSLAB1
OBJECTIVE:
Study of some Basic & Advance Unix commands on Linux/ Unix Operating System.
THEORY:
To execute a command, type its name, options and arguments at the shell prompt.
15. comm <file1> <file2>:To display common values between two files
• Simple Filters
5. paste <file1> <file2> :To combine two file vertically rather than horizontally
Ex paste –d “|” fname1 fname2
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
9. tee: read from standard input and write to standard output and files
Ex. ls *.txt | wc -l | tee count.txt
• Pipe
Connects commands so the output of one becomes input for the second
Vertical bar(|) is the pipe operator.
Ex. ls -l | more
cat file1 file2 | sort > file3
Concatenates file1 and file2
Sends the result to the sort command
Store the alphabetized, concatenate result as a new file called file3
Grep: Global regular expression print
Searching and pattern matching tools
Searches files for one or more pattern arguments. It does plain string, basic regular
expression, and extended regular expression searching
Following are some of the options for grep
-i ignore case for matching
-v doesn’t display lines matching expression
-n display line numbers along of occurrences
-c counting number of occurrences
-l display list of file names
-e exp for matching
-f file take patterns from file
-E treat pattern as an extended reg. exp
-F matches multiple fixed strings (fgrep)
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
1. Change your password to a password you would like to use for the remainder of
the semester.
9. Direct the output of the man pages for the date command to a file named mydate.
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
12. Go to the subdirectory mydir and copy the file mydate to a new file called ourdate
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
14. Do a long listing on the file ourdate and note the permissions.
15. Display the name of the current directory starting from the root.
16. Move the files in the directory mydir back to your home directory.
20. Redirect the output of the long listing of files to a file named list.
21. Select any 5 capitals of states in India and enter them in a file named capitals1.
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
Choose 5 more capitals and enter them in a file named capitals2. Choose 5 more
capitals and enter them in a file named capitals3. Concatenate all 3 files and
redirect the output to a file named capitals.
23. Give read and write permissions to all users for the file capitals.
20. Give read permissions only to the owner of the file capitals. Open the file, make
some changes and try to save it. What happens ?
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
21. Create an alias to concatenate the 3 files capitals1, capitals2, capitals3 and
redirect the output to a file named capitals. Activate the alias and make it run.
22. Find out the number of times the string “the” appears in the file mydate.
23. Find out the line numbers on which the string “date” exists in mydate.
24. Print all lines of mydate except those that have the letter “i” in them.
26. List 5 states in north east India in a file mystates. List their corresponding
capitals
in a file mycapitals. Use the paste command to join the 2 files.
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
27. Use the cut command to print the 1st and 3rd columns of the /etc/passwd file for
all students in this class.
28. Count the number of people logged in and also trap the users in a file using the
command.
30. Create any two files & display the common values between them.
OUTPUT:mObserve and note down result displayed /generated after execution of
above commands.
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
APPLICATIONS:
1. To enable the user to communicate with the kernel through the command
interpreter.
2. Useful in Shell Programming.
• FAQs:
5) How will you sort the file which contains numeric data?
Ans- To sort a file that contains numeric data, you can use the sort command with the -n option,
which sorts the data numerically.
Example: sort -n filename
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)
This will sort the file filename containing numeric data in ascending order. For descending order, you
can use the -r option along with -n: sort -nr filename
CONCLUSION:-
In this lab, we explored and executed various basic and advanced Linux commands on a
Linux/Unix operating system. By understanding how to use commands for tasks such as file
manipulation, process management, and system navigation, we gained hands-on experience
with the command line interface. This lab helped us to better understand the functionality
and efficiency of Linux commands, which are essential for system administration and
troubleshooting in Unix-based environments.