Removing characters from a file name in linux

bash

Rate this post

Below is a little snippet to rename files in a linux directory.
This code will loop through all the text files in a directory and remove the first 10 characters

[bash]
#!/bin/bash
for i in *.txt
do
mv $i ${i:(10)}
done
[bash]

To remove everything before the last 10 characters
[bash]
#!/bin/bash
for i in *.txt
do
mv $i ${i:(-10)}
done
[bash]

Related posts: