how delete a special file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how delete a special file
# 8  
Old 04-08-2010
Ok, what's the output of the following command ?

Code:
ls -al | perl -lane 'print "$F[0] $F[$#F]" if /\.$/'

tyler_durden

Or if you don't have Perl, then what's the output of the following 2 commands ?

Code:
ls -al | awk '/\.$/'
ls -al | awk '/\.$/{print $1, $NF}'

# 9  
Old 04-08-2010
find options/syntax may be different depending on your OS/platform

In the directory containing the file:
Code:
$ ls -lai  ### to list the inodes
$ find . -inum <inode_number_of_dot_file> -exec ls -la {} \;

if it only returns that file as the result, and you know you don't need the file
Code:
$ find . -inum <inode_number_of_dot_file> -exec rm {} \;

or rename it to a more usable/appropriate name if still needed:
Code:
$ find . -inum <inode_number_of_dot_file> -exec mv {} <newname> \;


Last edited by ec01; 04-08-2010 at 11:30 AM.. Reason: add code tags
# 10  
Old 04-08-2010
thanks it's this file:
-rw-rw-r-- 1 admin admin 0 4\346\234\210 1 19:42 \033[00m\
\302\267\033[00m$

then how can i remove it .

any idea will be appreciated
# 11  
Old 04-08-2010
find alone isn't very helpful, when it comes to spotting characters that don't print. either pipe it through methyl's sed suggestion, or use something like:
Code:
find . -mindepth 1 -maxdepth 1 -print0 | od -cb



---------- Post updated at 10:38 AM ---------- Previous update was at 10:28 AM ----------

An example that may be helpful to you:
Code:
$ touch "$(printf '.\001\002\003')"
$ find . -mindepth 1 -maxdepth 1
./.
$ find . -mindepth 1 -maxdepth 1 -print0 | od -cb
0000000    .   /   . 001 002 003  \0                                    
          056 057 056 001 002 003 000                                    
0000007
$ rm "$(printf '\056\057\056\001\002\003')"
$ find . -mindepth 1 -maxdepth 1 -print0 | od -cb
$ # Strangely named file is now gone

Also, if this odd file is the only one in the directory, you might be able to delete it with a simple:
Code:
rm *

or
Code:
rm .*

Regards,
Alister
# 12  
Old 04-08-2010
thanks , i need to go back to my dormitory now.
i will deal with it tomorrow.
thanks
# 13  
Old 04-08-2010
Unless I missed something important . and .. are files created by the mkdir command.
Normally ls does not show them. It does for you.

I am guessing that somehow a '.' file - possibly with non-printing characters in the file name - has been created. Which some other posters are assuming is the case.

I would like to point out:
If it is really just a dot ('.') then the directory is hosed. (or something unpleasantly interesting happened to the ls command) You may have to resort to fsck (or whatever utility you use) to fix filesystems. One way to see if this is the case is to follow madmat's suggestion.
# 14  
Old 04-08-2010
Quote:
drwxrwxr-x 7 admin admin 4096 4\346\234\210 8 22:09 \033[00;\
34m.\033[00m$
drwxr-xr-x 6 admin admin 4096 4\346\234\210 8 09:42 \033[00;\
34m..\033[00m$
-rw-rw-r-- 1 admin admin 0 4\346\234\210 1 19:42 \033[00m\
\302\267\033[00m$
I guess that the Escape sequences are something to do with formatting your local "ls". Not seen that before myself. The Chinese names in the directory listing are also outside of my experience.
I have highlighted what I think are the three filenames in this listing. The normal "." and ".." which we expect in every directory and a weird file with a two-character name.

Code:
We can test this theory.
# Generate the filename.
WEIRD=`echo "\0302\0267\c"`
# See if we can find it.
ls -lad "${WEIRD}" | sed -n l
# If we found the filename, we can rename it
mv "${WEIRD}" junkfile
# Then delete it
rm junkfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help to delete special characters exists only at the end of the each record in UNIX file?

Hi, I have a file in unix with 15 columns.It consists special characters(#,$,^M,@,*,% etc)at the end of the each record.I want to remove these special characters.I used the following: Sed -e 's/ /g;s/ */ /g' . But It is removing special characters exists everywhere in the file(begining,middle... (24 Replies)
Discussion started by: rakeshp
24 Replies

2. Shell Programming and Scripting

Delete special characters

My sed is not working on deleting the entire special characters and leaving what is necessary.grep connections_per a|sed -e 's/\<\!\-\-//g' INPUT: <!-- <connections_per_instance>1</connections_per_instance> --> <method>HALF</method> <!--... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

3. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

4. Shell Programming and Scripting

how to delete special characters from the file content

Hello Team, Any one suggest how to delte the below special character from a file which is having one column 10 rows of same below content. ---------------------------------------- Kosten|bersicht gemd_ ' =Welche Kosten kvnnen... (2 Replies)
Discussion started by: kanakaraju
2 Replies

5. Shell Programming and Scripting

sed delete pattern with special characters

Hi all, I have the following lines <b>A gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>B gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) <b>J gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text) and I would like to... (5 Replies)
Discussion started by: stinkefisch
5 Replies

6. UNIX for Dummies Questions & Answers

How to delete a file with special characters

I don't now exactly how I did it, but I created a file named " -C " cexdi:/home1 $ls -lt total 1801336 -rw------- 1 cexdi ced-group 922275840 23 mars 10:03 -C How do I delete this file ? cexdi:/home1 $rm -C rm: invalid option -- C Syntax : rm filename ... Doesn't work...... (5 Replies)
Discussion started by: yveslagace
5 Replies

7. UNIX for Dummies Questions & Answers

how to delete whole directory in special case

Hello, Today, as a root user, i want to copy recursively all files and diretories in a source directory to a destination directory using the following command, cp -r /home/smith/* /home/bob/ However, I carelessly missed the '*' out when I executed the command. Now, i noticed a... (1 Reply)
Discussion started by: cy163
1 Replies

8. Shell Programming and Scripting

delete a special character in file

hi i want to delete a particular character in file. example file name:abcsample abc=bbbqw3/ hidh=ajjqiwio4/ xyx=hakjp/ ........../ ......./ i want to delete that special character (/) in abcsample file Permnently.please give the required commands for my requirement. required... (1 Reply)
Discussion started by: srivsn
1 Replies

9. Shell Programming and Scripting

delete a special character in file

hi i want to delete a particular character in file. example file name:abcsample abc=bbbqw3/ hidh=ajjqiwio4/ xyx=hakjp/ ........../ ......./ i want to delete that special character (/) in abcsample file.please give the required commands for my requirement. thank you (3 Replies)
Discussion started by: srivsn
3 Replies
Login or Register to Ask a Question