user3667111 user3667111 - 1 year ago 75
Linux Question

Removing the file extension in a text file bash

So I have put a load of names of files in a text file, these are specifically


ls *.log > finished_data.txt

Now that I Have the list of
files, how do I keep the names but remove the
My thought process is renaming them all?

Answer Source

Just loop through the .log files and move them:

for file in *.log
    mv "$file" "${file%.log}"

This uses shell parameter expansion:

$ d="a.log.log"
$ echo "${d%.log}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download