Suppose you have a directory of files, and all of the files have a common prefix that is a certain number of characters long, and you want to take the prefix off. Your directory looks like this:
[alan@shitfit testdir]$ ls
000-lol.zip 001-rofl.txt 002-roflmfao.jpg
So to get rid of the numbers and dashes in all of the files, you can do something like this:
for F in *; do mv $F ${F:4}; done
The ${F:4} bit tells Bash to print the string $F starting at the 4th character. It turns out Bash does all kinds of things with strings, as you can see here.
So, your result will look like this:
[alan@shitfit testdir]$ ls
lol.txt rofl.txt roflmfao.jpg
To tune your renaming to a certain file extension, you might use:
for F in *.txt; do mv $F ${F:4}; done
You have a number of options available, and all of them involve a loop, some kind of formatting approach, and the mv command. Micha suggested using find and piping the results to while, read, sed, and mv. This guy does something like that to match the beginnings of filenames to a pattern.
Presto.
Comment
Turning Off Mail Notifications In Bash, Part 2 Comment Visual Selection Blocks in Vim
Thanks for the tip, made my day!
— Florian Brucker · Jan 7, 04:28 PM · #
order propecia [url=“http://www.bmbvideo.com/propecia.html”]order propecia[/url] http://www.bmbvideo.com/propecia.html order propecia buy ambien [url=“http://www.bmbvideo.com/ambien.html”]buy ambien[/url] http://www.bmbvideo.com/ambien.html buy ambien tramadol [url=“http://www.bowlinginlubbock.com/Tramadol.htm”]tramadol[/url] http://www.bowlinginlubbock.com/Tramadol.htm tramadol
— ahtis_ausstellung · Dec 9, 07:16 AM · #
Hi! kWkRbJUg http://isamyy.com/
— viagra · Jan 21, 06:08 PM · #
YGpZxEL
— OFysxFXH · Feb 2, 07:30 PM · #
U57TDQ sefedpidgfpw, [url=http://jdfmofsvwsvc.com/]jdfmofsvwsvc[/url], [link=http://ueoikjiebzwx.com/]ueoikjiebzwx[/link], http://keoyimmazamw.com/
— folejo · Feb 6, 06:34 AM · #