Cool Bash Commands

Remove the ABCD– prefix from a filename:
$ s='ABCD --11212239.pdf'
$ mv "$s" "${s#ABCD--}"


Remove the prefix from all files in current directory recursively:
while IFS= read -r -d '' filename; do
mv "$filename" "${filename#ABCD--}"
done < <(find . -type f -name 'ABCD--*' -print0)

Remove the .pdf suffix from a filename:
$ s='ABCD --11212239.pdf'
$ mv "$s" "${s%.pdf}"


Remove the suffix from all the files in the current directory recursively:
while IFS= read -r -d '' filename; do
mv "$filename" "${filename%.pdf}"
done < <(find . -type f -name '*.pdf' -print0)

About vicki

Welcome to the Sovereign Republic of Vickistan. I am the President here. Lucky me! No taxes or laws yet. Lucky you!
This entry was posted in Linux. Bookmark the permalink.