I would like to rename files within each sub-directory by adding the name of the sub-directory. Following the answer from Rename files by adding their parent folder name, I tried:
rename 's/(.*)\//$1\/$1_/' */*
However for lots of sub-directories it doesn't work. I have 13,000 sub-directories each containing about 300 files. I get
-bash: /usr/bin/rename: Argument list too long
I tried:
ls | xargs rename 's/(.*)\//$1\/$1_/' */*
find . -maxdepth 1 -type f -print0 | xargs rename 's/(.*)\//$1\/$1_/' */*
Both give the same error:
-bash: /usr/bin/xargs: Argument list too long
EDIT
xargs -L rename 's/(.*)\//$1\/$1_/' */*
xargs -L1 rename 's/(.*)\//$1\/$1_/' */*
Same error:
-bash: /usr/bin/xargs: Argument list too long
*/*
is always expanded by the shell; if you have too many matching files then it'll always be an "Argument list too long" even beforexargs
could get to do its business. The point ofxargs
is that it reads the list of files from stdin instead of parameters, that is, you should not have a final*/*
. Thels
orfind
command is supposed to list the filenames. – egmont Oct 08 '18 at 07:57find
with-exec
flag or a for loop. – Sergiy Kolodyazhnyy Oct 08 '18 at 09:30