Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-05-2012, 06:26 AM   #1
LQ Newbie
Registered: Aug 2012
Posts: 6

Rep: Reputation: Disabled
[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
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.

Last edited by wguayan; 09-05-2012 at 08:52 PM.
Old 09-05-2012, 07:07 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
Looking at the man page for rename (possibly a different version than yours) the syntax is
rename from to file ...
with an example for fixing HTM to HTML files:
rename .htm .html *.htm
So I would expect that
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:
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.
     echo "$filename" | grep -q " "         #  Check whether filename
     if [ $? -eq $FOUND ]                   #+ contains space(s).
       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"

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

exit 0

Last edited by tronayne; 09-05-2012 at 07:31 AM. Reason: Fumble finger
Old 09-05-2012, 08:52 PM   #3
LQ Newbie
Registered: Aug 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
That did it, works great. Thank you so much!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /dev/disk/by-label DISAPPEARED! Can't mount USB flash drive ShellyCat Linux - Desktop 5 11-16-2010 11:30 PM
I do not want icon for usb flash drive on my desktop (but I do want it mounted) taylorkh Ubuntu 2 08-25-2008 11:49 AM
can't change the disk label of my new 500gig usb drive oskar Linux - Hardware 12 08-01-2007 06:14 PM
how come usb flash drive doesn't get auto mounted? darkhatter Fedora 5 02-26-2006 08:04 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration