Reference no: EM133140271
KIT501 ICT Systems Administration Fundamentals - University of Tasmania
Goal
The main purpose of this second UNIX tutorial is to give you familiarity with the UNIX file system and some more general-purpose UNIX commands.
Exercises
Under your home directory, create a new directory named kit501
$ mkdir kit501
Check to see that the new directory has actually been created
$ ls
10 minutes ago you created two text files named f1.txt and f2.txt. Now move them into the kit501 directory. If you did not create the two files, go back to the pages which contain the instructions for using joe or nano command for creating text files:
$ mv f1.txt kit501
$ mv f2.txt kit501
Change into this new directory:
$ cd kit501
Are you really under this new directory now?
$ pwd
Are there any files currently stored under this new directory? Can you see f1.txt and
f2.txt?
$ ls
You may have forgotten the contents of f1.txt and f2.txt. Can you check them?
$ cat f1.txt
$ cat f2.txt
Can you try to change file names?
$ mv f1.txt f3.txt
$ mv f2.txt f4.txt
Have the names been changed?
$ ls
OK you know it's easy to change file names, so you will change them back to their original names:
$ mv f3.txt f1.txt
$ mv f4.txt f2.txt
Next, make some copies of f1.txt:
$ cp f1.txt file01.txt
(Note: pressing the UP arrow key brings back a previously entered command, which saves trouble in typing longer command lines)
$ cp f1.txt file02.txt
$ cp f1.txt file001.txt
$ cp f1.txt file002.txt
Have you really made some copies of f1.txt?
$ ls
Next, test the special characters * and ?
$ ls f?.txt
$ ls file??.txt
$ ls file???.txt
$ ls ??.txt
$ ls file*.txt
$ ls f*.txt
You should now have some understanding about the difference between * and ?. Next, remove the extra files you created for this exercise:
$ rm file01.txt
$ rm file02.txt
Have the two files been removed?
$ ls
Do you have to remove files one by one?
$ rm file*.txt
Has this one command line removed multiple files?
$ ls
Next, do more exercises on manipulating files.
Under the current directory make a new sub-directory named testdir:
$ mkdir testdir
Copy f1.txt and f2.txt into the new sub-directory:
$ cp f1.txt f2.txt testdir
Can you check to see whether a copy of the two files are actually in testdir?
$ cd testdir
$ ls
What is your current directory now?
$ pwd
Can you go back to the parent directory (kit501) of the current directory?
$ cd ..
Are you really under kit501 now?
$ pwd
How can you delete testdir together with its content?
$ rmdir testdir
Looks like this cannot be done, because rmdir deletes only empty directories. You can change directory into testdir, remove the two files manually to make it an empty directory, and then come back here to run rmdir. However, there is a better approach for this purpose.
$ rm -r testdir
Has the testdir (which is non-empty) been removed?
$ ls
(Warning: rm with option -r can be a dangerous operation because it deletes an entire directory tree.)
Next, try the option -r with the cp command
Make two test directories named testdir1 and testdir2:
$ mkdir testdir1 testdir2
$ ls
Copy f1.txt and f2.txt into testdir1:
$ cp f1.txt f2.txt testdir1
$ ls testdir1
More Hands-on Exercises
A). Under the directory kit501 create two subdirectories called testdir1 and testdir2 using a single command line. Use ls to check their existence.
B). Under testdir1 create two subdirectories named d1 and d2 using a single command line.
C). Under d1 create two ordinary files named file1.txt and file2.txt using the joe or nano text editor.
D). Copy all files in the directory d1 to the directory d2 using a single command line.
E). Under the directory d2 rename file1.txt as f1.txt and file2.txt as f2.txt.
F). Under the directory d2 move f1.txt and f2.txt to the directory d1 using a single command line.
G). Remove the directory d2.
H). Copy everything (files, directories) under the directory testdir1 to the directory testdir2 using a single command line.
I). Remove the directory testdir1.
J) Run the following command and ensure that you understand the output:
$ du -a testdir2
K). Remove the directory testdir2 without first making it empty.
L). Create 5 new directories (under kit501) which must be named dir1, dir2, dir3, dir4, and dir5.
Create a text file under dir1 and a text file under dir2.
Then under the parent directory (kit501) of the 5 directories, remove all the empty directories but retain all the nonempty directories using a single short command line (a command with a single argument).
Attachment:- Practical.rar