How to Remove File with Special Characters

How to remove files with special characters

  • Try to add -- at the beginning of the file name.
$ rm -v -- #file
$ rm -v -- "#file"
  • Try to add ./ at the beginning of the file name.
$ rm -v ./#file
  • If the previous tips do not work, you can still remove it using the inode number with:
ls -li

output:

5133242 -rw-r--r-- 1 user #*%/file

then using find

$ find . -inum 5133242 -delete

How to mass remove files that contain special characters in file name

This will delete every file whose name ends in (1), recursively:

find . -name '*(1)' -exec rm {} +
  • -name '*(1) (1)' to only delete files ending with a double 1.
  • -name '*([0-9])' will match any single digit.
  • find . -mindepth 1 -maxdepth 1 -name '*(1)' -exec rm {} + for no recursion.
  • I would do find . -name '*(1)' -exec echo rm {} \; to print a neat list of the rm commands to be executed. Review it, then remove echo to run for real.
  • Changing \; back to + is optional, + is more efficient.

How to remove this special character at the end of the file

It's unclear how the % (percent sign) is ending up in your file; it's easy to remove with sed:

sed -i '' 's/\(</.*>\)%.*/\1/g' file.xml

This will remove the percent and re-save your file. If you want to do a dry-run omit the -i '' portion as this is tells sed to save the file in-line.

As mentioned in the comments, there are many ways to do it. Just be sure you aren't removing something that you want to keep.

How to remove special characters in file names?

Your rename would work if you add the g modifier to it, this performs all substitutions instead of only the first one:

$ echo "$file"
foo bar,spam.egg

$ rename -n 's/[^a-zA-Z0-9_-]//' "$file"
foo bar,spam.egg renamed as foobar,spam.egg

$ rename -n 's/[^a-zA-Z0-9_-]//g' "$file"
foo bar,spam.egg renamed as foobarspamegg

You can do this will bash alone, with parameter expansion:

  • For removing everything except a-zA-Z0-9_- from file names, assuming variable file contains the filename, using character class [:alnum:] to match all alphabetic characters and digits from current locale:

    "${file//[^[:alnum:]_-]/}"

    or explicitly, change the LC_COLLATE to C:

    "${file//[^a-zA-Z0-9_-]/}"

Example:

$ file='foo bar,spam.egg'

$ echo "${file//[^[:alnum:]_-]/}"
foobarspamegg

C++ 17 copy and delete files with special characters in their names on Windows 7 x64?

  1. Go to the header file in which std::filesystem::path is defined.
    (possibly in: PATH_TO_MINGW/usr/include/c++/YOUR_VERSION/bits/fs_path)

  2. Look for using value_type =

  3. Look for compiler macros that define which value_type is ultimately used.

an example from the version from my system:

#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
using value_type = wchar_t;
static constexpr value_type preferred_separator = L'\\';
#else

When the macro _GLIBCXX_FILESYSTEM_IS_WINDOWS is set to 1 then a wchar_t will be used, which should solve your issue.

How to remove special characters from text file

Remove characters that are not within the ascii table (11,12,40-176)

Sample Image

\11 = tab

\12 = new line

\40-176 = ( to ~ this range includes all letters and symbols present in the keyboard

cat test.txt | tr -cd '\11\12\40-\176' > temp && mv temp test.txt

NOTE: If your data has special characters that are not in the ascii table, they might be removed as well



Related Topics



Leave a reply



Submit