-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Seems like this is homework...we help people solve problems at work
while they are.getting paid, so why not help someone at school!
Francis Isabel wrote:
> somebody can help me explain to me this exercise
>
> write a shell script program that takes the name of a direcoty as an
> argumen and search the file hierarchy at the directory for zero-length
> file.
The first line basically says that you should be able to type this in
the terminal and it will search ANY directory you list
./deletescript directory name here
Search /tmp
./deletescript /tmp
write the name of all zero-length file to start output.
Was this suppose to say write all zero-lenght files to standard output?
Either way it means that any empty or zero length files will be listed
as a result of the search, but empty files only.
if there
> is no option on the command line, have the script deletet he file
> after displaying its name, asking the user for confirmation, and
> receiving positive confirmation
There is an option that you can use with the rm command to confirm yes
or no if you want to delete a file
You can actually do all of this in a one liner...lets do it in 10 easy
steps.
1. cd $HOME
2. Create a file named deletescript...so deletescript is an argument to
touch:
touch deletescript
3. Edit the deletescript and put this in it and save it
#!/bin/bash
find $1 -type f -empty -exec rm -i {} \;
4. Now you need to make the file executable:
chmod +x deletescript
or chmod 755 deletescript
5. Make a homework directory for this little exercise:
mkdir deleteme
cd deleteme
6. Create a few empty files..touch makes zero length files. Understand
that any field after a command is an argument...below you will pass 4
arguments to touch:
touch a b c d
7. Create a file that says hello in it...this will be your non zero
length file:
echo "HELLO HOMEWORK" > e
8. Go back to your home directory and run the script:
cd $HOME
./myscript deleteme
9. Please learn what is going on in this one line here:
find $1 -type f -empty -exec rm -i {} \;
10. Go eat some icecream
The most important thing is $1 which means the first argument or first
field after the script name...anything after the script name is
considered an argument. Anything after the first argument is the second
and so on...arguments are separated by 1 space. So $3 would take the
third argument from the command line
Bryan
>
> >
- --
A healthy diet includes Linux, Linux and more Linux.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkrkzFEACgkQh+MLjl5SKYQ5VgCfTtn1ALcwr7EpgGu7DXkfvG2X
BYIAmQHP7qDO1lcEJzf3IPxqolJufFUw
=pJuR
-----END PGP SIGNATURE-----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit our group at
http://groups.google.com/group/linuxusersgroup
-~----------~----~----~----~------~----~------~--~---