Moving files from folders and subfolders to a specific folder
I am new to bash. I am using secure delete to remove files from a Debian Linux PC. However, secure delete does not remove folders. This has lead me to look at writing a script that would move files to a predetermined folder for deletion. My plan is as follows:
I have a folder on my desktop called shredder where I move the contents of the waste bin to. The script needs to identify all files within the folders and sub folders, within the shredder folder, and move each file to the shredder folder and then delete the folder. At this point secure delete can be used with a command like shred -v -u *.* on the shredder folder. The problem I have is in creating the code to move files from the different folders and then deleting the folders. Note that the names of the files, folders and subfolders will not always be known. Any help greatly appreciated. Michael |
Why not use cp -a then delete the folders?
|
thanks...bro
|
Please mark as SOLVED if you have your solution.
|
Hi,
Welcome to LQ! Why not just use the 'mv' command. Just move the parent directory that you desire to remove to the 'shred' directory. Just a few links to aid you; Linux Documentation Project Rute Tutorial & Exposition Linux Command Guide Ultimate Linux Newbie Guide LinuxSelfHelp Getting Started with Linux Bash Reference Manual Advanced Bash-Scripting Guide Linux Home Networking Virtualiation- Top 10 :hattip: The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links! |
I think I misread the point. Please ignore my suggestion and follow onebuck's. In your shedder folder, do
Code:
find -type f -exec shred -v -u {} \; |
Quote:
|
Quote:
find: missing argument to `-exec' Am I correct in that what you are thinking of here is to run your code from a script that that works from the shredder folder. As a result, the files are found in all sub folders and moved to the shredder folder. After this action, the folders are deleted. If that is the case, we are definitely on the right track. |
Quote:
Code:
find -type f -exec shred -v -u {} \; Code:
#!/bin/bash Code:
bash ~/shred.sh |
Quote:
One small issue is that the folders are not removed. What happens is the script is removed and the folders stat in tact. |
I'm not sure what could have really happened but since you placed the script in the shredder folder, it should have been included in the deletion as well.
Perhaps bash no longer continued to run after it finds out that the script no longer exists so it didn't run the second statement that deletes the directories. ~ is just an alias to your home directory. For example if your username is 'user' then your home directory would probably be /home/user. And if that's the case, if you try to run 'cd ~', it will just be the same as 'cd /home/user'. Running 'cd' with no argument is also the same as 'cd ~' or 'cd /home/user'. What I meant before was that you place the script in your home directory. |
You should be careful not to run the script anywhere but in the shredder directory. I'll make some modifications to the script just to be safe:
Code:
#!/bin/bash |
Quote:
Michael |
All times are GMT -5. The time now is 05:14 AM. |