linuxfindls

How do I find files with ampersands in their names in Linux


I would have thought

ls \*\&\*

would work but it doesn't.


Solution

  • When you write ls \*\&\*, you are escaping the wildcard characters (*) so that they are interpreted literally, rather than as wildcards. You are looking for a file with the literal name *&*.

    To list files in the current directory containing &, you would write instead:

    ls *\&*
    

    (or ls *"&"* or ls *'&'*, etc). This way you are escaping only the & character and the * characters continue to have their special meaning.