1

I have a bash script which copies data across to a USB stick. It works. The data is copied across fine, but the filenames are always changed. They are the same as they were before, but any longer names are cut to only 8 chars long, and have an extension that is only 3 chars long (11 char max total).

So an original file called "willGetCutShorter.html" becomes "willGetS.htm" on the drive, whereas "small.txt" stays the same. Copied directory names are cut in the same way, all appearing 8 chars long (they have no extension, of course).

I don't want this to happen. I want the file and directory names to not be modified at all. I don't know why this is happening either.

In my bash script, I copy everything in my computer directory to the drive using an asterisk to represent all the computer directory contents. I'm wondering if this is why? Perhaps cp is only grabbing part of the filename?

Also, while in Linux the files appear all in lowercase, even stuff that was originally part uppercase. In Windows however, all files and folders are uppercase.

Why?

EDIT #1

I formatted the USB drive on a Windows 7 machine before I started using it in this way. In my /etc/fstab file I have added an entry for the drive that mounts it as msdos. This was because I read a manual page (probably 'man mount') and it said that the drive format, which is FAT32, is covered by msdos.

I wanted to mount it with FAT32 as the filesystem type, but I couldn't see that option in the mount manual page. The fstab entry means the mount command consists of only this:

sudo mount /mnt/

The copy commands in the bash script are all like this:

cp -f -r /path/to/dir/* /mnt/to/dir/

It sounds like I just need to reformat the drive to something else, or mount it slightly differently?

9

I suspect you are using a mount command like the one below:

      mount -t msdos /dev/XYZ /mnt/test

This will force the partition to be mounted in legacy DOS FAT filesystem which uses the 8.3 filename convention (See https://en.wikipedia.org/wiki/8.3_filename) instead of vfat which uses Long filenames (https://en.wikipedia.org/wiki/Long_filename).

Recommend using either of the below options for mount:

      mount /dev/XYZ /mnt/test     (by default uses vfat, if it is FATXX formatted USB stick)

or

      mount -t vfat /dev/XYZ /mnt/test  (explicitly mount as vfat, if it is FATXX formatted USB stick)
  • You're completely correct, thank you. My /etc/fstab file included an entry that mounts the filesystem as type msdos because with my very limited knowledge of filesystems I thought that was the right one. In the manual page for mount there was no FAT32 option which is what the drive is formatted to. It looks like vfat covers FAT32 so when I changed the type to vfat it still mounted perfectly, but my problem with the filenames changing was fixed. Thanks a lot! – user179130 Jul 13 '16 at 6:12
6

It is probably the file-system on the usb-storage. FAT file system can only support file-names of 8+3 characters. This file-system is very old. It is only needed for backwards compatibility with very old systems.

FAT also only support upper-case characters. As this is only one case, there is an option to map this to lower-case. This makes thing more convenient. As you do not have to type in capitals, and directory listings do not look shouty.

Consider using FAT32, ntfs, ext4, something else.

  • You're correct, thank you. Another little thing learned! – user179130 Jul 13 '16 at 6:13

Your Answer

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