z/OS - Group home

How to process files with messy codes in file name in UNIX-like platform (z/OS USS, Linux)

  

With the development of internet, many data of the users will need to be stored and processed cross platforms. However, the conditions that file names with messy codes will often occur when some files are copied between Linux and Windows, or just copied between Linux systems. In most cases, this problem is due to the Character set difference between different platforms. This article will mainly introduce how to process files with messy codes in file name in Unix-like platform (z/OS USS, Linux).

 

1. The frequent fault with messy codes in file names often encountered in Unix-like platform

DEMO@LPAR1&ls

-rwxr-xr-x  1 SETUP  OPERATOR   0 Jun 14  2011  �0 }q�V�

 

DEMO@LPAR1&rm –r �0 }q�V�

rm: FSUM9195 cannot unlink entry "�0 }q�V�": EDC5129I No such file or directory. (errno2=0x058B005D)

 

DEMO@LPAR1&cat �0 }q�V�

cat: �0 }q�V�: EDC5129I No such file or directory. (errno2=0x05620062)

 

For these files with messy codes in file names, we can clearly see they are such files in the directory, but we can not browser them, delete them and so on. This article will take advantage of inode to solve this problem.

 

2. inode introduction

Inode is a kind of data structure of UNIX operating system, its essence is a struct, it includes some important information related with all files of the file system. When creating file system in UNIX, a lot of inode will also be created at the same time. In general, about one percent of the file system disk space is assigned to inode table.

Sometimes, users will use some different terminologies, such as inode and inumber. These two terminologies are very similar, and they are related, but they are not the same concepts. Inode refers to data structure, but in fact inumber is mark number of inode. So we also call inumber as inode number or inumber (index number).  Inumber is only an important element of file related information.

Inode table includes a list, in which all the inode numbers of related file systems are listed. When a user is trying to search or access a file, UNIX system will take advantage of inode table to find the correct inode number. The related commands could be used to access this very inode and also modify it after the inode number is found.

 

3. Use inumber to operate files with messy code in file names

Each inode has a number, operating system uses inumber to distinguish different files.

It's worth repeating here, Unix/Linux systems take advantage of inumbers instead of file names to distinguish different files. As to operating systems, file names are only aliases that are easy to be distinguished for inumber. On the surface, users are opening files via file names. In fact, this process can be divided into three parts in internal systems. Firstly, system will find the inumber corresponding to the file name;  secondly, get the inode information via inumber; finally, find the block where file data is located and read the data according to inode information.

 

Inumbers (inode numbers) of  related files can be displayed via “ls -i” commands as following.

image

 

 

 

 

Next, we will introduce how to process files with messy codes in file name using inode in details.

1) Modify files via inode

image

 

 

 

 

 

It is clear that there are four file under this directory, including three ones with the same inumber. Why are there three files with the same inumber ? Because here we are creating these files via hard link. Let me put it another way, file te%0@st1.txt is firstly created, then we can use the following commands to create two hard links separately.

image

 

Let us edit file te%0@st3.txt with inumber 7502624 firstly, the command is as following.

image

 

 

Then we will process the other three files with the same inumber, for example, we will edit te%0@st2.txt here, command is as following.

image

 

 

2) Copy files via inode

For example, here we will copy te%0@st3.txt to the current directory, and rename the file name to test3.txt using the following commands.

image

 

3) Delete files via inode

According to above command formats, we can easily know how to use inumber to delete indicated files. For example, we are going to delete the newly created file test3.txt, commands are as following.

image

 

We can also use the following command formats to delete indicated files via inumber.

image

 

 

 

 

 

 

 

You may not be familiar with the exec parameters, I will detail its related parameters here.

find  path -option [ -print ]  [ -exec -ok command ] {} \;

 

The parameters are as following.

path: The directory path used for “find” command to operate. For example, . indicates current directory, / indicates system root directory.

-print: Used for “find” command to output matched files to standard output.

-exec: Used for “find” command to execute shell command to matched files with given parameters.

-ok: This function is similar to -exec, but it provides a safer mode for user to operate.

Here, in command “rm -i”, i indicates interactive, or rather, it indicates Interactive Mode Delete Files. Before each deletion operation, a system reminder will will be given to user using this parameter.

 

4. Conclusion

This article mainly introduces how to process files with messy codes in file name in Unix-like platform (z/OS USS, Linux), and only applies to UNIX-like platform.