You may work in pairs, if space demands.                 
The purpose of this assignment is to get you started writing Linux
scripts using bash
. You will create and edit a bash script in class
that uses many of the features of shell scripts described in the
lecture.
                
Make sure you can login to the Linux system using the ct320 user and the password given to you by the instructor or teaching assistant. Make sure that you understand the system well enough to run a browser, file manager, terminal and text editor.                 
Practice redirection and pipes using find
and grep
, as shown by
the following sequence:
$ cd /bin $ find . -print | grep dir $ find . -print | grep ch
Advanced students may realize that these pipelines can be reduced
to single find
statements.
                
Practice arranging output in order by name or size or date using ls
and sort
commands, as shown by the following sequence:
$ ls -l | sort -k 9 $ ls -l | sort -k 5 -n
Of course, there are probably ls
options to accomplish the same
ends.
                
Practice splitting an output stream to the terminal and a file using
echo
and tee
, as shown by the following sequence:
$ cd $ echo "Brush your teeth after every meal" | tee string.txt $ cat string.txt
Practice operating on all of the files in a directory using ls
and
chmod
, in conjunction with xargs
, as shown by the following
sequence:
$ mkdir temp $ cd temp $ echo "File 1" >file1.txt $ echo "File 2" >file2.txt $ echo "File 3" >file3.txt $ echo "File 4" >file4.txt $ ls -l $ ls | xargs chmod a=rw $ ls -l
Write a script that does all of the following:
bscript
.
# Students: name1, name2 # Logins: login1, login2 # Assignment: CT320 BashI # Date: YYYY-MM-DD
directory
.
unprotect
, sets protections using chmod a=rwx
for all contents.
list
, displays a long directory listing.
delete
, deletes all files and dirs recursively.
archive
, copies all files and directories to
/tmp/archive
.
In addition to the previous requirements, the script must:                 
/tmp/archive
if it does not exist.
bscript.log
,
creating it anew for each run.
You might want to make a backup copy of the Test
directory before
testing any commands in case your script intentionally or accidentally
deletes files. Now test your script as follows:
                
Test
.
file1.txt
through file5.txt
in Test
.
Test
called Subtest
.
Subfile1.txt
and Subfile2.txt
in Subtest
.
Test
.
unprotect
.
-rwxrwxrwx
).
list
, and examine the
resulting listing.
archive
, and check
/tmp/archive
.
delete
and make sure
Test
is empty.
When you have tested your script, and it works, show your work to the TA.                 
Modified: 2017-09-07T16:38                  User: Guest                  Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |