Debian Codegraph @

idelete.sh

raw symbols SCIP
1 #!/bin/bash
2 # idelete.sh: Deleting a file by its inode number.
3
4 # This is useful when a filename starts with an illegal character,
5 #+ such as ? or -.
6
7 ARGCOUNT=1 # Filename arg must be passed to script.
8 E_WRONGARGS=70
9 E_FILE_NOT_EXIST=71
10 E_CHANGED_MIND=72
11
12 if [ $# -ne "$ARGCOUNT" ]
13 then
14 echo "Usage: `basename $0` filename"
15 exit $E_WRONGARGS
16 fi
17
18 if [ ! -e "$1" ]
19 then
20 echo "File \""$1"\" does not exist."
21 exit $E_FILE_NOT_EXIST
22 fi
23
24 inum=`ls -i | grep "$1" | awk '{print $1}'`
25 # inum = inode (index node) number of file
26 # -----------------------------------------------------------------------
27 # Every file has an inode, a record that holds its physical address info.
28 # -----------------------------------------------------------------------
29
30 echo; echo -n "Are you absolutely sure you want to delete \"$1\" (y/n)? "
31 # The '-v' option to 'rm' also asks this.
32 read answer
33 case "$answer" in
34 [nN]) echo "Changed your mind, huh?"
35 exit $E_CHANGED_MIND
36 ;;
37 *) echo "Deleting file \"$1\".";;
38 esac
39
40 find . -inum $inum -exec rm {} \;
41 # ^^
42 # Curly brackets are placeholder
43 #+ for text output by "find."
44 echo "File "\"$1"\" deleted!"
45
46 exit 0