Tar and Compress
Create a relatively
large file (you can copy and paste from another). When complete, try to
compress it as follows:
gzip largeFile
Compare the size of
the compressed file and the original both in terms of bytes and allocation
units. When finished, uncompress the file:
gzip –d largeFile
Create a number of
small text files (at least four) and fill them with trivial data e.g.
myFile1
myFile2
myFile3, etc.
Try ls –ls and
examine the size of each file and the number of allocation units. Now archive
these files using tar.
tar cvf myFiles.tar *
Now enter ls –ls,
a new file should be created. Again look at the size of the file and the number
of allocation units it uses.
Finally, we can
compress the new file:
gzip myFiles.tar
Do ls –ls and
note .gz should be appended to the file.
Now, compare the size
of the four files (i.e. the number of allocation units) and the number of
allocation files taken up by the new file.
Now uncompress the tar
file (gzip –d as above) and extract
files from the archive:
tar xvf myFiles.tar
Exercise 1 Write a shell script which prompts a user to
enter a directory path. The script should archive and compress all the files
which are contained in the directory. Note: the user running the script needs
to enter the full path of the directory.
Exercise 2 Write a complimentary script which de-archives
and decompresses the files above. The shell should include creating a directory
to contain all the de-compressed and de-archived files.
Environmental Variables
Changing
PATH
Create a new directory at / e.g. /newDir
Change the directory and create a simple
script (call it script1) e.g. echo
“Hello”
Grant yourself permission to execute and
check it runs
Return to your home directory and try to
run it again – it should not run.
Now add the directory (i.e. /newDir) to
your PATH e.g. PATH=$PATH:/newDir
and try again.
It should work from any directory (don’t
use ./ with it), enter script1.
Making
PATH permanent
Unfortunately when you change PATH from the
command line (as above) means only a temporary change.
To make the change permanent, create the
file .bash_profile (if it’s not
already there) in your home directory.
PATH=$PATH:/newDir
export PATH
Once the file is saved, log out and log in
again. The script should now run.
PS1 – the primary prompt
Set PS1=”Hello Everybody”
To make it permanent, create .bashrc
PS1=”My Linux: “
export PS1
Exercise
3 – look up to see how prompt
colours can be changed.
No comments:
Post a Comment