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 therm
commands to be executed. Review it, then removeecho
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 variablefile
contains the filename, using character class[:alnum:]
to match all alphabetic characters and digits from currentlocale
:"${file//[^[:alnum:]_-]/}"
or explicitly, change the
LC_COLLATE
toC
:"${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?
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
)Look for
using value_type =
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)
\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
How to Compile a Node C++ Addon So That I Can Use Distribute It on Amazon Aws
Is There a Rpm File Naming Convention in Lsb
Xfs - How to Not Modify Mtime When Writing to File
How to Change Port Gitlab on Centos 6
Authenticating Gtk App to Run with Root Permissions
How to Set Environment Variable Within Gdb Using Shell Command
I Need a Tcp Option (Ioctl) to Send Data Immediately
How to Convert Absolute Path to Relative in C Linux
How to Get The Output of at Command in Current or Another Terminal Window
Difference Between Starting a Command Using Init.D Script and Service Start
How to Restrict Access to Certain Files for a Certain Process