Reply
Thread Tools
Posts: 25 | Thanked: 10 times | Joined on May 2010
#1
I want to be able to rename all .jpg files in a directory to .jp1 using xterm.

I tried the rename command, but it doesn't seem to exist.

I tried the xargs commands here, but xterm dislikes the -i switch:
http://puschitz.com/pblog/?p=31

Any ideas?
 
eitama's Avatar
Posts: 702 | Thanked: 334 times | Joined on Feb 2010 @ Israel.
#2
# change .htm files to .html
for file in *.htm ; do mv $file `echo $file | sed 's/\(.*\.\)htm/\1html/'` ; done

From :
http://lab.artlung.com/unix-batch-file-rename/
__________________
| Developer of Horizontal-Call - Call your contacts, fast! |
| Reverse SSH - access your N900 from anywhere, anytime |
| Using Samsung Galaxy S GT-i9000 and Nokia N900 |
| DonateMe - If you feel I helped you in a very good way, feel free to donate |
 

The Following User Says Thank You to eitama For This Useful Post:
Posts: 303 | Thanked: 175 times | Joined on Oct 2009 @ London UK
#3
Ouch.. calling sed for each file, and not space filename safe

try this.. to rename all files in the current directory and below (including sub-directories).

find . -type f -name "*.jpg" | while IFS="" read file ; do mv "$file" "${file%.jpg}.jp1" ; done


If you want to rename only the files in the current directory, and not any files in sub-directories below:

for file in *.jpg ; do mv "$file" "${file%.jpg}.jp1" ; done


${file%.jpg} => strip ".jpg" from the end of $file
${file%.jpg}.jp1 => Strip .jpg1 from end of $file, then append .jp1

file=fish.jpg
fish.jpg => fish.jp1

neat
 

The Following User Says Thank You to cpitchford For This Useful Post:
Posts: 25 | Thanked: 10 times | Joined on May 2010
#4
Thank you both.

cpitchford, I used your first example, and it worked great!

Thanks again.
 
Reply


 
Forum Jump


All times are GMT. The time now is 21:51.