LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   [SOLVED] How Can I Change the Label of My Mounted USB Flash Drive? (https://www.linuxquestions.org/questions/linux-general-1/%5Bsolved%5D-how-can-i-change-the-label-of-my-mounted-usb-flash-drive-4175425754/)

wguayan 09-05-2012 06:26 AM

[SOLVED] How Can I Change the Label of My Mounted USB Flash Drive?
 
How can I change the label of my USB mounted in /media. The file name has spaces in it.

I tried using
Quote:

rename 'y/ /_/' *
on the device name and that doesn't work. Normally I would use e2label /media/usb newlabel, but it's a FAT32 file system.

Anyway, any help would be appreciated.

tronayne 09-05-2012 07:07 AM

Looking at the man page for rename (possibly a different version than yours) the syntax is
Code:

rename from to file ...
with an example for fixing HTM to HTML files:
Code:

rename .htm .html *.htm
So I would expect that
Code:

rename file\ name file_name file\ name
might work for you -- you use the back slant to "escape" the blank in the file name.

This all assumes, of course, that you can write on the device (and I don't really know if that's possible -- try it on something you don't care about, eh).

Hope this helps some.

Just as an aside, I have this little utility that renames blanks in file name to underscores; I don't know who the author is or where I got it (sorry!), but it might be of use when dealing with Miserydos files:
Code:

cat blank-rename.sh
#!/bin/bash
ONE=1                                # For getting singular/plural right (see below).
number=0                        # Keeps track of how many files actually renamed.
FOUND=0                                # Successful return value.

for filename in *                # Traverse all files in directory.
do
    echo "$filename" | grep -q " "        #  Check whether filename
    if [ $? -eq $FOUND ]                  #+ contains space(s).
    then
      fname=$filename                      # Yes, this filename needs work.
      n=`echo $fname | sed -e "s/ /_/g"`  # Substitute underscore for blank.
      mv "$fname" "$n"                    # Do the actual renaming.
      let "number += 1"
    fi
done 

if [ "${number}" -eq "$ONE" ]                # For correct grammar.
then
        echo "${number} file renamed."
else
        echo "${number} files renamed."
fi

exit 0


wguayan 09-05-2012 08:52 PM

That did it, works great. Thank you so much!


All times are GMT -5. The time now is 05:32 PM.