How to rename (unhide) all files and subdirectories within a directory?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I want to make a script to "unhide" all files and directories inside a certain directory in one go, e.g. ./unhide test
.
test/
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
Desired outcome:
test/
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
How can I do that?
I'm still new to this and I've been trying to find a solution using find
, but stuck at -exec
, and rename
(or mv
) because I'm still struggling to understand how this combination works. :(
So, I'll appreciate if anyone here can give a solution and detailed explanation as well. Thanks.
command-line bash scripts batch-rename
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
3
down vote
favorite
I want to make a script to "unhide" all files and directories inside a certain directory in one go, e.g. ./unhide test
.
test/
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
Desired outcome:
test/
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
How can I do that?
I'm still new to this and I've been trying to find a solution using find
, but stuck at -exec
, and rename
(or mv
) because I'm still struggling to understand how this combination works. :(
So, I'll appreciate if anyone here can give a solution and detailed explanation as well. Thanks.
command-line bash scripts batch-rename
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
It might help to show your desired outcome
– wjandrea
47 mins ago
@wjandrea Updated. :)
– Lukman Hakim
6 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I want to make a script to "unhide" all files and directories inside a certain directory in one go, e.g. ./unhide test
.
test/
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
Desired outcome:
test/
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
How can I do that?
I'm still new to this and I've been trying to find a solution using find
, but stuck at -exec
, and rename
(or mv
) because I'm still struggling to understand how this combination works. :(
So, I'll appreciate if anyone here can give a solution and detailed explanation as well. Thanks.
command-line bash scripts batch-rename
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to make a script to "unhide" all files and directories inside a certain directory in one go, e.g. ./unhide test
.
test/
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
Desired outcome:
test/
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
How can I do that?
I'm still new to this and I've been trying to find a solution using find
, but stuck at -exec
, and rename
(or mv
) because I'm still struggling to understand how this combination works. :(
So, I'll appreciate if anyone here can give a solution and detailed explanation as well. Thanks.
command-line bash scripts batch-rename
command-line bash scripts batch-rename
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 7 mins ago
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago


Lukman Hakim
385
385
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Lukman Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
It might help to show your desired outcome
– wjandrea
47 mins ago
@wjandrea Updated. :)
– Lukman Hakim
6 mins ago
add a comment |Â
It might help to show your desired outcome
– wjandrea
47 mins ago
@wjandrea Updated. :)
– Lukman Hakim
6 mins ago
It might help to show your desired outcome
– wjandrea
47 mins ago
It might help to show your desired outcome
– wjandrea
47 mins ago
@wjandrea Updated. :)
– Lukman Hakim
6 mins ago
@wjandrea Updated. :)
– Lukman Hakim
6 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
You can do that with find
as follows:
find /path/to/test -depth -name ".*" -execdir rename -n 's|/.|/|' +
This only prints the renaming actions, if it shows what you want remove the -n
option.
Explanations
-depth
– letsfind
process from bottom to top, renaming files before their parent directories-name ".*"
– letsfind
search for files (everything is a file) beginning with a dot-execdir … +
– execute…
in the matched file‘s directoryrename 's|/.|/|'
– replace the first occurence of “/.†from the matched file’s path (find
’s placeholder for which is) with “/â€Â, essentially removing the dot from the beginning of the filename
This would be e.g.rename 's|/.|/|' ./.hiddenfile1
in your case, this would be renamed to./hiddenfile1
.
Example run
$ tree -a
.
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
$ find ~/test -depth -name ".*" -execdir rename 's|/.|/|' +
$ tree -a
.
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
Usage in a script
In a script you can simply use positional parameters instead of the path, it may be relative or absolute – just remember to quote correctly:
#!/bin/bash
find "$1" -depth -name ".*" -execdir rename -n 's|/.|/|' +
add a comment |Â
up vote
1
down vote
$ tree -a test
test
├── .alsohidden
├── sub1
│  └── .hiddenfile1
└── sub2
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
3 directories, 4 files
$ find test/ -name ".*" -exec rename -n 's|(.*/).(.*)|$1$2|' +
rename(test/.alsohidden, test/alsohidden)
rename(test/sub2/.hiddendirsub, test/sub2/hiddendirsub)
rename(test/sub2/.hiddenfile2, test/sub2/hiddenfile2)
rename(test/sub1/.hiddenfile1, test/sub1/hiddenfile1)
find test/
begin paths withtest/
, search recursively from this path-exec command +
runcommand
on the found files, constructing an argument list.rename -n
do not do anything, only show what will be done (remove-n
after testing to actually rename)s|old|new|
replaceold
withnew
(.*/).(.*)
save all the chars up to and including the last directory separator/
, skip a literal.
, save all the subsequent characters$1$2
print the saved patterns
Why doesrename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)
– dessert
21 mins ago
@dessert omg I just assumed it would allow, I always use|
if I need/
in the regex (unless I need|
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars
– Zanna
13 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You can do that with find
as follows:
find /path/to/test -depth -name ".*" -execdir rename -n 's|/.|/|' +
This only prints the renaming actions, if it shows what you want remove the -n
option.
Explanations
-depth
– letsfind
process from bottom to top, renaming files before their parent directories-name ".*"
– letsfind
search for files (everything is a file) beginning with a dot-execdir … +
– execute…
in the matched file‘s directoryrename 's|/.|/|'
– replace the first occurence of “/.†from the matched file’s path (find
’s placeholder for which is) with “/â€Â, essentially removing the dot from the beginning of the filename
This would be e.g.rename 's|/.|/|' ./.hiddenfile1
in your case, this would be renamed to./hiddenfile1
.
Example run
$ tree -a
.
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
$ find ~/test -depth -name ".*" -execdir rename 's|/.|/|' +
$ tree -a
.
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
Usage in a script
In a script you can simply use positional parameters instead of the path, it may be relative or absolute – just remember to quote correctly:
#!/bin/bash
find "$1" -depth -name ".*" -execdir rename -n 's|/.|/|' +
add a comment |Â
up vote
2
down vote
You can do that with find
as follows:
find /path/to/test -depth -name ".*" -execdir rename -n 's|/.|/|' +
This only prints the renaming actions, if it shows what you want remove the -n
option.
Explanations
-depth
– letsfind
process from bottom to top, renaming files before their parent directories-name ".*"
– letsfind
search for files (everything is a file) beginning with a dot-execdir … +
– execute…
in the matched file‘s directoryrename 's|/.|/|'
– replace the first occurence of “/.†from the matched file’s path (find
’s placeholder for which is) with “/â€Â, essentially removing the dot from the beginning of the filename
This would be e.g.rename 's|/.|/|' ./.hiddenfile1
in your case, this would be renamed to./hiddenfile1
.
Example run
$ tree -a
.
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
$ find ~/test -depth -name ".*" -execdir rename 's|/.|/|' +
$ tree -a
.
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
Usage in a script
In a script you can simply use positional parameters instead of the path, it may be relative or absolute – just remember to quote correctly:
#!/bin/bash
find "$1" -depth -name ".*" -execdir rename -n 's|/.|/|' +
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can do that with find
as follows:
find /path/to/test -depth -name ".*" -execdir rename -n 's|/.|/|' +
This only prints the renaming actions, if it shows what you want remove the -n
option.
Explanations
-depth
– letsfind
process from bottom to top, renaming files before their parent directories-name ".*"
– letsfind
search for files (everything is a file) beginning with a dot-execdir … +
– execute…
in the matched file‘s directoryrename 's|/.|/|'
– replace the first occurence of “/.†from the matched file’s path (find
’s placeholder for which is) with “/â€Â, essentially removing the dot from the beginning of the filename
This would be e.g.rename 's|/.|/|' ./.hiddenfile1
in your case, this would be renamed to./hiddenfile1
.
Example run
$ tree -a
.
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
$ find ~/test -depth -name ".*" -execdir rename 's|/.|/|' +
$ tree -a
.
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
Usage in a script
In a script you can simply use positional parameters instead of the path, it may be relative or absolute – just remember to quote correctly:
#!/bin/bash
find "$1" -depth -name ".*" -execdir rename -n 's|/.|/|' +
You can do that with find
as follows:
find /path/to/test -depth -name ".*" -execdir rename -n 's|/.|/|' +
This only prints the renaming actions, if it shows what you want remove the -n
option.
Explanations
-depth
– letsfind
process from bottom to top, renaming files before their parent directories-name ".*"
– letsfind
search for files (everything is a file) beginning with a dot-execdir … +
– execute…
in the matched file‘s directoryrename 's|/.|/|'
– replace the first occurence of “/.†from the matched file’s path (find
’s placeholder for which is) with “/â€Â, essentially removing the dot from the beginning of the filename
This would be e.g.rename 's|/.|/|' ./.hiddenfile1
in your case, this would be renamed to./hiddenfile1
.
Example run
$ tree -a
.
├── sub1
│  └── .hiddenfile1
└── sub2
└── .hiddendir
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
$ find ~/test -depth -name ".*" -execdir rename 's|/.|/|' +
$ tree -a
.
├── sub1
│  └── hiddenfile1
└── sub2
└── hiddendir
├── hiddendirsub
├── hiddenfile2
└── not.hidden
Usage in a script
In a script you can simply use positional parameters instead of the path, it may be relative or absolute – just remember to quote correctly:
#!/bin/bash
find "$1" -depth -name ".*" -execdir rename -n 's|/.|/|' +
edited just now
answered 39 mins ago


dessert
20.5k55896
20.5k55896
add a comment |Â
add a comment |Â
up vote
1
down vote
$ tree -a test
test
├── .alsohidden
├── sub1
│  └── .hiddenfile1
└── sub2
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
3 directories, 4 files
$ find test/ -name ".*" -exec rename -n 's|(.*/).(.*)|$1$2|' +
rename(test/.alsohidden, test/alsohidden)
rename(test/sub2/.hiddendirsub, test/sub2/hiddendirsub)
rename(test/sub2/.hiddenfile2, test/sub2/hiddenfile2)
rename(test/sub1/.hiddenfile1, test/sub1/hiddenfile1)
find test/
begin paths withtest/
, search recursively from this path-exec command +
runcommand
on the found files, constructing an argument list.rename -n
do not do anything, only show what will be done (remove-n
after testing to actually rename)s|old|new|
replaceold
withnew
(.*/).(.*)
save all the chars up to and including the last directory separator/
, skip a literal.
, save all the subsequent characters$1$2
print the saved patterns
Why doesrename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)
– dessert
21 mins ago
@dessert omg I just assumed it would allow, I always use|
if I need/
in the regex (unless I need|
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars
– Zanna
13 mins ago
add a comment |Â
up vote
1
down vote
$ tree -a test
test
├── .alsohidden
├── sub1
│  └── .hiddenfile1
└── sub2
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
3 directories, 4 files
$ find test/ -name ".*" -exec rename -n 's|(.*/).(.*)|$1$2|' +
rename(test/.alsohidden, test/alsohidden)
rename(test/sub2/.hiddendirsub, test/sub2/hiddendirsub)
rename(test/sub2/.hiddenfile2, test/sub2/hiddenfile2)
rename(test/sub1/.hiddenfile1, test/sub1/hiddenfile1)
find test/
begin paths withtest/
, search recursively from this path-exec command +
runcommand
on the found files, constructing an argument list.rename -n
do not do anything, only show what will be done (remove-n
after testing to actually rename)s|old|new|
replaceold
withnew
(.*/).(.*)
save all the chars up to and including the last directory separator/
, skip a literal.
, save all the subsequent characters$1$2
print the saved patterns
Why doesrename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)
– dessert
21 mins ago
@dessert omg I just assumed it would allow, I always use|
if I need/
in the regex (unless I need|
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars
– Zanna
13 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
$ tree -a test
test
├── .alsohidden
├── sub1
│  └── .hiddenfile1
└── sub2
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
3 directories, 4 files
$ find test/ -name ".*" -exec rename -n 's|(.*/).(.*)|$1$2|' +
rename(test/.alsohidden, test/alsohidden)
rename(test/sub2/.hiddendirsub, test/sub2/hiddendirsub)
rename(test/sub2/.hiddenfile2, test/sub2/hiddenfile2)
rename(test/sub1/.hiddenfile1, test/sub1/hiddenfile1)
find test/
begin paths withtest/
, search recursively from this path-exec command +
runcommand
on the found files, constructing an argument list.rename -n
do not do anything, only show what will be done (remove-n
after testing to actually rename)s|old|new|
replaceold
withnew
(.*/).(.*)
save all the chars up to and including the last directory separator/
, skip a literal.
, save all the subsequent characters$1$2
print the saved patterns
$ tree -a test
test
├── .alsohidden
├── sub1
│  └── .hiddenfile1
└── sub2
├── .hiddendirsub
├── .hiddenfile2
└── not.hidden
3 directories, 4 files
$ find test/ -name ".*" -exec rename -n 's|(.*/).(.*)|$1$2|' +
rename(test/.alsohidden, test/alsohidden)
rename(test/sub2/.hiddendirsub, test/sub2/hiddendirsub)
rename(test/sub2/.hiddenfile2, test/sub2/hiddenfile2)
rename(test/sub1/.hiddenfile1, test/sub1/hiddenfile1)
find test/
begin paths withtest/
, search recursively from this path-exec command +
runcommand
on the found files, constructing an argument list.rename -n
do not do anything, only show what will be done (remove-n
after testing to actually rename)s|old|new|
replaceold
withnew
(.*/).(.*)
save all the chars up to and including the last directory separator/
, skip a literal.
, save all the subsequent characters$1$2
print the saved patterns
answered 39 mins ago


Zanna
48.6k13120230
48.6k13120230
Why doesrename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)
– dessert
21 mins ago
@dessert omg I just assumed it would allow, I always use|
if I need/
in the regex (unless I need|
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars
– Zanna
13 mins ago
add a comment |Â
Why doesrename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)
– dessert
21 mins ago
@dessert omg I just assumed it would allow, I always use|
if I need/
in the regex (unless I need|
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars
– Zanna
13 mins ago
Why does
rename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)– dessert
21 mins ago
Why does
rename
accept “|†as a delimiter, but not “_â€� Should I ask a new question? ;)– dessert
21 mins ago
@dessert omg I just assumed it would allow, I always use
|
if I need /
in the regex (unless I need |
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars– Zanna
13 mins ago
@dessert omg I just assumed it would allow, I always use
|
if I need /
in the regex (unless I need |
). That would be a good question. Maybe it has to be a non-word char or there's a set of permitted chars– Zanna
13 mins ago
add a comment |Â
Lukman Hakim is a new contributor. Be nice, and check out our Code of Conduct.
Lukman Hakim is a new contributor. Be nice, and check out our Code of Conduct.
Lukman Hakim is a new contributor. Be nice, and check out our Code of Conduct.
Lukman Hakim is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1089485%2fhow-to-rename-unhide-all-files-and-subdirectories-within-a-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
It might help to show your desired outcome
– wjandrea
47 mins ago
@wjandrea Updated. :)
– Lukman Hakim
6 mins ago