[lug] Newline in a filename

D. Stimits stimits at idcomm.com
Sun Nov 11 10:31:34 MST 2001

"Timothy C. Klein" wrote:
> Hello,
> I am writing a Perl script that renames files.  I forgot to chomp some
> input after I read it from a file, and thus renamed a file with a
> newline in the file name.  It looks like this in a directory listing
> cp9-dc_0043?-0510.jpg
> The question mark is the new line.  When I try to delete by using tab
> expansion, the question mark turns into a newline, confusing things.  I
> am not sure how to escape the new line character.  How can I delete this
> guy?

Wildcards are one way. Test them first with ls, e.g.:
ls -aF abc.txt?
...this will test for files named abc.txt, but with any additional
character at the end. A newline would qualify.

The second possibility is to quote your file names, and for the newline
portion, precede with the "literal quote" sequence, control-v. So if you
hit control-g on a regular console (maybe on xterms, depends on setup),
you'd get a bell; if you use control-v control-g, then you'd see ^g and
it would not be interpreted. To quote return key, use control-v return.
The above sample might instead look like:
ls -aF "abc.txt^J".

D. Stimits, stimits at idcomm.com

> Tim
> --
> ==============================================
> == Timothy Klein || teece at silverklein.net   ==
> == ---------------------------------------- ==
> == "Hello, World" 17 Errors, 31 Warnings... ==
> ==============================================
>   ------------------------------------------------------------------------
>    Part 1.2Type: application/pgp-signature

More information about the LUG mailing list