The ./
in find's output comes from the .
argument before the options. Changing the .
argument changes the part of the output you're focused on. Given your example, this would produce the output you're asking for:
find dir1 dir2 dir3 dir4 dir5 -mtime -2 -type f -exec ls {} \;
I excluded the regex options because I guessed that they duplicate the action of specifying the subdirectory arguments. The output is:
dir1/demo1.sh
dir2/demo2.sh
dir3/demo3.sh
dir4/demo4.sh
dir5/demo5.sh
In your particular test case (with only five matching subdirs), you can reduce the list of subdirectories to a simple shell glob:
find dir[1-5] -mtime -2 -type f -exec ls {} \;
Or an even shorter glob:
find dir? -mtime -2 -type f -exec ls {} \;
There are many use cases where using find dir1 dir2 dir3 dir4 dir5
or find dir?
won't find the desired files like this. But the point of my answer was to show how the arguments before the options will affect the paths in find's output.
find
command for something, and is that why you want to modify it? The output offind
can not generally be safely parsed since Unix filenames can contain newlines. It is therefore better to usefind
with its-exec
predicate to execute whatever it is you need to run on the found files. See also Why is looping over find's output bad practice?. If you don't care about that, then there is nothing stopping you from passing the output throughsed 's/..//'
. – Kusalananda Jun 02 '23 at 15:41