Saturday, July 21, 2012

Tutorial on Deleting Metacharatered Files


Tutorial on Deleting Metacharatered Files

Tutorial on Deleting Metacharatered Files
If you’ve transferred files to your Unix account from a PC or Macintosh with filenames containing what Unix considers to be meta-characters, they may cause problems. Meta-characters (including semicolons, spaces, backslashes, dollar signs, question marks, and asterisks) are characters that are interpreted under Unix as commands or instructions. Although these characters may not cause any trouble in other operating systems, their special Unix interpretations may cause problems when you try to delete them. Lets start with how to delete metacharactered files in Unix Environment , Sometimes accidentally, we create a strange file that can’t be deleted because of it being created with space or some control characters in its name,
1: One of the best way to remove the file using the inode number  , Here list is a metacharactered file, we can get the inode number of file by running ls –lirt (where i stand for inode no.)
546688 -rw-rw-r– 1 username groupname 39 Oct 9 19:53 sftdvis
546869 -rw-rw-r– 1 username groupname 55 Oct 9 21:23 dvis
96015 -rwxrwxr-x 1 username groupname 1637 Dec 16 14:18 TestScript.sh
114500 -rw-r–r– 1 username groupname 8512 Dec 27 12:48 PaymentDD.class
115912 -rw-r–r– 1 username groupname 22355 Dec 29 13:06 csAPIInBan_Dl.class
546533 drwxrwxr-x 2 username groupname 96 Jan 10 06:06 test
546557 -rw-rw-r– 1 username groupname 0 Jan 10 06:10 list
Then running the find command to delete that file,
find . –inum 546557 –exec rm {} \; ( inum represent the inode number of that file )
2 :There is also another quick way,might work most of the time,Just list the metacharactered files using ls –lrqt (where q list nonprinting character in the file name),
lrwxrwxrwx 1 username groupname 27 Mar 21 2011 abp_home -> /ENBSTSTR/vdc/ST_ST_SP6_P26
drwxr-xr-x 8 username groupname 8192 May 11 2011 pbin_V64
drwxrwxr-x 3 username groupname 8192 May 11 2011 patch
-rw-r–r– 1 username groupname 5933 Jul 29 12:32 VDC9I
-rwxr-xr-x 1 username groupname 367 Aug 1 14:23 a.sh
drwxrwxr-x 4 username groupname 96 Aug 23 09:11 Patches
-rw-rw-r– 1 username groupname 39 Oct 9 19:53 sftdvis
-rw-rw-r– 1 username groupname 55 Oct 9 21:23 dvis
-rwxrwxr-x 1 username groupname 1637 Dec 16 14:18 TestScript.sh
-rw-r–r– 1 username groupname 8512 Dec 27 12:48 PaymentDD.class
-rw-r–r– 1 username groupname 22355 Dec 29 13:06 csAPIInBan_Dl.class
drwxrwxr-x 2 username groupname 96 Jan 10 06:06 test
-rw-rw-r– 1 username groupname 0 Jan 10 06:20 listst??
Then run rm listst?? , it will remove that file.
3.There is another way if there is spaces in the file name , Rm –rf “file name with spaces”.To remove a file which have spaces in between its name.Another format:rm file\ with\ spaces\ in\ the\ name .Use quotes to surround the file name:rm “file with a space.txt”.
4.To remove a file whose name begins with a dash ( - ) character, refer to the file with the following syntax: rm ./-filename.Some Emacs editors allow you to directly edit a directory, and this provides yet another way to remove a file with a troublesome name.
5.There are some characters that you cannot remove using any of the above methods, such as forward slashes, interpreted by Unix as directory separators. To remove a file with such meta-characters, you may have to FTP into the account containing the file from a separate account and enter the command: mdel
You will be asked if you really wish to delete each file in the directory. Be sure to answer  n  (for no) for each file except the file containing the difficult character that you wish to delete. Delete that file by typing  y  (for yes) when prompted. Once you’ve deleted the intended file, you may press Ctrl-c to discontinue the mdel process. Use this approach cautiously to avoid deleting other files by mistake.

No comments:

Post a Comment