I have very little knowledge about unix.
My task is to write a shell script to delete multiple files and directories.
All files and directories have different location.
So can i use this logic of creating an array and storing all the paths in that.Then looping around the array and use rm command with each element of array.
I dont have unix system to practice commands, hence i was not able to test it. Is this the correct way? or what else could be done
Thanks a lot.
Yes you can do it this way.
The rm command can take multiple arguments to delete multiple files/directory in one command.
So, instead of calling rm once per entry in your array, you can call it only one time with all the files in your array as parameter.
If you have a lot of files to delete, be careful because there is a command line length limit. (you can get it by executing “getconf ARG_MAX” )