2

I have something odd. I creates some directories using a very simple script :

... create all directories ( running under a user that has the correct rights ) e.g :

mkdir -p /home/EAI003A/05_EDSNFE/ISU2EAI/VEA/tre

But I get the directories double ! When I do ls -lrt I get

uxel081c: wmb - /home/EAI003A/05_EDSNFE/EAI2ISU/VEA # ls -lrt
total 0

drwxr-xr-x    2 wmb      mqbrkrs         256 Jan 28 15:25 tre
drwxr-xr-x    2 wmb      mqbrkrs         256 Jan 28 15:25 err
drwxr-xr-x    2 wmb      mqbrkrs         256 Jan 28 15:25 arc
drwxr-xr-x    2 wmb      mqbrkrs         256 Jun 12 08:35 tre
drwxr-xr-x    2 wmb      mqbrkrs         256 Jun 12 08:35 tbt
drwxr-xr-x    2 wmb      mqbrkrs         256 Jun 12 08:35 err
drwxr-xr-x    2 wmb      mqbrkrs         256 Jun 12 08:35 arc
drwxr-xr-x    2 wmb      mqbrkrs         256 Jun 13 10:49 tbt

(notice the double tre, tbt , arc ... )

They double directories do point to the same data.

When you do a normal ls you get

uxel081c: wmb - /home/EAI003A/05_EDSNFE/EAI2ISU/VEA # ls
    tre  tre

Thus only two directories !

What happens ?

  • Welcome on StackExchange. Could you post the whole script you use to create the directories, please? The problem probably is there, unless ls and mkdir have strange behaviour on your system (due to aliases, for example). Also, could you post the output of ls -lrti? – lgeorget Jun 17 '13 at 13:45
  • Thank you for your reply ! Two more points that I need to mention a) This is a NAS share - thus not a local drive) b) The directories existed already ( manually manualy) prior to executing the script. Nevertheless this is a way of working and it is only now that we see an issue. – Laurens Jun 17 '13 at 14:12
  • The outcome from lrti wmb - /home/EAI003A/05_EDSNFE/EAI2ISU/VEA # ls -lrti total 0 98332 drwxr-xr-x 2 wmb mqbrkrs 256 Jan 28 15:25 tre 98333 drwxr-xr-x 2 wmb mqbrkrs 256 Jan 28 15:25 err 98334 drwxr-xr-x 2 wmb mqbrkrs 256 Jan 28 15:25 arc 98802 drwxr-xr-x 2 wmb mqbrkrs 256 Jun 12 08:35 tre 98801 drwxr-xr-x 2 wmb mqbrkrs 256 Jun 12 08:35 tbt 98800 drwxr-xr-x 2 wmb mqbrkrs 256 Jun 12 08:35 err 98799 drwxr-xr-x 2 wmb mqbrkrs 256 Jun 12 08:35 arc 98331 drwxr-xr-x 2 wmb mqbrkrs 256 Jun 13 10:49 tbt – Laurens Jun 17 '13 at 14:14
  • My script ( be dazzled)mkdir -p /home/EAI003A/05_EDSNFE/EAI2ISU/VEA/arc mkdir -p /home/EAI003A/05_EDSNFE/EAI2ISU/VEA/err mkdir -p /home/EAI003A/05_EDSNFE/EAI2ISU/VEA/tbt mkdir -p /home/EAI003A/05_EDSNFE/EAI2ISU/VEA/tre – Laurens Jun 17 '13 at 14:16
  • When I said "post this or that", I meant "update your question". It's quite difficult to read code when it's not properly formatted and indented :). – lgeorget Jun 17 '13 at 14:25
2

If I had to hazard a guess I'd be suspicious of the files and whether they have non-printable characters in their names. You can display these special characters through the use of the following switches to ls.

excerpt from Removing Non-printing Characters from File Names

Locating "non-printing" characters in file names

The ls command has all the options you need to detect "hidden" characters:

Command      Function                                         Sample Output
-------      --------                                         ------ ------
ls           hides/interprets nongraphic characters           zzz
ls -b        prints octal codes for nongraphic characters     zzz\010\010\010aaa
ls -q        prints question marks for nongraphic characters  zzz???aaa

See the above referenced page for more information on these types of characters and there removable.

0

My guess is that you edited your script on Windows at some point, and that version had Windows line endings: a CR (carriage return) followed by a LF (line feed). As far as Unix shells are converned, LF is the line ending character, and CR is an ordinary character. So if you have this in your script (where ␍ is a CR character):

mkdir -p /home/EAI003A/05_EDSNFE/ISU2EAI/VEA/tre␍

then in your editor you'll only see

mkdir -p /home/EAI003A/05_EDSNFE/ISU2EAI/VEA/tre

but the shell sees that the mkdir command is called with the arguments -p and /home/EAI003A/05_EDSNFE/ISU2EAI/VEA/tre␍.

When the CR character is printed onto a terminal, its effect is to move the cursor to the beginning of the line. With ls -l, CR only turns up at the end of the line and so has no visible effect. With plain ls, the CR at the end of every second file name causes the next pair of file names to overwrite the previous lines.

Convert your script to use Unix line endings with one of these commands:

dos2unix /path/to/script                # if dos2unix is available
sed -i -e $'s/\r//' /path/to/script     # on Linux or Cygwin only
perl -i -e 's/\r$//' /path/to/script

Your editor may have a way to do that, too. In your editor, when you edit a shell script, check that the line endings are “LF” or “Unix” or “Linux” and not “CRLF” or “Windows” or ”DOS“.

Depending on your unix variant, try ls -b or ls -Q or ls -q to make the special character in the file name appear. To merge the two directories, first move the files into the proper directory, then remove the other one.

mv -i tre/* tre?/
rmdir tre?/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.