Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi,
i have many files in a lot of directories and subdirectories where i want to change the time-stamp of files and folders. it works fine with touch for _one_ file, but takes some time for all. i did not find any recursive function for touch. and i have no idea how to write a script for that.
can anyone help?
#!/bin/sh
for X in *
do
[ -d "$X" ] && cd "$X" && multitoucher && cd ..
touch "$X"
done
This worked for me. It has to be in your path and executable, and named multitoucher to work properly. To make sure, create a test directory and populate it with test files and directories etc. I can't take any credit for any destructive behavior this script exhibits, as I just spent the last half hour figuring this out for the first time.
marc
OH! Make sure you're in the top directory that you want touched, so if you want to touch all the files and folders in /home/jdoe/touchme/ make sure to cd /home/jdoe/touchme/ before running that script, or else all the files and folders in the directory you're in and all below will be touched.
Last edited by marcheikens; 11-02-2004 at 12:03 PM.
And it will work in a 'true' linux/unix environment. With that I'm trying to say that if you run it and it encounters names with, for example, spaces in them it will fail........
The for X in * is the base for that problem. This File (one file!!) will be broken up and X will be filled first with This and next with File.
Using find is one way of solving this. There must be others (there's the while construct in the back of my mind).
Quote:
I can't take any credit for any destructive behavior this script exhibits.
after find /home/mandavi/data/ -exec touch {}\ -t 06251436;
but i can't find in the find-manual any need for an extra argument for -exec but the arguments for the executed command.
and i have a lot of "non-unix" file and folder names in the tree...
Are you sure about the spaces? I thought "$X" took care of spaces, or couldn't you also put ${X} ?
${X} will not work, the "$X" or "${X}" will work in some cases (a real space being one of them). But a space is just one of the 'strange' characters you can encounter.
Odd, I'm playing with spaces, &, %, even * in file and directory names, and no errors. I don't know why this works for me, as I'm still a novice at bash scripting.
Distribution: Gentoo Linux, Ubuntu, Manderake 10 Official
Posts: 5
Rep:
find /usr/src/linux -exec touch {} \; does not work for me...
But this one did
find /usr/src/linux * -exec touch {} \;
Note the *.
Without the -exec option, find /usr/src/linux would only output /usr/src/linux. Including the * would display all the files inside /usr/src/linux, which is what you want.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.