Can the “rename” command distinguish between directories and files? [duplicate]
This question already has an answer here:
How do I rename a directory via the command line?
6 answers
I need to rename only directories and not files, and I want to do it with rename
.
Is there any way to do it?
It says nothing in the manual about differentiating between directories and files.
This command changes everything, no matter directory or files:
rename 's/ /n/g' *
This command solved my problem:
rename 's/ /n/g' */
I need a slash behind it.
command-line directory rename
marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 2 more comments
This question already has an answer here:
How do I rename a directory via the command line?
6 answers
I need to rename only directories and not files, and I want to do it with rename
.
Is there any way to do it?
It says nothing in the manual about differentiating between directories and files.
This command changes everything, no matter directory or files:
rename 's/ /n/g' *
This command solved my problem:
rename 's/ /n/g' */
I need a slash behind it.
command-line directory rename
marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Those links are helpful to me.
– JulianLai
Jan 15 at 10:30
4
Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers ofrename
... I suggest you remove that part of your question and post it as an answer!
– Zanna
Jan 15 at 14:50
2
by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.
– RoVo
Jan 15 at 16:09
1
@JulianLai It causes problems for people that usels | wc -l
to count the number of objects, or generally when parsing the output ofls
-- which is discouraged, but widely done.
– PerlDuck
Jan 15 at 16:20
2
and many many more things.
– RoVo
Jan 15 at 16:20
|
show 2 more comments
This question already has an answer here:
How do I rename a directory via the command line?
6 answers
I need to rename only directories and not files, and I want to do it with rename
.
Is there any way to do it?
It says nothing in the manual about differentiating between directories and files.
This command changes everything, no matter directory or files:
rename 's/ /n/g' *
This command solved my problem:
rename 's/ /n/g' */
I need a slash behind it.
command-line directory rename
This question already has an answer here:
How do I rename a directory via the command line?
6 answers
I need to rename only directories and not files, and I want to do it with rename
.
Is there any way to do it?
It says nothing in the manual about differentiating between directories and files.
This command changes everything, no matter directory or files:
rename 's/ /n/g' *
This command solved my problem:
rename 's/ /n/g' */
I need a slash behind it.
This question already has an answer here:
How do I rename a directory via the command line?
6 answers
command-line directory rename
command-line directory rename
edited Jan 15 at 14:46
Zanna
50.8k13136241
50.8k13136241
asked Jan 15 at 8:48
JulianLaiJulianLai
6942621
6942621
marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kulfy, karel, Elder Geek, waltinator, Thomas Jan 16 at 18:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Those links are helpful to me.
– JulianLai
Jan 15 at 10:30
4
Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers ofrename
... I suggest you remove that part of your question and post it as an answer!
– Zanna
Jan 15 at 14:50
2
by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.
– RoVo
Jan 15 at 16:09
1
@JulianLai It causes problems for people that usels | wc -l
to count the number of objects, or generally when parsing the output ofls
-- which is discouraged, but widely done.
– PerlDuck
Jan 15 at 16:20
2
and many many more things.
– RoVo
Jan 15 at 16:20
|
show 2 more comments
Those links are helpful to me.
– JulianLai
Jan 15 at 10:30
4
Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers ofrename
... I suggest you remove that part of your question and post it as an answer!
– Zanna
Jan 15 at 14:50
2
by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.
– RoVo
Jan 15 at 16:09
1
@JulianLai It causes problems for people that usels | wc -l
to count the number of objects, or generally when parsing the output ofls
-- which is discouraged, but widely done.
– PerlDuck
Jan 15 at 16:20
2
and many many more things.
– RoVo
Jan 15 at 16:20
Those links are helpful to me.
– JulianLai
Jan 15 at 10:30
Those links are helpful to me.
– JulianLai
Jan 15 at 10:30
4
4
Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of
rename
... I suggest you remove that part of your question and post it as an answer!– Zanna
Jan 15 at 14:50
Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of
rename
... I suggest you remove that part of your question and post it as an answer!– Zanna
Jan 15 at 14:50
2
2
by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.
– RoVo
Jan 15 at 16:09
by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.
– RoVo
Jan 15 at 16:09
1
1
@JulianLai It causes problems for people that use
ls | wc -l
to count the number of objects, or generally when parsing the output of ls
-- which is discouraged, but widely done.– PerlDuck
Jan 15 at 16:20
@JulianLai It causes problems for people that use
ls | wc -l
to count the number of objects, or generally when parsing the output of ls
-- which is discouraged, but widely done.– PerlDuck
Jan 15 at 16:20
2
2
and many many more things.
– RoVo
Jan 15 at 16:20
and many many more things.
– RoVo
Jan 15 at 16:20
|
show 2 more comments
1 Answer
1
active
oldest
votes
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
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.
edited Jan 15 at 17:00
wjandrea
9,25442663
9,25442663
answered Jan 15 at 16:17
RoVoRoVo
7,3661841
7,3661841
add a comment |
add a comment |
Those links are helpful to me.
– JulianLai
Jan 15 at 10:30
4
Have you answered your own question in the question? The trailing slash requires less typing than any method that could have been provided by the developers of
rename
... I suggest you remove that part of your question and post it as an answer!– Zanna
Jan 15 at 14:50
2
by the way ... I would not recommend using newlines in file/folder names. It may cause a lot of trouble.
– RoVo
Jan 15 at 16:09
1
@JulianLai It causes problems for people that use
ls | wc -l
to count the number of objects, or generally when parsing the output ofls
-- which is discouraged, but widely done.– PerlDuck
Jan 15 at 16:20
2
and many many more things.
– RoVo
Jan 15 at 16:20