OS Lab3
OS Lab3
OS Lab3
Procedure:
1. Open your Unix shell and try these commands:
Create a new file and add some text in it
v cat > filename
View a file
v cat /etc/passwd
v more /etc/passwd
v more filename
1
ls > dir.txt
cal 2020 > year2020
cal 2 2020 > Feb2020
cp file1 file2 is the command which makes a copy of file1 in the current
working directory and calls it file2
% cd /Lab2
Then at the UNIX prompt, type,
% cp /home/Admin/Desktop/Text.doc .
Note: Don't forget the dot . at the end. Remember, in UNIX, the dot means
the current directory.
The above command means copy the file science.txt to the current
directory, keeping the name the same.
Task :
1. Create two directories in your home directory with name D1 and D2
2. Create a text file by using a text editor and save it by name file1( By
default file will be saved in your home directory.
3. Using the information given in the above tutorial and using cp
command make the file1 available in D1 and D2.
2
3
Tutorial 2 (Using mv command):
mv (move)
To move a file from one place to another, use the mv command. This has
the effect of moving rather than copying the file, so you end up with only
one file rather than two.
It can also be used to rename a file, by moving the file to the same
directory, but giving it a different name.
We are now going to move the file file1.txt to your Ex1 directory.
% mv file1.txt Ex1/.
Tutorial 3:
4
rm (remove), rmdir (remove directory)
% cp Text.doc tempfile.txt
% ls
% rm tempfile.txt
% ls
You can use the rmdir command to remove a directory (make sure it is
empty first). Try to remove the backups directory. You will not be able to
since UNIX will not let you remove a non-empty directory.
Task
Create a directory called tempstuff using mkdir , then remove it using the
rmdir command.
Before you start the next section, you may like to clear the terminal
window of the previous commands so the output of the following
commands can be clearly understood.
% clear
This will clear all text and leave you with the % prompt at the top of the
window.
cat
The command cat can be used to display the contents of a file on the
screen. Type:
% cat file1.txt
5
Source: http://www.ee.surrey.ac.uk/Teaching/Unix/index.html