How to Manipulate Filenames Having Spaces and Special Characters in Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

6 Responses

  1. Carlos Martins says:

    Hi Dear,

    I’m creating the shell script needs to copy files. This script has three parameters, the first parameter is the file.txt that contains list of files, 2nd parameter is location of the files and last parameter is destination path.

    I’m facing problem when I have to copy files whose filename has white space.

    Can you help me with that?

  2. alimp5 says:

    Thanks a lot, really great article with good practical examples..

  3. Kishore says:

    Regarding the terminal argument ” touch *12.txt ” may open up more than one file if you have a file named a12.txt , b12.txt etc in a text editor like Geany or the first file in alphabetical order in Nano .

  4. Naveen says:

    We can eliminate this issue by passing the file name is single quote to solve the special characters present in the file.

    Eg: touch ‘₹@@%%@’

  5. inukaze says:

    Hi there i have a lot of files with [!] in their namefiles , i need move just that files inside another sub-folder , i try with

    for file in $(ls | grep -e “.[!]]” | awk ‘NF { print “\””$0″\””}’); do mv -f “$PWD/$file” “$PWD/Folder001/” ; done

    but is imposible , because bash in “do mv -f “$PWD/$file”
    reads the “This is an example of large filename.ext” like

    This -> File1
    is -> File2
    an -> File 3
    example -> File 4
    of -> File 5
    large -> File 6
    filename.ext -> File 7

    How i can use “mv” for large filename with special characters like [!](EJU) to another folder ???

  6. MaxIo_Yu says:

    it’s easy to create such files, “” will resolve all the situation, but it’s hard to process them in your script or command.
    the most ugly file name I have seen it’s “xxx “, since when i list it in terminal, I cannot know how many spaces the name inlcuded. but if it’s in script, it will have no problem to get the name through API

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.