rename
does not distinguish between files and folders.
The shell is responsible for expanding the wildcard *
into files and folders.
*
will be expanded to all non-hidden files and folders.
*/
will be expanded to all non-hidden folders.
But I don't know of any way to expand to files only. You can use find -exec
instead.
only folders:
rename 's/ /\n/g' */
or
find . -maxdepth 1 -type d -exec rename 's/ /\n/g' {} +
Only files:
find . -maxdepth 1 -type f -exec rename 's/ /\n/g' {} +
Note that find
will also find hidden files unlike *
(unless you turn on the dotglob
shell option by running shopt -s dotglob
).
zsh
seems to be able to match files only with wildcards.
Disclaimer: I would not recommend adding newlines to file names as it may cause trouble and break many scripts.
rename
... I suggest you remove that part of your question and post it as an answer! – Zanna Jan 15 '19 at 14:50ls | wc -l
to count the number of objects, or generally when parsing the output ofls
-- which is discouraged, but widely done. – PerlDuck Jan 15 '19 at 16:20