Operating System - HP-UX
1834378 Members
2418 Online
110066 Solutions
New Discussion

How to remove the file with strange name?

 
SOLVED
Go to solution
yyghp
Super Advisor

How to remove the file with strange name?

I noticed that there was a file in the system with strange filename:

$ ll
total 480
-rwxrwxrwx 1 oracle oinstall 10095 Apr 5 17:58 CPL_MASTER.SH
-rwxrwxrwx 1 oracle oinstall 6717 Mar 24 2005 CPL_MASTER.SHBCK
-rwxrwxrwx 1 oracle oinstall 7662 Apr 21 2005 CPL_MASTER.SHBCK02
-rwxrwxrwx 1 oracle oinstall 7727 Jul 7 2005 CPL_MASTER.SHBCK03
-rwxrwxrwx 1 oracle oinstall 4861 Feb 9 2005 CPL_MASTER_BATCH.SH
-rwxrwxrwx 1 oracle oinstall 10035 Jul 15 2005 CPL_MASTER_TEST.SH
-rwxrwxrwx 1 oracle oinstall 425 Feb 9 2005 SH
-rwxrwxrwx 1 oracle oinstall 215 Feb 9 2005 cpl_ftp.sh
-rwxrwxrwx 1 oracle oinstall 87 Jul 21 2005 cpl_list.sh
-rwxrwxrwx 1 oracle oinstall 83 Jul 21 2005 cpl_list1.sh
-rwxrwx--- 1 oracle oinstall 5365 Apr 19 14:11 database_schema.txt
-rwxrwxrwx 1 oracle oinstall 3920 Nov 18 2005 database_schema.txt_crypt
-rwxrwxrwx 1 oracle oinstall 67 Feb 9 2005 ftp_test.txt
-rwxrwxrwx 1 oracle oinstall 10 Feb 9 2005 linevar.txt
-rwxrwxrwx 1 oracle oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log
-rwxrwxrwx 1 oracle oinstall 3178 Dec 8 08:30 njphrrs.log
-rwxrwxrwx 1 oracle oinstall 1319 Jul 7 2005 obj_bu_batch.sql
-rwxrwxrwx 1 oracle oinstall 127 Feb 9 2005 read_line_by_line.sh
-rwxrwxrwx 1 oracle oinstall 330 Feb 9 2005 read_line_by_line2.sh
-rwxrwxrwx 1 oracle oinstall 333 Feb 11 2005 read_line_by_line3.sh
-rwxrwxrwx 1 oracle oinstall 516 Feb 11 2005 read_line_by_line4.sh
-rwxrwxrwx 1 oracle oinstall 80 Feb 9 2005 runsql.sh
-rwxrwxrwx 1 oracle oinstall 86 Mar 30 2005 select.sql
-rwxrwxrwx 1 oracle oinstall 1186 Feb 10 2005 test1.sh
-rwxrwxrwx 1 oracle oinstall 82 Feb 9 2005 test_dest.sh
-rwxrwxrwx 1 oracle oinstall 333 Feb 9 2005 test_server_dest.sh
-rwxrwxrwx 1 oracle oinstall 619 Jul 7 2005 trig_bu_batch.sql
-rwxrwxrwx 1 oracle oinstall 1090 Jul 7 2005 view_bu_batch.sql

See the file in the middle of "ll":
-rwxrwxrwx 1 oracle oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log

Why the filename overwrote the group owner, size, and time of the file?
Thanks!
9 REPLIES 9
Joseph C. Denman
Honored Contributor

Re: How to remove the file with strange name?

You should be able to do it with

rm *ksdjfkl*df.log

...jcd...
If I had only read the instructions first??
Geoff Wild
Honored Contributor

Re: How to remove the file with strange name?

See:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1012235

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to remove the file with strange name?

Hi:

One easy, guaranteed way is to list your file(s) by inode and then remove the file by that inode number:

# ls -il /path #...note the inode number in the first column

# find /path -xdev -type f -inum -exec rm {} \;

I suggest that you substitute 'ls -l' for 'rm' before you actually remove the file to verify that you really want to remove what you found.

Another form, which will prompt you to respond before the remove happens, is:

# find /path -xdev -type f -inum -ok rm {} \;

In any case, the most important points are (1) use '-xdev' so no mountpoints are crossed; (2) substitute the number you wound from the 'ls' command into the 'find' command; and (3) of course, specifiy the correct or directory name.

*Remember* and inode number is only unique within a filesystem. That is, the *same* inode numbers can (often do) exist in different mounted filesystems!

Regards!

...JRF...
Bill Hassell
Honored Contributor

Re: How to remove the file with strange name?

The bad listing format indicates that the filename contains special characters like backspace or carriage return. To see the special characters, use ll -b

Then create an ll the identifies just this file. Now since the file has ; characters, these mean something special to the shell so you can escape them with \ or replace them in the ll command with * something like this:

ll *ksdjfkl*

If that shows you just the bad file, replace the ll with rm:

rm *ksdjfkl*


Bill Hassell, sysadmin
Sandman!
Honored Contributor

Re: How to remove the file with strange name?

Move to the folder where the file is located and then remove it interactively; responding with a "y" for the file in question and "" for the rest:

# cd
# rm -i -- ./*

cheers!
Prasad Joshi
Regular Advisor

Re: How to remove the file with strange name?

Hi

The only problem I could see is, it has some special characters (;) in the file name.

See the output of the following command
bash-2.02# rm oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log
rm: oinstalsdfadfjal non-existent
bash: ksdjfkl: command not found
bash: ajds: command not found
bash: lfkjas: command not found
bash: df.log: command not found

";" is used for seperating different commands on the same line.

So rm will try to remove a file with name till first ; i.e. oinstalsdfadfjal

Then it will try to execute next command till next ; and so on.

If you want to remove this file, then special meaning of ; should be removed. So, use \ before ;. This will override the special meaning of the ; operator.

See following output.


bash-2.02# cat > oinstalsdfadfjal\;ksdjfkl\;ajds\;lfkjas\;df.log
This is a test file.

bash-2.02# ls -l | grep oi
-rw-r--r-- 1 root sys 21 Jun 2 11:10 oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log

bash-2.02# cat oinstalsdfadfjal\;ksdjfkl\;ajds\;lfkjas\;df.log
This is a test file.

bash-2.02# rm oinstalsdfadfjal\;ksdjfkl\;ajds\;lfkjas\;df.log

bash-2.02# ls -l | grep oi



I think this will solve your problem.
Thanks and regards,
Prasad.
Prasad Joshi
Regular Advisor

Re: How to remove the file with strange name?

Hi,

You can try in this way also.
Parse the output so that it will give the exact file name and then pass that file name to rm command.

1. Using xargs.

bash-2.02# ls -l | grep -i oin
-rw-r--r-- 1 root sys 20 Jun 2 11:25 oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log

bash-2.02# ls -l | grep -i oin | awk '{print $9}'
oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log

bash-2.02# ls -l | grep -i oin | awk '{print $9}' | xargs -n1 rm

bash-2.02# ls -l | grep -i oin


2. Way

bash-2.02# ls -l | grep -i oi
-rw-r--r-- 1 root sys 5 Jun 2 11:27 oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log

bash-2.02# ls | grep -i oi
oinstalsdfadfjal;ksdjfkl;ajds;lfkjas;df.log

bash-2.02# rm `ls | grep -i oi`

bash-2.02# ls | grep -i oi
bash-2.02#

Thanks and reagrds,
Prasad.
Raj D.
Honored Contributor

Re: How to remove the file with strange name?

Hi yygp,

You can find the inode number of the file.
Then do a find and remove it.

1. # ls -li filename

2. # find / -inum i_number -exec rm {} \;


cheers,
Raj.


" If u think u can , If u think u cannot , - You are always Right . "
rariasn
Honored Contributor

Re: How to remove the file with strange name?

Hi,

$ ls -li *fadfjal*

note "inode number" is first colum

List:
$ find $PWD -inum i_number -exec ll{} \;

and delete:
$ find $PWD -inum i_number -exec rm{} \;

rgs,
ran