Skip to main content
added 2 characters in body
Source Link

With rename

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.


With common bash commands

Since you said that rename is not installed on your system, here's a solution that uses more standard Bash:

for file in *.txt; do
    mv "$file" $"${file%.txt}_1.txttxt"
done

Explanation: We loop over all files. For each file, we move it to the correct location by making use of something called "parameter expansion" (this is the ${} part). The special character % can be used within parameter expansion to match a pattern at the end of the string and delete it.

For further information, see: http://wiki.bash-hackers.org/syntax/pe#from_the_end

With rename

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.


With common bash commands

Since you said that rename is not installed on your system, here's a solution that uses more standard Bash:

for file in *.txt; do
    mv "$file" ${file%.txt}_1.txt
done

Explanation: We loop over all files. For each file, we move it to the correct location by making use of something called "parameter expansion" (this is the ${} part). The special character % can be used within parameter expansion to match a pattern at the end of the string and delete it.

For further information, see: http://wiki.bash-hackers.org/syntax/pe#from_the_end

With rename

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.


With common bash commands

Since you said that rename is not installed on your system, here's a solution that uses more standard Bash:

for file in *.txt; do
    mv "$file" "${file%.txt}_1.txt"
done

Explanation: We loop over all files. For each file, we move it to the correct location by making use of something called "parameter expansion" (this is the ${} part). The special character % can be used within parameter expansion to match a pattern at the end of the string and delete it.

For further information, see: http://wiki.bash-hackers.org/syntax/pe#from_the_end

Add quotes because bash is dangerous...
Source Link

With rename

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.


With common bash commands

Since you said that rename is not installed on your system, here's a solution that uses more standard Bash:

for file in *.txt; do
    mv "$file" ${file%.txt}_1.txt
done

Explanation: We loop over all files. For each file, we move it to the correct location by making use of something called "parameter expansion" (this is the ${} part). The special character % can be used within parameter expansion to match a pattern at the end of the string and delete it.

For further information, see: http://wiki.bash-hackers.org/syntax/pe#from_the_end

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.

With rename

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.


With common bash commands

Since you said that rename is not installed on your system, here's a solution that uses more standard Bash:

for file in *.txt; do
    mv "$file" ${file%.txt}_1.txt
done

Explanation: We loop over all files. For each file, we move it to the correct location by making use of something called "parameter expansion" (this is the ${} part). The special character % can be used within parameter expansion to match a pattern at the end of the string and delete it.

For further information, see: http://wiki.bash-hackers.org/syntax/pe#from_the_end

Source Link

rename .txt _1.txt * should do what you are looking for.

To quote man rename:

rename [options] expression replacement file...

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.