LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


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

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
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.

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

Rep: Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844
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

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

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


Reply


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


All times are GMT -5. The time now is 07:35 AM.

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