How to access directory with non-ascii, \n character in dir name
I have some data saved in a directory which has a non-ascii character in the name, how can I access the data within?
The directory appears as:
w0p6_t[[0.53.5]?[1.71.2]]
But escaping the special characters using \
before them does not work, nor does surrounding the directory name with quotes as suggested here.
I believe this "?" is a new line character (ascii \012
) as ls -lb
returns:
w0p7_t[[0.53.5]\n[1.71.2]]
I can see the contents of the directory using the tree
command, which shows the directory as:
w0p6_t[[0.53.5]\012[1.71.2]]
along with all of its content.
I have also tried:
cd "w0p7_t[[0.53.5]\n[1.71.2]]"
cd "w0p7_t[[0.53.5]\012[1.71.2]]"
and
cd w1p0_t\[\[0.53.5]\\012\[1.71.2\]\]
cd w1p0_t\[\[0.53.5]\\n\[1.71.2\]\]
with no success.
Also, attempting to auto-complete the command using Tab does not prompt suggestions for this directory.
Solution 1:
Here are a couple of ways (there are likely more)
-
an unquoted
?
will match any single character - including the newline character. So for examplecd w0p6_t\[\[0.53.5\]?\[1.71.2\]\]
or
cd 'w0p6_t[[0.53.5]'?'[1.71.2]]'
-
you could use bash
$'string'
ANSI escaping to expand a\n
sequencecd $'w0p6_t[[0.53.5]\n[1.71.2]]'