Mike
Mike

Reputation: 11

/bin/find : Argument list too long

I am a beginner programming shell scripts, right now I am doing a shell script to create zip files according to last modification of directory inside a path. Where date is:

today=date +%Y-%m-%d

customers=find /DOMINOAPP/Delta_Transfer/*/* -type d -name "*" -newermt $today | cut -d "/" -f4

I got this error:

./zips.sh: line 8: /bin/find: Argument list too long

Please anyone could you help me to fix this issue?

Upvotes: 1

Views: 3149

Answers (1)

bfontaine
bfontaine

Reputation: 19830

Wildcards (outside of strings) are expanded by the shell, so here /DOMINOAPP/Delta_Transfer/*/* is first expanded by the shell, then passed to find. If it contains a lot of files the list will be super long and you’ll get that error.

find already goes into all subdirectories, so you can remove those wildcards:

find /DOMINOAPP/Delta_Transfer -type d -name "*" -newermt $today

To better understand wildcard expansion by the shell, compare the following commands:

$ touch a1 a2 a3
$ echo a*    # <-- expansion, = 'echo a1 a2 a3'
a1 a2 a3
$ echo "a*"  # <-- no expansion, = 'echo a*'
a*

Upvotes: 1

Related Questions