| Working with non-printable filenames |
|
|
|
| Written by Tom Hirt | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Tuesday, 24 February 2009 09:59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Have you ever found yourself working with a file-name that contained non-printable characters? If you have, then you already know how difficult they can be to work with. These files present a problem to us because they contain characters or symbols that are not typically found on our keyboard. Usually these files have control characters or other non UTF-8 compliant characters that we have no way of representing.
So how can we work with such a file? Fortunately unbeknownst to most *nix administrators, the modern day file-system deals with files and directories not by name, but by inode. When a file system is created (formated), data structures are created that contain information about each of the files and directories. Each file and directory is associated with an inode that is then identified by an inode number. Inodes store information on files, such as user and group ownership, access mode (read, write, execute permissions) and type of file. Most of the commands you probably already use have a command-line switch to either reveal or reference a given inode. For example, you'll see from the below screen shot that we have issued the command 'ls -ali'. You'll notice the additional switch of 'i' has produced a directory listing containing a new column that includes the inode number of each file and directory.
Now that we know the inode number of the file of interest, we can now use this to help us work with the non-printable file-name. Lets begin by renaming the first file-name to something that is a little more "friendly" to work with:
As you can see, we used find's command line switch of -inum to reference the non-printable filename's inode number renaming it to 'PRINTABLE_FILENAME'. Notice that in doing so, the inode number of the file never changed! As we said above, the inode is how the file is actually referenced by the filesystem. Because the human readable file-name we interact with is just another attribute contained in the meta-data of the inode database, changing the file-name has no actual affect on the underlying data referenced by the inode number. Thus changing the filename does not produce a new inode number. Now that the filename has been renamed, you can now intereact with the file as you would have done so with any other file using commands like less, cp, and rm to view the contents, copy and remove the file. But, lets take this one step further, and see how we might remove the file in one quick and easy step:
Notice we used the initial find as a precautionary step just to ensure we were matching the file of interest. After we verified the inode number of the file we wanted to remove, we used find optional command line switch of '-exec rm {} \;' to remove the file! Now how easy was that? Just remember our golden rule, backup backup backup! Once this file is removed, its gone forever.
!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved." |
|||||||||||||||||||||||||||||||||||||||||||||||||||
| Last Updated on Monday, 02 March 2009 17:46 | |||||||||||||||||||||||||||||||||||||||||||||||||||