needed opinion on the below code
Hi All,
I am planning to delete few files from a subdirectory, my aim is to locate all *.des files, remove them all except the one which the user specifies.here is the code i wrote which is not coming out right. des1 is already existing in the folder, and i am copying that to a new file with a different name and deleting all the *.des files in that folder. one more thing is, that there are also other type of files in the directory. so i just want to remove only the *.des files keeping the only one which the user specifies. #!/bin/bash echo "Enter Des File name" read des1 echo " Enter the 5 digit name" read des2 cp $des1 $des2 touch $des2 for i in `ls .` rm -f $i/*.des i know that above code removes all *.des files, wat command do i add to exclude that particular user given file. if you point me to the command name , i will figure out the code... Thanks |
hi, not quite sure from your description but here is some untested code to fool around with:
Code:
#!/bin/bash |
Thanks Schenidz..i am getting some error..i will try to debug it..if i don;t get an answer i will reply again.
|
Its not backing up the user given input, and its removing all the *.des files in the directory.
any other suggestions.. |
Quote:
|
suresh,
I solved the error, it was a space issue in my script. The part is i am not able to write a effective code to remove the user input file from the directory. for e.g. A(main dir)--> b, c b and c are subdirectories, basically i want the code to look under b and c remove all the *.des files , except the user input. |
I did not really understand the two input names in the code of post #1 (please, clarify). However, following your description, you can exclude a file name from a list by means of grep -v:
Code:
#!/bin/bash |
Thanks colucix..i tried this one and it worked for me
find . -not -name $des1 -iname "*.des" -exec rm -f {} \; i figured out this part, but the question..if i want to loop this command through the first subdirectory or the user specified directory..how would i do that? if i figured it out i will post it here |
All times are GMT -5. The time now is 06:33 AM. |