Home > bash > Delete multiple files with special characters

Delete multiple files with special characters

September 7Hits:2
Advertisement

I have a machine containing a large number of files that were originally created on a mac with some sort of special character in the name (not sure what). When I do an ls in a bash terminal, these files show up something like the following:

$ ls -al ls: cannot access ._BLM?OAS: No such file or directory ls: cannot access BLM?OAS: No such file or directory total 20476 drwx------+ 43 Integr None       0 Sep  7 09:19 . drwx------+ 16 Integr None       0 Sep  7 09:19 .. -rwx------+  1 Integr None   24580 Jul  6 14:27 .DS_Store ???????????  ? ?      ?          ?            ? ._BLM?OAS drwx------+  2 Integr None       0 Sep  7 09:19 66-North . . . 

Note particularly the errors after the ls and the file with all the ? in it's name. Now I know I can delete the ._ file safely, except that when I try to do that it doesn't work:

$ rm ._*         rm: cannot remove `._BLM?OAS': No such file or directory 

So how can I remove these files? There are literally several hundred of them, so one-by-one doesn't work. I know I can add the -delete flag to find to delete all found files, but doing a 'find . -name "._*" -delete' results in the same error (only repeated hundreds of times). Thanks.

Answers

You can remove the file by encasing it in single quotes:

[email protected](/tmp)$ touch '._BLM?OAS'
[email protected](/tmp)$ ls -l ._BLM?OAS
-rw-r--r--  1 wmoore users 0 Sep  7 14:04 ._BLM?OAS
[email protected](/tmp)$ rm -f '._BLM?OAS'
[email protected](/tmp)$ ls -l ._BLM?OAS
/usr/bin/ls: ._BLM?OAS: No such file or directory

However, being as that the files status contains a bunch of question marks, this leads me to believe you have a corrupt filesystem. I recommend a fsck, which may correct the data.

Are these files on an LVM volume? If so, it looks as though you may have lost one or more physical or logical volumes in the volume group. This will cause ls -l to show all those question marks, because ls thinks the file is there (as it is listed in the directory inode), but it will be unable to stat it to get permissions, size, ownership, etc. because the inode is not actually present.

I've had this happen to me before, but in my case LVM was being used by a commercial clustered filesystem (IBRIX), so the solution I used was somewhat specific to that product. Novell has a page describing how you might recover from LVM problems here that might be helpful. CentOS has another one here.

However, if this is just a regular old partition with a non-clustered filesystem sitting on it (e.g. ext3 on /dev/sda5, or whatever), then a simple fsck may be all you need to do.

Definitely check your logs and the output from dmesg. If you really did lose a physical or logical volume, you should see errors from LVM or the underlying hardware devices. That will give you some indication of what really happened, which you'll need to know in order to fix it.

Tags:bash, files

Related Articles

  • Delete multiple files with special charactersSeptember 7

    I have a machine containing a large number of files that were originally created on a mac with some sort of special character in the name (not sure what). When I do an ls in a bash terminal, these files show up something like the following: $ ls -al

  • Delete ghost files with special charactersAugust 5

    I have read several ways to delete files with special characters, but none of them works for me in one special folder in my cache system. I have no idea how the files got there, and why they turned into ghost files. if i do: "ls -li" in my cache

  • Can not delete files containing special characters in the file nameDecember 27

    I use Ubuntu 9.10 (Karmic) and I have a directory with many files, among them these two files: ./baer.jpg ./bär.jpg I would like to delete bär.jpg but I can't. If I type rm b and hit TAB, it shows me both files, if I append ä and hit TAB, nothing get

  • bulk rename (or correctly display) files with special charactersJanuary 26

    I have a bunch of directories and subdirectories that contain files with special characters, like this file: [email protected]:~$ ls test�sktest.txt test?sktest.txt Find reveals an escape sequence: [email protected]:~$ find test�sktest.txt -ls 424512 4000 -rwxr-

  • nginx returns 404 on files with special charactersAugust 19

    I just switched over to nginx as a static file server and it works for the vast majority of files but it's throwing a 404 on certain files with special characters. This is Kevin Worthington's 64 bit build of nginx running on Windows Server 2008 R2. M

  • Deleting Multiple FilesOctober 8

    I am deleting multiple files with the command: del /s *.doc *.rtf *.txt I get the error Could Not Find *.doc. How can I get the command to continue deleting RTF and TXT files when there are no more DOC files? I want to use a single command so I can t

  • What is the FTP Command for deleting multiple files as once?March 8

    I'm trying to run this command via FTP in order to delete some files I have stored in a folder in my website: DEL *.csv However this doesn't work and I don't know why. However if I try to delete every single file this works: DEL file.csv (works) How

  • Can't delete multiple files at once in Windows 8November 1

    This is weird, but I can't delete multiple files at once in Windows 8. Files are on my desktop, I'm selecting them with Ctrl+left click. After that delete option is disappearing from the right click menu, delete button on the keyboard also doesn't wo

  • Is there a better way to do this command to find strings in a file excluding special characters?April 11

    Is there a better way to do this command to find strings in a file excluding special characters? Currently I'm doing: strings file.abc | grep -v \= | grep -v \] | grep -v \) | more I'd like to add more special characters so I'm only getting a-z and A

  • Linux - How to copy a list of files with special characters to new directoryAugust 6

    I have a list of files with paths, some of the files have special characters such as spaces, hyphens, single or double quotes like the following: /Music/Allman_Brothers/Filmore_east/The Allman Brothers Band - At The Fillmore East (Disc 2) - 02 - In M

  • Can't echo or create a symbolic link to a file with special characters in its name inside bash scriptNovember 25

    I'm trying to create a symbolic link to files with the following naming convention: .$abc$namehere.zip;1 As can be seen, it has the following special characters in it: . $ ; In my bash script I have the following lines of code: FILE1=`find /mydir/ -n

  • escape files with special characters in copy commandNovember 17

    I'm going to copy many files and folders, some have special characters..how I can copy all files and escape those files with special characters?

  • Delete multiple files in Document DirectoryJanuary 22

    I am trying to create a function that I can delete multiple files in Document Directory with a given file Extension. So far I have the function below but I can I complete it on older to delete the files founds? static func searchFilesDocumentsFolder(

  • Replacing multiple occurences of special characters in java by a single special characterJanuary 25

    I want to remove multiple occurrences of special characters like " ", "-", "!", "_" from my java string by a single underscore "_". I tried replaceAll("([\\s\\-\\!])\\1+","_") and it se

  • PHP indexing files with special characters (RecursiveIteratorIterator)February 7

    I'm using PHP with the RecursiveIteratorIterator-class to get the filenames from a number of folders, the filenames are added to a MySQL database. This works fine, but for some files, something weird is happening. Many files contain special character

  • How to delete file containing special characters in Linux?November 22

    I've created a linux bash file in a windows text editor. This file contained commands for moving files to another location under linux. After i ran this file i discovered that destination files have "\r" symbol in their end. (I guess this is bec

  • Using find and tar with files with special characters in the nameJune 1

    I want to archive all .ctl files in a folder, recursively. tar -cf ctlfiles.tar `find /home/db -name "*.ctl" -print` The error message : tar: Removing leading `/' from member names tar: /home/db/dunn/j: Cannot stat: No such file or directory tar

  • Windows 7 search for files with special characters in nameFebruary 15

    I have a rather large source code repository on my machine; it is not indexed by Windows Search. I am trying to find some oddly-named generated files of the form .#name.extension.version where name and extension are normal names and extensions and ve

  • Delete multiple files on PowerShell command lineDecember 16

    With PowerShell, what is the most concise way to delete multiple explicitly named files? E.g. on *ix it would be: rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif I'm currently using: echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm But I consider

  • How do I rename multiple files by removing characters in bash?December 29

    I have to rename multiple files in directory by removing first 5 characters for each filename. How can I do this i bash/shell? I'm using Ubuntu 11.10. Thanks. --------------Solutions------------- A simple for loop with a bit of sed will do the trick:

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.886 s.