home | list info | list archive | date index | thread index

Re: Directory starting with ''$'\n''

Another option for deleting the file could be using 'find' to get a precise
pattern match syntax for just the one file, and then re-run the exact same
command, adding the -delete option.

$ touch $'\nbad_file'
$ find . -maxdepth 1 -name '*bad*'
./?bad_file
$ find . -maxdepth 1 -name '*bad*' -print
./?bad_file
$ find . -maxdepth 1 -name '*bad*' -print -delete
./?bad_file
$ find . -maxdepth 1 -name '*bad*' -print
$

and the bad_file could be renamed to a new_name with this find/xargs
combination, using null separation (find -print0 & xargs -0 )
$ touch $'\nbad_file'
$ find . -maxdepth 1 -name '*bad*' -print
./?bad_file
$ find . -maxdepth 1 -name '*bad*' -print0 | xargs -r -IFILE -0 mv FILE
new_name
$ ls
new_name

Regards,
  Kelvin


On Sat, Nov 29, 2025 at 9:48 AM Dianne Skoll via linux <
linux [ at ] linux-ottawa [ dot ] org> wrote:

> On Sat, 29 Nov 2025 02:18:59 -0800
> Ron via linux <linux [ at ] linux-ottawa [ dot ] org> wrote:
>
> > $ touch $'\nbad_file'
> > $ rm bad_file ## tab completion supplied the file name
> > rm: cannot remove 'bad_file': No such file or directory
>
> When I try it, tab completion (I use bash) works for me:
>
> $ touch $'\nbad_file'
> $ ls
> ''$'\n''bad_file'
> $ rm '
> bad_file'
> $ ls
>
> I typed rm <TAB> and it completed correctly.
>
> > And, wildcards fail too, in some cases:
>
> A wildcard inside single quotes is not expanded; that's expected.
> rm *bad* should work:
>
> $ touch $'\nbad_file'
> $ rm -v *bad*
> removed ''$'\n''bad_file'
>
> > One part I won't retract is my contention that support for line feeds
> > in file names is a bad idea.
>
> Well, maybe, but that's certainly not going to change at the kernel
> level at this point.  It would be considered a change that breaks
> user-space.  And if the kernel supports it, user-space tools are
> obliged to as well... otherwise, someone could create a file that
> really *can't* be renamed or deleted with standard tools.
>
> Regards,
>
> Dianne.
>
> To unsubscribe send a blank message to linux+unsubscribe [ at ] linux-ottawa [ dot ] org
> To get help send a blank message to linux+help [ at ] linux-ottawa [ dot ] org
> To visit the archives: https://lists.linux-ottawa.org
>
>

message navigation