bash script to delete and store location of full path
Hi all I am needing help on a bash script I'm trying to program, here's a little info on my knowledge and my problem.
I have only just started using linux (ubuntu) so my knowledge is poor but I am really interested in it and slowly learning more and more but my programming skills are also poor but I have never done this style of computing before so for give me for bad programming practices. :o My Problem: I am trying to create a script that deletes files but moves them to a "dustbin" location but at the same time save its file path in a .txt file in case I need to restore it . Here's what I have so far for that and it works. For i in $1 do mv $i ~/dustbin echo "Moved File $i" done Now I have located solved solution to some thing similar to what I'm trying to achieve here: http://www.linuxquestions.org/questi...re-4175438482/ But because my knowledge is not very good I get a little lost. Thanks for your time all |
Please place code or scripts within code blocks. Use advanced mode to assist with this.
A quick test shows that the script works. however there is a problem; which is that $i is gone once you've moved it. Further, you want to echo this information to a file, not just to stdout. Try using a variable: Here's your original: Code:
For i in $1 Code:
#!/bin/bash |
Hi rtmistler, thanks for taking the time to answer my question.
I have gone with a different approach which I think you will agree is better overall: Code:
#!/bin/sh Code:
#!/bin/sh Thanks |
Not 100% sure what you want to do, but assuming you want to keep a record of the files you have tried to move in ~/fp.txt then you code doesn't do it for two reasons:
|
I wasn't familiar with readlink, but looked it up to see that it's how to get the information on a symbolic link. I'm confused there because bash supports the "-h" test operator.
http://www.tldp.org/LDP/abs/html/fto.html Quote:
I recommend you stay basic until you have to do differently. Otherwise you write this complex script which you'll have a lot of issues debugging. Re-Note my earlier recommendation that you place: Quote:
|
Quote:
– The mv command has a -v option to give a message about the executed command. – When the text file with the original paths gets large, it might take some time to get the necessary entry. Depending on your file system and mount options you can store the information as extended attributes: Code:
$:~/baz> touch foobar |
I would suggest using tar to make a copy - that way the full path would preserved within the tar output file, AND you would also have a symbolic links preserved appropriately.
The basic problem is that you would loose your data if it just happened to have the same file name in two different paths - the first one removed would be lost, and your tracking data would be invalid. Putting the data in a tar file allows you to use compression to reduce storage, AND you can generate a unique file name to hold the tar file. If you wanted a tracking file with paths, just list the contents of the tar file (tar -vtf tarfilename ...) and have the output combined with the unique tar file name appended to the tracking file. |
Thanks all for your input but I'm very new to this and would like to keep things simple for now.
Now I have improved my delete script with a few error checkers and it works really well so my next step is to restore but I'm not sure I even have this right as I'm reading random stuff and if anyone has a nice newbie guide on scripts they think is best to read that would be great but here's the code I have right now. Code:
if [ -f $1 ] |
All times are GMT -5. The time now is 09:51 PM. |