“Programming is like sex, one mistake and you have to support it for the rest of your life.” — Michael Sinz
All articles
Last comments
me again
If you would like to backup your system to ISO- disk image or clone a partition.
humble pie
I think it works, Mint 18 xfce. Have installed clonezilla from the mint package manager, called it [sudo clonezilla] and it opened.
hoek
This is awesome!
david mabitsi
i cant seem to be winning uninstalling linux mint 17.2
Archive
«    December 2016    »
MonTueWedThuFriSatSun
 1234
567891011
12131415161718
19202122232425
262728293031 
» » How to remove spaces in file names?

How to remove spaces in file names?

How to remove spaces in file names?

Spaces in file names very often can create a lot of "hemorrhoids". Who works in the console, that will understand me. Recently there was a need to mass encode a group video files from one format to another. But the script didn't work because the file names were these unfortunate spaces. 

Sorry for the spelling and phonetic errors in the text.
Owner and main writer of MintGuide.org is not a native English speaker.


Instead of spaces appeared underscores need to go to the desired directory and execute the command or script. To do this, go to the directory:
cd /path to directory/
And now let's execute the following script, which will replace the spaces with underscore characters, or any other desired character:
 
#!/bin/sh
for i in *.avi
do
k=`echo ${i}|sed s/' '/'_'/g`
mv "${i}" ${k}
done
Instead of *.avi put your extension files in which you need to make name changes. Or, you can simply transfer the desired file extensions, then the script will have the following form:
 
#!/bin/sh
for i in *.mp4 *.txt *.avi *.html *.odt
do
k=`echo ${i}|sed s/' '/'_'/g`
mv "${i}" ${k}
done
But Linux wouldn't be Linux if there wasn't masses of ways to solve the problem. So to combat the spaces you can run other commands using other utilities or programs. You can use the rename utility:
rename 's/ /_/g' *
But if after work on those files you want back again with spaces in the names, then run the command:
rename 's/_/ /gi' *.mp4 *.txt *.avi *.html *.odt
This command in batch mode replace the underscore for a space.
Good Luck!!!
 
 

Related articles

Add a comment

  • bowtiesmilelaughingblushsmileyrelaxedsmirk
    heart_eyeskissing_heartkissing_closed_eyesflushedrelievedsatisfiedgrin
    winkstuck_out_tongue_winking_eyestuck_out_tongue_closed_eyesgrinningkissingstuck_out_tonguesleeping
    worriedfrowninganguishedopen_mouthgrimacingconfusedhushed
    expressionlessunamusedsweat_smilesweatdisappointed_relievedwearypensive
    disappointedconfoundedfearfulcold_sweatperseverecrysob
    joyastonishedscreamtired_faceangryragetriumph
    sleepyyummasksunglassesdizzy_faceimpsmiling_imp
    neutral_faceno_mouthinnocent
Login via
Up