4 Replies Latest reply on Jun 28, 2012 4:42 PM by Dude!

    directory name with trailing question mark

    EdStevens
      Oracle Linux 5.7 64bit running under Virtual Box

      Trying to remove an empty directory, instead of removing it, it simply renamed it with a non-printable character. I normally do this with 'rm -fR mydir' but decided to expand a bit and use rmdir instead.
      [oracle@vblnxsrv03 db_1]$ pwd
      /u01/app/oracle/product/11.2.0/db_1
      [oracle@vblnxsrv03 db_1]$ cd ..
      [oracle@vblnxsrv03 11.2.0]$ rm db_1
      rm: cannot remove `db_1': Is a directory
      [oracle@vblnxsrv03 11.2.0]$ rmdir db_1
      [oracle@vblnxsrv03 11.2.0]$ pwd
      /u01/app/oracle/product/11.2.0
      [oracle@vblnxsrv03 11.2.0]$ ll
      total 4
      drwxrwxr-x 2 oracle oinstall 4096 Jun 26 17:49 db_1?
      an 'ls -b' showed 'db_1\r'


      so, what's going on here?
        • 1. Re: directory name with trailing question mark
          Dude!
          What happens if you press the <tab> key to expand the name, for instance:

          <pre>
          rm -r db_1<tab><Return>
          </pre>

          What happened? Perhaps the directory was created by a shell script that was created under MS Windows and moved to Linux without converting proper line endings. Windows uses \r\n line-breaks. Linux and Unix uses only \n.
          • 2. Re: directory name with trailing question mark
            EdStevens
            Dude wrote:
            What happens if you press the <tab> key to expand the name, for instance:

            <pre>
            rm -r db_1<tab><Return>
            </pre>

            What happened? Perhaps the directory was created by a shell script that was created under MS Windows and moved to Linux without converting proper line endings. Windows uses \r\n line-breaks. Linux and Unix uses only \n.
            Yes, the directory was created from a shell script originally written in notepad on the host Windows os, and placed in a folder that was defined as a 'host share' to the guest Linux server. But when I open that script in vi on the linux server, it shows no "abnormalities" ... like a "^M" at the end of every line. But this is just one small piece of much larger process that has had me running in circles for several days now, so I couldn't swear to all the details leading up to this. I do vaguely remember opening one of the shell scripts in vi and manually deleting that '^M' from every line instead of using 'dos2unix', so maybe I did shoot myself in the foot.

            haven't been able to reproduce the problem in a controlled test. How do I delete this directory now? Tried both rmdir and rm -fr, with the bogus name in both single and double quotes. Neither command complained, but also did not remove the directory.

            Edited by: EdStevens on Jun 28, 2012 10:18 AM
            • 3. Re: directory name with trailing question mark
              Dude!
              You can press <esc> and type "set list / set nolist" at the vi ":" prompt to show or suppress hidden characters. Alternatively you can also use the "cat -v <filename>" at the shell prompt to show hidden characters in a file.

              There are plenty of options to remove bad line endings in files. If you use vi you can use "%s/^M//g". Use <ctrl-v><ctrl-m> to create ^M.

              To remove the directory, did the <tab> key for filename completion not work? Do you use the bash command shell?

              Edited by: Dude on Jun 28, 2012 8:26 AM
              • 4. Re: directory name with trailing question mark
                Dude!
                Here is the prove:

                Install the unix2dos utility:

                <pre>
                # yum -y install unix2dos
                </pre>

                Create a shell script that creates a directory and convert it to DOS:

                <pre>
                $ echo "mkdir db_1" > a
                $ unix2dos a
                unix2dos: converting file a to DOS format ...
                $ cat -v a
                mkdir db_1^M

                $ chmod u+x a
                </pre>

                Execute the script and test deleting the diretory using various methods:

                <pre>
                $ ./a
                $ ls -b
                a db_1\r

                Typing db_1<tab>:

                $ rm -r db_1^M/
                rm: remove directory `db_1\r'? y

                ls -b
                a
                ./a

                Typing db_1<ctrl-v><ctrl-m>:

                $ rm -r db_1^M/
                rm: remove directory `db_1\r'? y

                </pre>
                1 person found this helpful