how to sort files by their permissions using ls?
I have a large number of files and directories in one directory.
I need to sort them in terms of the permissions.
For example
drwx------
drwxr-xr-x
drwxr-x---
I am just wondering if we can sort the files and dirs using ls
?
ls sort
add a comment |
I have a large number of files and directories in one directory.
I need to sort them in terms of the permissions.
For example
drwx------
drwxr-xr-x
drwxr-x---
I am just wondering if we can sort the files and dirs using ls
?
ls sort
1
ls -l|sort
will sort by permissions.
– geedoubleya
Oct 31 '14 at 12:22
add a comment |
I have a large number of files and directories in one directory.
I need to sort them in terms of the permissions.
For example
drwx------
drwxr-xr-x
drwxr-x---
I am just wondering if we can sort the files and dirs using ls
?
ls sort
I have a large number of files and directories in one directory.
I need to sort them in terms of the permissions.
For example
drwx------
drwxr-xr-x
drwxr-x---
I am just wondering if we can sort the files and dirs using ls
?
ls sort
ls sort
edited Oct 31 '14 at 23:16
Gilles
539k12810901606
539k12810901606
asked Oct 31 '14 at 12:18
Chenming ZhangChenming Zhang
5181711
5181711
1
ls -l|sort
will sort by permissions.
– geedoubleya
Oct 31 '14 at 12:22
add a comment |
1
ls -l|sort
will sort by permissions.
– geedoubleya
Oct 31 '14 at 12:22
1
1
ls -l|sort
will sort by permissions.– geedoubleya
Oct 31 '14 at 12:22
ls -l|sort
will sort by permissions.– geedoubleya
Oct 31 '14 at 12:22
add a comment |
3 Answers
3
active
oldest
votes
ls
does not directly support sorting by permissions, but you can combine it with the sort command:
ls -l | sort
You can use the -k
option to sort to start matching from a specific character, the format is -k FIELD.CHAR
, the permissions are the first field in the ls
output. So e.g. -k 1.2
will start from the second character of the permission string, which will ignore any directory / device / link etc. flag, or -k 1.5
for sorting by group permissions.
If you don't want the additional output of ls -l
, you can remove it with awk:
ls -l | sort | awk '{ print $1, $NF}'
This will print only the first field (the permissions) and the last one (the filename).
1
If you don't want additional output it much easy to usestat
commandstat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
add a comment |
You can also sort by octal value.
for i in *; do stat --format="%a %n" "$i"; done | sort -n
add a comment |
Which option to the ls will sort the output by file size?
New contributor
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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
});
}
});
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%2funix.stackexchange.com%2fquestions%2f165225%2fhow-to-sort-files-by-their-permissions-using-ls%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
ls
does not directly support sorting by permissions, but you can combine it with the sort command:
ls -l | sort
You can use the -k
option to sort to start matching from a specific character, the format is -k FIELD.CHAR
, the permissions are the first field in the ls
output. So e.g. -k 1.2
will start from the second character of the permission string, which will ignore any directory / device / link etc. flag, or -k 1.5
for sorting by group permissions.
If you don't want the additional output of ls -l
, you can remove it with awk:
ls -l | sort | awk '{ print $1, $NF}'
This will print only the first field (the permissions) and the last one (the filename).
1
If you don't want additional output it much easy to usestat
commandstat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
add a comment |
ls
does not directly support sorting by permissions, but you can combine it with the sort command:
ls -l | sort
You can use the -k
option to sort to start matching from a specific character, the format is -k FIELD.CHAR
, the permissions are the first field in the ls
output. So e.g. -k 1.2
will start from the second character of the permission string, which will ignore any directory / device / link etc. flag, or -k 1.5
for sorting by group permissions.
If you don't want the additional output of ls -l
, you can remove it with awk:
ls -l | sort | awk '{ print $1, $NF}'
This will print only the first field (the permissions) and the last one (the filename).
1
If you don't want additional output it much easy to usestat
commandstat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
add a comment |
ls
does not directly support sorting by permissions, but you can combine it with the sort command:
ls -l | sort
You can use the -k
option to sort to start matching from a specific character, the format is -k FIELD.CHAR
, the permissions are the first field in the ls
output. So e.g. -k 1.2
will start from the second character of the permission string, which will ignore any directory / device / link etc. flag, or -k 1.5
for sorting by group permissions.
If you don't want the additional output of ls -l
, you can remove it with awk:
ls -l | sort | awk '{ print $1, $NF}'
This will print only the first field (the permissions) and the last one (the filename).
ls
does not directly support sorting by permissions, but you can combine it with the sort command:
ls -l | sort
You can use the -k
option to sort to start matching from a specific character, the format is -k FIELD.CHAR
, the permissions are the first field in the ls
output. So e.g. -k 1.2
will start from the second character of the permission string, which will ignore any directory / device / link etc. flag, or -k 1.5
for sorting by group permissions.
If you don't want the additional output of ls -l
, you can remove it with awk:
ls -l | sort | awk '{ print $1, $NF}'
This will print only the first field (the permissions) and the last one (the filename).
answered Oct 31 '14 at 12:37
crater2150crater2150
2,61821523
2,61821523
1
If you don't want additional output it much easy to usestat
commandstat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
add a comment |
1
If you don't want additional output it much easy to usestat
commandstat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
1
1
If you don't want additional output it much easy to use
stat
command stat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
If you don't want additional output it much easy to use
stat
command stat -c"%A %n" * | sort
– Costas
Oct 31 '14 at 15:28
add a comment |
You can also sort by octal value.
for i in *; do stat --format="%a %n" "$i"; done | sort -n
add a comment |
You can also sort by octal value.
for i in *; do stat --format="%a %n" "$i"; done | sort -n
add a comment |
You can also sort by octal value.
for i in *; do stat --format="%a %n" "$i"; done | sort -n
You can also sort by octal value.
for i in *; do stat --format="%a %n" "$i"; done | sort -n
edited Oct 31 '14 at 15:50
Ramesh
23.7k34104185
23.7k34104185
answered Oct 31 '14 at 15:30
LinuxGuruLinuxGuru
30912
30912
add a comment |
add a comment |
Which option to the ls will sort the output by file size?
New contributor
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
add a comment |
Which option to the ls will sort the output by file size?
New contributor
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
add a comment |
Which option to the ls will sort the output by file size?
New contributor
Which option to the ls will sort the output by file size?
New contributor
New contributor
answered 3 hours ago
Edmond AssadiEdmond Assadi
1
1
New contributor
New contributor
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
add a comment |
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
– G-Man
2 hours ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f165225%2fhow-to-sort-files-by-their-permissions-using-ls%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
1
ls -l|sort
will sort by permissions.– geedoubleya
Oct 31 '14 at 12:22