Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing part of a filename for multiple files on Linux

Tags:

linux

bash

shell

People also ask

How do I partially rename multiple files at once?

Click the Select all button. Quick tip: Alternatively, you can also use the Ctrl + A keyboard shortcut to select all files. You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.

How do you cut a filename in Linux?

You should be using the command substitution syntax $(command) when you want to execute a command in script/command. name=$(echo "$filename" | cut -f 1 -d '. ')

How do I delete multiple files with the same name in Linux?

To delete multiple files at once, use the rm command followed by the file names separated by space. When using regular expansions, first list the files with the ls command so that you can see what files will be deleted before running the rm command.

How do I delete a filename in multiple files?

Alternatively, head to the folder containing the files you want to delete, hit Shift + Right Click, and select Open a command window here. Then input "del [filename]" and press Enter.


First of all use 'sed -e' instead of '\e'

And I would suggest you do it this way in bash

for filename in *.fasta; do 
    [ -f "$filename" ] || continue
    mv "$filename" "${filename//test.extra/}"

done

Try rename "extra.test" "" *

Or rename 's/extra.test//;' *

$ find
./extra.test-eggs.txt
./extra.testbar
./fooextra.test
./ham-extra.test-blah

$ rename "extra.test" "" *
$ find
./-eggs.txt
./bar
./foo
./ham--blah

I know this tread is old, but the following oneliner, inspired from the validated answer, helped me a lot ;)

for filename in ./*; do mv "./$filename" "./$(echo "$filename" | sed -e 's/test.extra//g')";  done

Try the rename command:

rename 's/test.extra//g' *.fasta

$ mmv '*test.extra*.fasta' '#1#2.fasta'

This is safe in the sense that mmv will not do anything at all if it would otherwise overwrite existing files (there are command-line options to turn this off).


 // EXTENSION - File extension of files
 // STRING - String to be Replace

      for filename in *.EXTENSION;
      do  [ -f "$filename" ] || continue;  
      mv "$filename" "${filename//STRING/}"; 
      done