LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2016, 08:47 PM   #1
crltzn.staff
LQ Newbie
 
Registered: Oct 2016
Posts: 2

Rep: Reputation: Disabled
Argument list too long


Hi,


I am creating a cronjob that will delete the 14 days old .jpg files on each below directory

20161010
20161011
20161012
20161013
20161014
20161015
20161016
20161017
20161018

Below is the command i used. I want to list them first before removing but I encounter Argument list too long.

find */*.jpg -type f -mtime +14 -exec ls -l {} \;
-bash: /bin/find: Argument list too long


kindly help.

Thanks

Last edited by crltzn.staff; 10-18-2016 at 08:54 PM.
 
Old 10-18-2016, 08:56 PM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Did you try using a search engine for the error?

https://duckduckgo.com/?q=arguement+...low&t=lm&ia=qa
(First Result)
https://stackoverflow.com/questions/...mands#11289567

You're also using the find command incorrectly.

Like this

Code:
find */ -iname '*.jpg' -type f -mtime +14 -exec ls -l {} \;
Not this

Code:
find */*.jpg -type f -mtime +14 -exec ls -l {} \;

Which will fix your original issue as well

Code:
       -name pattern
              Base  of  file  name  (the  path  with  the  leading directories
              removed) matches shell pattern  pattern.   Because  the  leading
              directories  are  removed, the file names considered for a match
              with -name will never include a slash, so `-name a/b' will never
              match  anything  (you  probably  need  to use -path instead).  A
              warning is issued if you try to do this, unless the  environment
              variable  POSIXLY_CORRECT is set.  The metacharacters (`*', `?',
              and `[]') match a `.' at the start of the base name (this  is  a
              change  in  findutils-4.2.2;  see  section STANDARDS CONFORMANCE
              below).  To ignore a directory  and  the  files  under  it,  use
              -prune;  see an example in the description of -path.  Braces are
              not recognised as being special,  despite  the  fact  that  some
              shells  including  Bash  imbue  braces with a special meaning in
              shell patterns.  The filename matching is performed with the use
              of  the  fnmatch(3)  library function.   Don't forget to enclose
              the pattern in quotes in order to protect it from  expansion  by
              the shell.

       -iname pattern
              Like -name, but the match is case insensitive.  For example, the
              patterns  `fo*'  and  `F??'  match  the file names `Foo', `FOO',
              `foo', `fOo', etc.   The pattern `*foo*` will also match a  file
              called '.foobar'.

Last edited by Sefyir; 10-18-2016 at 08:57 PM.
 
Old 10-18-2016, 08:58 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
it worked for me
Code:
$find */*.jpg -type f -mtime +14 -exec ls -l {} \;
results snippet
Code:
-rw-rw-r-- 1 userx users 5564552 Aug 12 07:44 wallpaper/1_035.jpg
-rw-rw-r-- 1 userx users 5583064 Aug 12 07:44 wallpaper/1_036.jpg
-rw-rw-r-- 1 userx users 4668801 Aug 12 07:44 wallpaper/1_037.jpg
-rw-rw-r-- 1 userx users 5083869 Aug 12 07:44 wallpaper/1_038.jpg
-rw-rw-r-- 1 userx users 4788415 Aug 12 07:44 wallpaper/1_039.jpg
-rw-rw-r-- 1 userx users 5789064 Aug 12 07:44 wallpaper/1_040.jpg
-rw-rw-r-- 1 userx users 5828280 Aug 12 07:44 wallpaper/1_041.jpg
-rw-rw-r-- 1 userx users 6873062 Aug 12 07:44 wallpaper/1_042.jpg
-rw-rw-r-- 1 userx users 6478105 Aug 12 07:44 wallpaper/1_043.jpg
-rw-rw-r-- 1 userx users 5333698 Aug 12 07:44 wallpaper/1_044.jpg
-rw-rw-r-- 1 userx users 5848674 Aug 12 07:44 wallpaper/1_045.jpg
-rw-rw-r-- 1 userx users 6847613 Aug 12 07:44 wallpaper/1_046.jpg
-rw-rw-r-- 1 userx users 6465080 Aug 12 07:44 wallpaper/1_047.jpg
-rw-rw-r-- 1 userx users 6691426 Aug 12 07:44 wallpaper/1_048.jpg
-rw-rw-r-- 1 userx users 5847404 Aug 12 07:44 wallpaper/1_049.jpg
-rw-rw-r-- 1 userx users 4724144 Aug 12 07:44 wallpaper/1_050.jpg
check your spaces?

Last edited by BW-userx; 10-18-2016 at 08:59 PM.
 
Old 10-18-2016, 09:01 PM   #4
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,689

Rep: Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715
Giving find a glob as a directory name is more than a bit iffy. There are valid ways to do that, but I recommend against it.
Just off the top I might do something like this
Code:
for foo in 20* ; do
   if [ -d ${foo} ] ; then
      find ${foo} -type f -mtime +14 -ls
   fi
done
to list them all, and
Code:
for foo in 20* ; do
   if [ -d ${foo} ] ; then
      find ${foo} -type f -mtime +14 -ls -delete 
   fi
done
to list and delete them in one step, or
Code:
for foo in 20* ; do
   if [ -d ${foo} ] ; then
      find ${foo} -type f -mtime +14 -delete
   fi
done
to just delete them silently.

This assumes the behavior of the GNU version of find.
 
Old 10-18-2016, 09:10 PM   #5
crltzn.staff
LQ Newbie
 
Registered: Oct 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
This works


find */ -iname '*.jpg' -type f -mtime +14 -exec ls -l {} \;



Thanks Sefyir
 
Old 10-18-2016, 09:13 PM   #6
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
Originally Posted by wpeckham View Post
Giving find a glob as a directory name is more than a bit iffy. There are valid ways to do that, but I recommend against it.
Just off the top I might do something like this
Code:
for foo in 20* ; do
   if [ -d ${foo} ] ; then
      find ${foo} -type f -mtime +14 -ls
   fi
done
I see the test for a directory, but why is for foo in 20* better then find 20*/?


Quote:
This works

find */ -iname '*.jpg' -type f -mtime +14 -exec ls -l {} \;

Thanks Sefyir
Take some time to examine why it works, and why yours failed. Otherwise you will run into this issue again.
 
Old 10-19-2016, 05:30 AM   #7
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,689

Rep: Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715Reputation: 2715
Quote:
Originally Posted by Sefyir View Post
I see the test for a directory, but why is for foo in 20* better then find 20*/?
When you use a glob for the path, you need to ensure you do it in a way that the shell will expand into something acceptable to find as a list of paths. To address this you can just go blind in the command, but know your directory well enough to be quite sure, or you can limit and test in the way you glob, or you can loop as did I and only give find a single verified path per invocation.

As you see above, mine is only ONE solution, and clearly not the most concise. There is always more than one right way. How you THINK is more interesting than the problem itself. The most natural thing for me is the 'divide and conquer' approach. Adjusting your command line to an invoke less likely to be fooled by unexpected glob expansion is another. They are all valid, and all work to accomplish your goal.

PS. The original posts crossed. When I gave my first response, it appeared the ONLY response. I was not responding to any of the other replies, because I had not seen them. I would not have you think that one solution is 'better' than the others, all of them that WORK are 'good' answers.

Last edited by wpeckham; 10-19-2016 at 05:33 AM.
 
Old 10-19-2016, 06:15 AM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
plus

just typing this

Code:
find /
tells find to search the entire system. including anything that is plugged into it, ie USB, if it is mounted then it will be searched. the only thing that will prevent a directory from being search using that is permissions.

in other words if you type
Code:
find / -name *jpg
it will spit out everything thing that it matches except it will not search areas it does not have permissions to do so.
output

does not have permissions to read.
Code:
nd: ‘/run/runit/supervise.socklog-unix’: Permission denied
find: ‘/run/runit/supervise.agetty-tty5’: Permission denied
find: ‘/run/runit/supervise.sshd’: Permission denied
find: ‘/run/runit/supervise.lxdm’: Permission denied
find: ‘/run/runit/supervise.acpid’: Permission denied
find: ‘/run/runit/supervise.dmeventd’: Permission denied
find: ‘/run/runit/supervise.uuidd’: Permission denied
find: ‘/run/runit/supervise.dhclient’: Permission denied
find: ‘/run/runit/supervise.agetty-tty3’: Permission denied
find: ‘/run/runit/supervise.mdadm’: Permission denied
find: ‘/run/runit/supervise.udevd’: Permission denied
find: ‘/run/runit/supervise.bluetoothd’: Permission denied
find: ‘/run/runit/supervise.NetworkManager’: Permission denied
find: ‘/run/runit/supervise.dbus’: Permission denied
find: ‘/run/lock/lvm’: Permission denied
has permissions to read
Code:
/home/userz/Dropbox/wallpaperbackups/mixed/C224.jpg
/home/userz/Dropbox/wallpaperbackups/mixed/t365.jpg
/home/userz/Dropbox/wallpaperbackups/mixed/C362.jpg
/home/userz/Dropbox/wallpaperbackups/mixed/t295.jpg
/home/userz/Dropbox/wallpaperbackups/mixed/t054.jpg
/home/userz/Dropbox/wallpaperbackups/mixed/C116.jpg
if you run find giving it root permissions then you can get around that. So that it will search your entire tree.
 
Old 10-19-2016, 02:26 PM   #9
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
Originally Posted by wpeckham View Post
PS. The original posts crossed. When I gave my first response, it appeared the ONLY response. I was not responding to any of the other replies, because I had not seen them. I would not have you think that one solution is 'better' than the others, all of them that WORK are 'good' answers.
Ah my mistake!
Yes, there are many ways to solve it.


Quote:
Originally Posted by BW-userx
in other words if you type
Code:

Code:
find / -name *jpg
it will spit out everything thing that it matches except it will not search areas it does not have permissions to do so.
output
You are correct, however be aware if there are any *jpg files in the directory where you run the command, the shell will expand *jpg to those files. It will also not match foo.JPG because -name is case-sensitive (use -iname to get past this one)

Eg. if you run it in a directory that contain foo.jpg, the shell will replace

Code:
find / -name *jpg 
  -> find / -name foo.jpg
Code:
set -xv
find ~/Pictures -name *jpg &> /dev/null
+ find /home/ty/Pictures -name '*jpg'
touch foo.jpg
+ touch foo.jpg
find ~/Pictures -name *jpg &> /dev/null
+ find /home/ty/Pictures -name foo.jpg
rm foo.jpg
+ rm foo.jpg
find ~/Pictures -name "*jpg" &> /dev/null
+ find /home/ty/Pictures -name '*jpg'
touch foo.jpg
+ touch foo.jpg
find ~/Pictures -name "*jpg" &> /dev/null
+ find /home/ty/Pictures -name '*jpg'
find ~/Pictures -name \*jpg &> /dev/null
+ find /home/ty/Pictures -name '*jpg'
rm foo.jpg
+ rm foo.jpg
The correct manner is to either escape it or quote it.

Code:
find / -name "*jpg"
find / -name \*jpg

Last edited by Sefyir; 10-19-2016 at 02:32 PM.
 
Old 10-19-2016, 02:28 PM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Sefyir View Post
Ah my mistake!
Yes, there are many ways to solve it.




You are correct, however be aware if there are any *jpg files in the directory where you run the command, the shell will expand *jpg to those files. It will also not match foo.JPG because -name is case-sensitive (use -iname to get past this one)

Eg. if you run it in a directory that contain foo.jpg, the shell will replace

Code:
find / -name *jpg 
  -> find / -name foo.jpg
The correct manner is to either escape it or quote it.




Code:
find / -name "*jpg"
find / -name \*jpg

or you can just drop that completely then look at what you get using just this.
Code:
find / *jpg
Code:
userx@Voided.1 & ~ >> $find / \*jpg | wc -l

find: ‘*jpg’: No such file or directory
1497073

Last edited by BW-userx; 10-19-2016 at 02:38 PM.
 
Old 10-19-2016, 02:31 PM   #11
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,807

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
@BW-userx, the glob is to be done by the find command, not by the shell. Therefore must be escaped, e.g. with quotes
Code:
find / -name "*jpg"
--
The */ glob lists only directories. Should work with all shells, and is perfectly valid.
The only side effect is it remains */ if there is no directory (unless nullglob option is set), but this will give a clear error message in find, not any unwanted action.
 
Old 10-19-2016, 02:36 PM   #12
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by MadeInGermany View Post
@BW-userx, the glob is to be done by the find command, not by the shell. Therefore must be escaped, e.g. with quotes
Code:
find / -name "*jpg"
--
The */ glob lists only directories. Should work with all shells, and is perfectly valid.
The only side effect is it remains */ if there is no directory (unless nullglob option is set), but this will give a clear error message in find, not any unwanted action.
hum never seen it done like that but thanks good info to know.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Argument list too long ekelly30 Linux - Kernel 11 01-09-2012 10:46 AM
[SOLVED] argument list too long deep27ak Linux - Newbie 5 11-26-2011 03:52 PM
Argument list too long ust Linux - Software 11 10-26-2009 10:16 AM
Argument list too long trutnev Linux - General 3 04-22-2004 04:32 PM
/bin/rm: Argument list too long dragon49 Linux - Software 1 09-02-2003 12:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration