Reputation: 1
i am using the following command and getting an error "arg list too long".Help needed.
find ./* \
-prune \
-name "*.dat" \
-type f \
-cmin +60 \
-exec basename {} \;
Upvotes: 0
Views: 612
Reputation: 16515
If you have to show only .dat filename in the ./ tree. Execute it without -prune
option, and use just path:
find ./ -name "*.dat" -type f -cmin +60 -exec basename {} \;
To find all the .dat files which are older than 60 minutes in the present directory only do as follows:
find . -iregex "./[^/]+\.dat" -type f -cmin +60 -exec basename {} \;
And if you have croppen (for example aix) version of find tool do as follows:
find . -name "*.dat" -type f -cmin +60 | grep "^./[^/]\+dat" | sed "s/^.\///"
Upvotes: 0
Reputation: 247082
Without find, and only checking the current directory
now=$(date +%s)
for file in *.dat; do
if (( $now - $(stat -c %Y "$file") > 3600 )); then
echo "$file"
fi
done
This works on my GNU system. You may need to alter the date and stat formats for different OS's
Upvotes: 0
Reputation: 189779
To only find files in the current directory, use -maxdepth 1
.
find . -maxdepth 1 -name '*.dat' -type f -cmin +60 -exec basename {} \;
Upvotes: 2
Reputation: 28402
In all *nix systems the shell has a maximum length of arguments that can be passed to a command. This is measured after the shell has expanded filenames passed as arguments on the command line.
The syntax of find is find location_to_find_from arguments....
. so when you are running this command the shell will expand your ./*
to a list of all files in the current directory. This will expand your find command line to find file1 file2 file3 etc etc
This is probably not want you want as the find is recursive anyway. I expect that you are running this command in a large directory and blowing your command length limit.
Try running the command as follows
find . -name "*.dat" -type f -cmin +60 -exec basename {} \;
This will prevent the filename expansion that is probably causing your issue.
Upvotes: 1
Reputation: 45313
Here is the fix
find . -prune -name "*.dat" -type f -cmin +60 |xargs -i basename {} \;
Upvotes: 2