A
A
Alexander Zharov2016-03-07 17:47:35
linux
Alexander Zharov, 2016-03-07 17:47:35

How to write a guaranteed deletion script in Linux?

Comrades at work strained to write a script on a system under Linux that would be guaranteed to delete the desired file. No programming skills. I kind of understood how it should look outside the program, but the question arose with writing.
1. It is necessary for the user to enter the path to the file
2. We are looking for all hard and symlinks through Ls
3. We kill them through shred -u -n 30 -z
The problem is that shred copes with its task well and without a script, that is, by hard links to the file will not enter it, but the names remain in the system. How to pull out the inodes of files so that they would also be deleted after shred simply through rm.
Guys help stuff something like this into the script!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2016-03-07
@wildDogDust

Call ./myshreder file1 file2 file3

#!/bin/bash
for file in [email protected]
do
   Inode=$(stat $file | grep -- 'Inode:' | sed -e's/.*Inode: \([0-9]*\).*/\1/')
   Links=$(stat $file | grep -- 'Links:' | sed -e's/.*Links: \([0-9]*\).*/\1/')
   if test $Links -ge 2
   then
         find -inum $Inode | xargs shred -u -n 30 -z          
   else
          stat $file | grep -- 'File:' | sed -e's/[^‘]*‘\([^ ]*\)’[^‘]*/\1 /g' | xargs shred -u -n 30 -z 
    fi
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question