Practical 2 Managing Files in Linux System
Practical 2 Managing Files in Linux System
YSTEMS (PRACTI
Section A
At current location (e.g /home/student), perform the following operations:
1. Show the current path.
pwd
3. Give two commands which can list all the contents at the current directory.
ls -a
dir -a
5. Inside this “super” directory, create four files “apple.doc”, “april.doc”, “box.txt” and
“boxes.txt” using touch command.
cd super
7. Go to root directory.
/
mv ultra.txt mega.txt
11. Copy “super” directory to home directory and rename it to “super2” in one command line.
cp -r p2/super ~/super2
ls
14. Go back to directory “p2”. Create a text file “sampleA.txt” using vi command.
cd ~/p2
15. Type the following contents into “sampleA.txt” and save the file.
“The shell is a program that takes keyboard commands and passes them to the operating
system to carry out. Almost all Linux distributions supply a shell program from the GNU
Project called bash.”
2
AACS2284 OPERATING SYSTEMS (PRACTICAL)
wq!
17. Type the following contents into “sampleB.txt” and save the file.
“When using a graphical user interface, we need another program called a terminal
emulator to interact with the shell.”
Control+D or Control+C
18. Open “sampleB.txt” again using vi command and add the following sentences.
“It’s likely called simply “terminal”.”
cat > sampleB.txt // vi sample.txt
It’s likely called simply “terminal”. // wq!
20. Combine the two files “sampleA.txt” and “sampleB.txt” to a file named “sampleC.txt”.
cat sampleA.txt sampleB.txt > sampleC.txt
23. Overwrite “sampleB.txt” by “sampleA.txt” and show the content of both files on the
terminal.
cat sampleA.txt > sampleB.txt
cat sampleA.txt sampleB.txt
3
AACS2284 OPERATING SYSTEMS (PRACTICAL)
25. Go back to home directory and create a new directory named “backup”.
cd ~
mkdir backup
4
AACS2284 OPERATING SYSTEMS (PRACTICAL)
Section B True/False.
Explain the answer if it is false.
True/False
1. The structure of the file system in Linux can be depicted in a True
form of tree. It begins at the root (/), and branches out like the
branches of a tree.
3. When the terminal is opened the starting directory is the root (/) False
directory. ans: home directory
5
AACS2284 OPERATING SYSTEMS (PRACTICAL)
Section C
1a. vi first.file
press i or o or a or R to switch into input mode to insert the word “today” for 4 lines/rows
press Esc to switch back to command mode
:w
1e. vi third.file
in command mode,
press :r first.file
then move the cursor to the last line
press :r second file
1f. :wq or :x
6
AACS2284 OPERATING SYSTEMS (PRACTICAL)
2. Using vi command, create a new file called “sonnet” that contains the first four lines of the
Shakespeare’s 80th Sonnet.
2a. :1,$s/the/a/g
OR
:1,$s/the/a/g
OR
:%s/the/a/g
2c. dd
U
2d. :set nu OR :set number
2e. :wq OR :x