You can also use History Expansion to refer to words on the current command line:
convert -trim -density 400 this_is_a_very_long_filename_of_my_pdf_file.pdf !#:$:r.png
- Event designator
!# refers to the command line typed so far
- Word designator
$ indicates the last word (before the expansion)
r removes the file extension. This also marks the end of the text, which is replaced when history expansion occurs.
.png is the new extension. This does not belong to the expansion itself.
When this line is run,
!#:$:r is replaced by the name of your pdf file minus the extension, thus creating the command from the question:
convert -trim -density 400 this_is_a_very_long_filename_of_my_pdf_file.pdf this_is_a_very_long_filename_of_my_pdf_file.png
This line is then directly executed.
If you want to check the command after history expansion, before execution, use
This will reload the expanded line into the editing buffer instead of executing it.
Note: Unlike any other expansion, history expansion is performed before the command is saved to the history. So
echo !# will appear as
echo echo and not as
echo !# in your