List readonly files
I need to list or show or query for the files in a folder (well, technically, on a USB drive, but I can navigate to it in Finder/Terminal) that are marked readonly.
All the Google-fu in the world just reveals solutions to change permissions but I don't need to do that.
My Dashcam marks videos/images readonly to save them when I press the button on it, but they're still in a folder with a few hundred MOV files, and I need a simple way to filter down to the ones I am looking for.
terminal finder permission
New contributor
add a comment |
I need to list or show or query for the files in a folder (well, technically, on a USB drive, but I can navigate to it in Finder/Terminal) that are marked readonly.
All the Google-fu in the world just reveals solutions to change permissions but I don't need to do that.
My Dashcam marks videos/images readonly to save them when I press the button on it, but they're still in a folder with a few hundred MOV files, and I need a simple way to filter down to the ones I am looking for.
terminal finder permission
New contributor
add a comment |
I need to list or show or query for the files in a folder (well, technically, on a USB drive, but I can navigate to it in Finder/Terminal) that are marked readonly.
All the Google-fu in the world just reveals solutions to change permissions but I don't need to do that.
My Dashcam marks videos/images readonly to save them when I press the button on it, but they're still in a folder with a few hundred MOV files, and I need a simple way to filter down to the ones I am looking for.
terminal finder permission
New contributor
I need to list or show or query for the files in a folder (well, technically, on a USB drive, but I can navigate to it in Finder/Terminal) that are marked readonly.
All the Google-fu in the world just reveals solutions to change permissions but I don't need to do that.
My Dashcam marks videos/images readonly to save them when I press the button on it, but they're still in a folder with a few hundred MOV files, and I need a simple way to filter down to the ones I am looking for.
terminal finder permission
terminal finder permission
New contributor
New contributor
edited 2 days ago
Nimesh Neema
14.8k43972
14.8k43972
New contributor
asked 2 days ago
Steven Evers
1161
1161
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
find . -type f -perm +444 ! -perm +222
searches for all files (-type f
) which are readable (-perm +444
) but not writable (! +perm +222
).
If your mind boggles after reading up on -perm
in man find
you can also use the (significantly slower, especially on slow devices) option of processing the output of find
yourself:
find . -type f -print0 |
xargs -0 -n 1 sh -c '[ -r "$1" -a ! -w "$1" ] && echo "$1"' sh
This basically takes each file find
finds, and runs it through a small shells script to check permissions.
PS: Hey, I didn't say the second way is less mind-boggling :-)
1
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)
– Yoric
2 days ago
1
@Yoric There is no general solution for this usingfind
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.
– nohillside♦
2 days ago
1
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
add a comment |
One way is to make use of the -w
option in bash to check if the file is writable or not.
Go into the directory you want to check your files, then enter:
for RO in $(find . -type f);do [ -r "$RO" ] && [ ! -w "$RO" ] && echo $RO;done
(credit to www.unix.com)
[EDIT]
To deal with spaces in file names, better to use the find -exec
way rather than looping into the find
:
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -exec echo {} ;
or
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -print
New contributor
Textually parsing the output fromfind
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.
– nohillside♦
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with usingfind -exec
– Yoric
2 days ago
My (hopefully) last remark on this:find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than thefind ... | xargs ... sh -c
monstrosity in my own answer :-)
– nohillside♦
2 days ago
add a comment |
List the files and grep for the read-only pattern:
ls -l | grep '^-r--'
^
symbol indicates start the line.
We are filtering only files here by mentioning ^-
, after that looking only for read permission files by specifying r--
. If you want to filter read & executable permission files, you can use r-x
.
If you want just the filename, you can use below command
ls -l | grep '^-r--' | awk 'NF>1{print $NF}'
Printing the file name using above command works, only if you don't have spaces in file name.
New contributor
2
Grepping thels -l
is a smart way to do it, but beware that your files might start with-rw-r--r--
withroot
as the owner, and such files won't be listed, even though they aren't writeable for the user.
– Yoric
2 days ago
1
grep ... | awk
is usally not required, the second command can be rewritten asls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "118"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Steven Evers 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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f347110%2flist-readonly-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
find . -type f -perm +444 ! -perm +222
searches for all files (-type f
) which are readable (-perm +444
) but not writable (! +perm +222
).
If your mind boggles after reading up on -perm
in man find
you can also use the (significantly slower, especially on slow devices) option of processing the output of find
yourself:
find . -type f -print0 |
xargs -0 -n 1 sh -c '[ -r "$1" -a ! -w "$1" ] && echo "$1"' sh
This basically takes each file find
finds, and runs it through a small shells script to check permissions.
PS: Hey, I didn't say the second way is less mind-boggling :-)
1
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)
– Yoric
2 days ago
1
@Yoric There is no general solution for this usingfind
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.
– nohillside♦
2 days ago
1
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
add a comment |
find . -type f -perm +444 ! -perm +222
searches for all files (-type f
) which are readable (-perm +444
) but not writable (! +perm +222
).
If your mind boggles after reading up on -perm
in man find
you can also use the (significantly slower, especially on slow devices) option of processing the output of find
yourself:
find . -type f -print0 |
xargs -0 -n 1 sh -c '[ -r "$1" -a ! -w "$1" ] && echo "$1"' sh
This basically takes each file find
finds, and runs it through a small shells script to check permissions.
PS: Hey, I didn't say the second way is less mind-boggling :-)
1
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)
– Yoric
2 days ago
1
@Yoric There is no general solution for this usingfind
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.
– nohillside♦
2 days ago
1
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
add a comment |
find . -type f -perm +444 ! -perm +222
searches for all files (-type f
) which are readable (-perm +444
) but not writable (! +perm +222
).
If your mind boggles after reading up on -perm
in man find
you can also use the (significantly slower, especially on slow devices) option of processing the output of find
yourself:
find . -type f -print0 |
xargs -0 -n 1 sh -c '[ -r "$1" -a ! -w "$1" ] && echo "$1"' sh
This basically takes each file find
finds, and runs it through a small shells script to check permissions.
PS: Hey, I didn't say the second way is less mind-boggling :-)
find . -type f -perm +444 ! -perm +222
searches for all files (-type f
) which are readable (-perm +444
) but not writable (! +perm +222
).
If your mind boggles after reading up on -perm
in man find
you can also use the (significantly slower, especially on slow devices) option of processing the output of find
yourself:
find . -type f -print0 |
xargs -0 -n 1 sh -c '[ -r "$1" -a ! -w "$1" ] && echo "$1"' sh
This basically takes each file find
finds, and runs it through a small shells script to check permissions.
PS: Hey, I didn't say the second way is less mind-boggling :-)
edited 2 days ago
answered 2 days ago
nohillside♦
50.9k13109149
50.9k13109149
1
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)
– Yoric
2 days ago
1
@Yoric There is no general solution for this usingfind
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.
– nohillside♦
2 days ago
1
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
add a comment |
1
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)
– Yoric
2 days ago
1
@Yoric There is no general solution for this usingfind
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.
– nohillside♦
2 days ago
1
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
1
1
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:
touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)– Yoric
2 days ago
Although the second method runs slower, it might be more accurate in certain situations if I am not mistaken with this example test for example:
touch test_file; sudo chown root:staff test_file;
(the first method fails to list the file, although it is a read-only file for the user)– Yoric
2 days ago
1
1
@Yoric There is no general solution for this using
find
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.– nohillside♦
2 days ago
@Yoric There is no general solution for this using
find
alone, see unix.stackexchange.com/questions/22421/… and the original question linked from there. In the case of the OP it's probably not an issue.– nohillside♦
2 days ago
1
1
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
Thanks, my head is spinning right now, so much to learn digging into "simple questions" :)
– Yoric
2 days ago
add a comment |
One way is to make use of the -w
option in bash to check if the file is writable or not.
Go into the directory you want to check your files, then enter:
for RO in $(find . -type f);do [ -r "$RO" ] && [ ! -w "$RO" ] && echo $RO;done
(credit to www.unix.com)
[EDIT]
To deal with spaces in file names, better to use the find -exec
way rather than looping into the find
:
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -exec echo {} ;
or
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -print
New contributor
Textually parsing the output fromfind
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.
– nohillside♦
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with usingfind -exec
– Yoric
2 days ago
My (hopefully) last remark on this:find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than thefind ... | xargs ... sh -c
monstrosity in my own answer :-)
– nohillside♦
2 days ago
add a comment |
One way is to make use of the -w
option in bash to check if the file is writable or not.
Go into the directory you want to check your files, then enter:
for RO in $(find . -type f);do [ -r "$RO" ] && [ ! -w "$RO" ] && echo $RO;done
(credit to www.unix.com)
[EDIT]
To deal with spaces in file names, better to use the find -exec
way rather than looping into the find
:
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -exec echo {} ;
or
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -print
New contributor
Textually parsing the output fromfind
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.
– nohillside♦
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with usingfind -exec
– Yoric
2 days ago
My (hopefully) last remark on this:find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than thefind ... | xargs ... sh -c
monstrosity in my own answer :-)
– nohillside♦
2 days ago
add a comment |
One way is to make use of the -w
option in bash to check if the file is writable or not.
Go into the directory you want to check your files, then enter:
for RO in $(find . -type f);do [ -r "$RO" ] && [ ! -w "$RO" ] && echo $RO;done
(credit to www.unix.com)
[EDIT]
To deal with spaces in file names, better to use the find -exec
way rather than looping into the find
:
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -exec echo {} ;
or
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -print
New contributor
One way is to make use of the -w
option in bash to check if the file is writable or not.
Go into the directory you want to check your files, then enter:
for RO in $(find . -type f);do [ -r "$RO" ] && [ ! -w "$RO" ] && echo $RO;done
(credit to www.unix.com)
[EDIT]
To deal with spaces in file names, better to use the find -exec
way rather than looping into the find
:
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -exec echo {} ;
or
find . -type f -exec [ -r {} ] ; -exec [ ! -w {} ] ; -print
New contributor
edited 2 days ago
nohillside♦
50.9k13109149
50.9k13109149
New contributor
answered 2 days ago
Yoric
2685
2685
New contributor
New contributor
Textually parsing the output fromfind
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.
– nohillside♦
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with usingfind -exec
– Yoric
2 days ago
My (hopefully) last remark on this:find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than thefind ... | xargs ... sh -c
monstrosity in my own answer :-)
– nohillside♦
2 days ago
add a comment |
Textually parsing the output fromfind
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.
– nohillside♦
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with usingfind -exec
– Yoric
2 days ago
My (hopefully) last remark on this:find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than thefind ... | xargs ... sh -c
monstrosity in my own answer :-)
– nohillside♦
2 days ago
Textually parsing the output from
find
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.– nohillside♦
2 days ago
Textually parsing the output from
find
usually breaks on file names containing space characters and similar. May not be a problem in the context the OP has, but might hit you in other circumstances.– nohillside♦
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with using
find -exec
– Yoric
2 days ago
@nohillside Thanks for the head up, I fixed the case replacing the for loop with using
find -exec
– Yoric
2 days ago
My (hopefully) last remark on this:
find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than the find ... | xargs ... sh -c
monstrosity in my own answer :-)– nohillside♦
2 days ago
My (hopefully) last remark on this:
find . -type f -exec [ -r {} -a ! -w {} ] ; -print
, much easier to read than the find ... | xargs ... sh -c
monstrosity in my own answer :-)– nohillside♦
2 days ago
add a comment |
List the files and grep for the read-only pattern:
ls -l | grep '^-r--'
^
symbol indicates start the line.
We are filtering only files here by mentioning ^-
, after that looking only for read permission files by specifying r--
. If you want to filter read & executable permission files, you can use r-x
.
If you want just the filename, you can use below command
ls -l | grep '^-r--' | awk 'NF>1{print $NF}'
Printing the file name using above command works, only if you don't have spaces in file name.
New contributor
2
Grepping thels -l
is a smart way to do it, but beware that your files might start with-rw-r--r--
withroot
as the owner, and such files won't be listed, even though they aren't writeable for the user.
– Yoric
2 days ago
1
grep ... | awk
is usally not required, the second command can be rewritten asls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
add a comment |
List the files and grep for the read-only pattern:
ls -l | grep '^-r--'
^
symbol indicates start the line.
We are filtering only files here by mentioning ^-
, after that looking only for read permission files by specifying r--
. If you want to filter read & executable permission files, you can use r-x
.
If you want just the filename, you can use below command
ls -l | grep '^-r--' | awk 'NF>1{print $NF}'
Printing the file name using above command works, only if you don't have spaces in file name.
New contributor
2
Grepping thels -l
is a smart way to do it, but beware that your files might start with-rw-r--r--
withroot
as the owner, and such files won't be listed, even though they aren't writeable for the user.
– Yoric
2 days ago
1
grep ... | awk
is usally not required, the second command can be rewritten asls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
add a comment |
List the files and grep for the read-only pattern:
ls -l | grep '^-r--'
^
symbol indicates start the line.
We are filtering only files here by mentioning ^-
, after that looking only for read permission files by specifying r--
. If you want to filter read & executable permission files, you can use r-x
.
If you want just the filename, you can use below command
ls -l | grep '^-r--' | awk 'NF>1{print $NF}'
Printing the file name using above command works, only if you don't have spaces in file name.
New contributor
List the files and grep for the read-only pattern:
ls -l | grep '^-r--'
^
symbol indicates start the line.
We are filtering only files here by mentioning ^-
, after that looking only for read permission files by specifying r--
. If you want to filter read & executable permission files, you can use r-x
.
If you want just the filename, you can use below command
ls -l | grep '^-r--' | awk 'NF>1{print $NF}'
Printing the file name using above command works, only if you don't have spaces in file name.
New contributor
edited 2 days ago
New contributor
answered 2 days ago
BarathVutukuri
1272
1272
New contributor
New contributor
2
Grepping thels -l
is a smart way to do it, but beware that your files might start with-rw-r--r--
withroot
as the owner, and such files won't be listed, even though they aren't writeable for the user.
– Yoric
2 days ago
1
grep ... | awk
is usally not required, the second command can be rewritten asls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
add a comment |
2
Grepping thels -l
is a smart way to do it, but beware that your files might start with-rw-r--r--
withroot
as the owner, and such files won't be listed, even though they aren't writeable for the user.
– Yoric
2 days ago
1
grep ... | awk
is usally not required, the second command can be rewritten asls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
2
2
Grepping the
ls -l
is a smart way to do it, but beware that your files might start with -rw-r--r--
with root
as the owner, and such files won't be listed, even though they aren't writeable for the user.– Yoric
2 days ago
Grepping the
ls -l
is a smart way to do it, but beware that your files might start with -rw-r--r--
with root
as the owner, and such files won't be listed, even though they aren't writeable for the user.– Yoric
2 days ago
1
1
grep ... | awk
is usally not required, the second command can be rewritten as ls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
grep ... | awk
is usally not required, the second command can be rewritten as ls -l | awk '/^-r--/ {print $NF}'
– nohillside♦
2 days ago
add a comment |
Steven Evers is a new contributor. Be nice, and check out our Code of Conduct.
Steven Evers is a new contributor. Be nice, and check out our Code of Conduct.
Steven Evers is a new contributor. Be nice, and check out our Code of Conduct.
Steven Evers is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Different!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fapple.stackexchange.com%2fquestions%2f347110%2flist-readonly-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown