Hi, I am trying to make a command to delete my files out the trash can, but one at a time.
I am currently using rm - i to do this, but the original file locations for restoring my files are heard on a .txt file which I am using as an index table.
How would I manage to make it so that if I remove a file using rm - i, the original path location is removed from my FileLocations.txt file aswell?
I so far have tried using ls dustbin > dustbin.txt to have a copy of the files in a textfile that still exist, and then I was going to try compare the files and remove the lines that did contain any of the file names in my dustbin.txt file.
The problem is I don't really know how to do this, hope you can help, thanks.
Hi, thanks for the post, I sort of understand what it is supposed to do but when it tries to do the rm -i it is doing it on simply say *file* instead of /root/dustbin/file, trying to mess about with the code but all I got was it asking me the three things quickly without getting to press y or n, and then it simply once again said can't remove file no such directory.
Hey, thanks again, it almost works now just there is a problem that when it prompts the rm -i, there is no chance for input it just displays for all the files
in fact you have 2 choices :
1) prevent list.ini to be listed in itself
2) put list.ini somewhere else so it doesn't appear in the dustbin list
(see my previous post that i meanwhile have updated)
Another problem i've realsied is that if I created two files with similiar names such as:
hello
hellothere
if I restored "hello" then "hellothere" also gets removed from file locations, i realise it is probbably to do with inserting a $ somewhere to make it so that what is check is hello only without any proceeding characters.
ls | grep -vf - /tmp/list.ini | sed 's/.*/^&$/' >removed.txt
So this will also match beginning and end of line.
The thing you have to care of is the PATH since the matching must be exact.
(a same filename can be present in 2 differents path)
So i would advise you to work with absolute path name instead of relative (unless you are certain that the filenames in dustbin are going to be uniq by design or by the way they are generated so that they can be used as a key to retrieve the original location)
how would you manage the case :
/etc/file1
/opt/file1
/usr/file1
have been removed...
(is there only 1 corresponding file1 in your dustbin directory ? even if those files have different content to eachother ? )
Or are the dustbin filenames generated so that they are uniq ?
I have made it so all file names are unique, so for instance if there's a file in the trashcan called file then I can not send another file called file there, without removing the first instance.
Please post exactly what you did try (there is no "-e" option in the current version of my previous post) make sure you didn't forgot the last separator (here, a slash) in the substitution command s/.../.../
Well i got it working now by editting some stuff about I think it was not deleting because of the ^ so it expected it to be at the start but really what was always going to be infront of it was a slash so I changed the ^ to \ / and it worked
Will try that other code to see how it goes as well though, and if you want can let you know how it goes?