In the zsh shell: $ pathname=/home/paulo/paulo.pdf $ printf '%s\n' $pathname:t:r paulo The :t modifier ("tail") extracts the last pathname component in $pathname (it works like basename). The :r modifier ("root", I suppose) extracts the bit of the filename up to the extension, if there is one. The extension is the part of the filename that occurs after ...


You can use the shell’s parameter expansion modifiers: $ pathname="/home/paulo/paulo.pdf" $ filename=${pathname##*/} $ printf "%s\n" "$filename" paulo.pdf $ basename=${filename%.*} $ printf "%s\n" "$basename" paulo ${pathname##*/} is expanded to the contents of pathname, minus the longest prefix matching */, i.e. the full path (if there is one). ${filename%...


fdupes sounds quite smart, but it does match all the files together. You could use a couple of the same techniques more optimally if you already have a single file that you want to match. You could start by getting the file size of foo.pdf, and constructing a find command that matches the exact size only. That should be a cheap shortlist. Then you could ...


Tell me if this does work (won't be fast): find /home/user -type f -name "*.pdf" -exec md5sum {} + 2> /dev/null | uniq -f2 -D


This should do what you want: pathname="/home/paulo/paulo.pdf" printf "%s\n" "$(basename $pathname)" | sed "s/\..*$//"

Only top voted, non community-wiki answers of a minimum length are eligible