script to timestamp files with timestamp from directory
If I want to change the timestamp for files and use the timestamp from the directory that contains these files. For this I can use:
Code:
touch -r ./<directory-XYZ> ./<directory-XYZ/*> I'm trying to create a little script but I got stuck very quickly :-) I'm having trouble reading the directories because they contain spaces and special characters ie "[" and "(". Something very basic like this doesn't work because the "\" in front of each special character is missing. Code:
ls -d1 */ | while read DIRNAME |
unstested, but
Code:
ls "${DIRNAME}" or even while read just at straight for loop will do it Code:
for dir in */;do edit: http://mywiki.wooledge.org/ParsingLs why ls is bad in scripts |
@Firerat,
Thanks for the hint. And thanks for the link you added. I will take a closer look at it later. For now the quick fix I needed was done by the following µ script. I had to use a slightly different approach as the directories were also containing subdirectories and the touch command didn't have a recursive option. Quote:
|
Code:
find "${dir}" -exec touch -r "${dir}" "${dir}"/* {} \; cheers |
Hi SAhbi,
Thanks for answering, sorry I took so long to respond. I'm not sure if I understand. I used the find cmd to find any files in $dir (possibly in multiple subdirectories) and then execute the touch cmd on those files. I use $dir as date reference. How do you suggest I should envoke the cmd string without find? Regards, Robbert |
All times are GMT -5. The time now is 09:22 AM. |