Sample Header Ad - 728x90

How to apply an ls to a file name with spaces in a variable

0 votes
2 answers
135 views
This code my_file="/tmp/file_without_spaces" if [ -f "${my_file}" ]; then my_ls_aaaammgg_hhss="$(ls ${my_file} -l --time-style='+%Y%m%d_%H%M%S' | cut -d' ' -f6)" mv "${my_file}" "${my_file}_${my_ls_aaaammgg_hhss}" fi changes /tmp/file_without_spaces into /tmp/file_without_spaces_aaaammgg_hhss, for example /tmp/file_without_spaces_20250218_161244. How can I do the same thing with a file with spaces in its name, for example /tmp/file with spaces ? I would like to get /tmp/file with spaces_20250218_161244.
Asked by CarLaTeX (331 rep)
Feb 18, 2025, 03:22 PM
Last activity: Feb 18, 2025, 07:21 PM