How to reorder folders in a directory in Linux?
up vote
0
down vote
favorite
I am new to Linux and am supposed to write a shell script to reorder the folders in a directory on the basis of ctime. The place where i am stuck is sorting the folders physically.
I have tried the following approaches:
- I was using combinations of ls sort command under an impression that it also changes the physical order but it is not affecting the order only listing the result.
- Using sort command alone hangs the terminal and then I am left with no other option other than canceling the command.
Kindly provide some reference for physical reordering of the folders. I have gone through articles but they were not much helpful.
What I am trying to achieve is to sort the folders in the directory on basis of last modified time. The main concern here is not how to extract time details of a folder in linux but what command can be helpful in sorting the folders physically on basis of last modified time.
Commands I have tried:
du -m --max-depth 1 | sort -rn
ls -1 | sort
ls -la | sort -k 1
linux shell
New contributor
|
show 4 more comments
up vote
0
down vote
favorite
I am new to Linux and am supposed to write a shell script to reorder the folders in a directory on the basis of ctime. The place where i am stuck is sorting the folders physically.
I have tried the following approaches:
- I was using combinations of ls sort command under an impression that it also changes the physical order but it is not affecting the order only listing the result.
- Using sort command alone hangs the terminal and then I am left with no other option other than canceling the command.
Kindly provide some reference for physical reordering of the folders. I have gone through articles but they were not much helpful.
What I am trying to achieve is to sort the folders in the directory on basis of last modified time. The main concern here is not how to extract time details of a folder in linux but what command can be helpful in sorting the folders physically on basis of last modified time.
Commands I have tried:
du -m --max-depth 1 | sort -rn
ls -1 | sort
ls -la | sort -k 1
linux shell
New contributor
1
Directories have no intrinsic order. The order will depend on the system locale. By "reordering", do you mean listing the directories and sorting them? Please edit your question and explain your task more clearly, and also show the scripts/commands you have already tried.
– slhck
Nov 13 at 14:54
Please check . I have done the edits .
– Nishant Singh
Nov 13 at 14:59
@slhck: They frequently do, and it depends on the filesystem. In most cases the order is not changeable by the user, so I hope the OP really meant "reorder the folder list" as inls -ltc
...
– grawity
Nov 13 at 15:59
1
By "physical" do you mean "visual"? Are you trying to change the order the items are listed in a Nautilus window? Please edit the question to include the Linux distribution (Ubuntu, for instance).
– Christopher Hostage
Nov 13 at 16:18
1
I am voting to close the question unless it is edited with the information given in the comments below. As it stands it's not answerable, as it is an XY problem.
– slhck
Nov 14 at 18:50
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am new to Linux and am supposed to write a shell script to reorder the folders in a directory on the basis of ctime. The place where i am stuck is sorting the folders physically.
I have tried the following approaches:
- I was using combinations of ls sort command under an impression that it also changes the physical order but it is not affecting the order only listing the result.
- Using sort command alone hangs the terminal and then I am left with no other option other than canceling the command.
Kindly provide some reference for physical reordering of the folders. I have gone through articles but they were not much helpful.
What I am trying to achieve is to sort the folders in the directory on basis of last modified time. The main concern here is not how to extract time details of a folder in linux but what command can be helpful in sorting the folders physically on basis of last modified time.
Commands I have tried:
du -m --max-depth 1 | sort -rn
ls -1 | sort
ls -la | sort -k 1
linux shell
New contributor
I am new to Linux and am supposed to write a shell script to reorder the folders in a directory on the basis of ctime. The place where i am stuck is sorting the folders physically.
I have tried the following approaches:
- I was using combinations of ls sort command under an impression that it also changes the physical order but it is not affecting the order only listing the result.
- Using sort command alone hangs the terminal and then I am left with no other option other than canceling the command.
Kindly provide some reference for physical reordering of the folders. I have gone through articles but they were not much helpful.
What I am trying to achieve is to sort the folders in the directory on basis of last modified time. The main concern here is not how to extract time details of a folder in linux but what command can be helpful in sorting the folders physically on basis of last modified time.
Commands I have tried:
du -m --max-depth 1 | sort -rn
ls -1 | sort
ls -la | sort -k 1
linux shell
linux shell
New contributor
New contributor
edited Nov 13 at 15:59
slhck
157k46434461
157k46434461
New contributor
asked Nov 13 at 14:52
Nishant Singh
11
11
New contributor
New contributor
1
Directories have no intrinsic order. The order will depend on the system locale. By "reordering", do you mean listing the directories and sorting them? Please edit your question and explain your task more clearly, and also show the scripts/commands you have already tried.
– slhck
Nov 13 at 14:54
Please check . I have done the edits .
– Nishant Singh
Nov 13 at 14:59
@slhck: They frequently do, and it depends on the filesystem. In most cases the order is not changeable by the user, so I hope the OP really meant "reorder the folder list" as inls -ltc
...
– grawity
Nov 13 at 15:59
1
By "physical" do you mean "visual"? Are you trying to change the order the items are listed in a Nautilus window? Please edit the question to include the Linux distribution (Ubuntu, for instance).
– Christopher Hostage
Nov 13 at 16:18
1
I am voting to close the question unless it is edited with the information given in the comments below. As it stands it's not answerable, as it is an XY problem.
– slhck
Nov 14 at 18:50
|
show 4 more comments
1
Directories have no intrinsic order. The order will depend on the system locale. By "reordering", do you mean listing the directories and sorting them? Please edit your question and explain your task more clearly, and also show the scripts/commands you have already tried.
– slhck
Nov 13 at 14:54
Please check . I have done the edits .
– Nishant Singh
Nov 13 at 14:59
@slhck: They frequently do, and it depends on the filesystem. In most cases the order is not changeable by the user, so I hope the OP really meant "reorder the folder list" as inls -ltc
...
– grawity
Nov 13 at 15:59
1
By "physical" do you mean "visual"? Are you trying to change the order the items are listed in a Nautilus window? Please edit the question to include the Linux distribution (Ubuntu, for instance).
– Christopher Hostage
Nov 13 at 16:18
1
I am voting to close the question unless it is edited with the information given in the comments below. As it stands it's not answerable, as it is an XY problem.
– slhck
Nov 14 at 18:50
1
1
Directories have no intrinsic order. The order will depend on the system locale. By "reordering", do you mean listing the directories and sorting them? Please edit your question and explain your task more clearly, and also show the scripts/commands you have already tried.
– slhck
Nov 13 at 14:54
Directories have no intrinsic order. The order will depend on the system locale. By "reordering", do you mean listing the directories and sorting them? Please edit your question and explain your task more clearly, and also show the scripts/commands you have already tried.
– slhck
Nov 13 at 14:54
Please check . I have done the edits .
– Nishant Singh
Nov 13 at 14:59
Please check . I have done the edits .
– Nishant Singh
Nov 13 at 14:59
@slhck: They frequently do, and it depends on the filesystem. In most cases the order is not changeable by the user, so I hope the OP really meant "reorder the folder list" as in
ls -ltc
...– grawity
Nov 13 at 15:59
@slhck: They frequently do, and it depends on the filesystem. In most cases the order is not changeable by the user, so I hope the OP really meant "reorder the folder list" as in
ls -ltc
...– grawity
Nov 13 at 15:59
1
1
By "physical" do you mean "visual"? Are you trying to change the order the items are listed in a Nautilus window? Please edit the question to include the Linux distribution (Ubuntu, for instance).
– Christopher Hostage
Nov 13 at 16:18
By "physical" do you mean "visual"? Are you trying to change the order the items are listed in a Nautilus window? Please edit the question to include the Linux distribution (Ubuntu, for instance).
– Christopher Hostage
Nov 13 at 16:18
1
1
I am voting to close the question unless it is edited with the information given in the comments below. As it stands it's not answerable, as it is an XY problem.
– slhck
Nov 14 at 18:50
I am voting to close the question unless it is edited with the information given in the comments below. As it stands it's not answerable, as it is an XY problem.
– slhck
Nov 14 at 18:50
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you want to list the contents of a directory by ctime, @grawity is correct, use
ls -ltc
If you want to list the contents of a directory based on the filesystem tree structure, you are wanting to sort by inode. You can do that using
ls -li | sort
If you want something else, please provide a sample input and a sample output.
Hope this helps
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
1
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
1
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
1
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you want to list the contents of a directory by ctime, @grawity is correct, use
ls -ltc
If you want to list the contents of a directory based on the filesystem tree structure, you are wanting to sort by inode. You can do that using
ls -li | sort
If you want something else, please provide a sample input and a sample output.
Hope this helps
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
1
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
1
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
1
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
add a comment |
up vote
0
down vote
If you want to list the contents of a directory by ctime, @grawity is correct, use
ls -ltc
If you want to list the contents of a directory based on the filesystem tree structure, you are wanting to sort by inode. You can do that using
ls -li | sort
If you want something else, please provide a sample input and a sample output.
Hope this helps
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
1
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
1
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
1
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
add a comment |
up vote
0
down vote
up vote
0
down vote
If you want to list the contents of a directory by ctime, @grawity is correct, use
ls -ltc
If you want to list the contents of a directory based on the filesystem tree structure, you are wanting to sort by inode. You can do that using
ls -li | sort
If you want something else, please provide a sample input and a sample output.
Hope this helps
If you want to list the contents of a directory by ctime, @grawity is correct, use
ls -ltc
If you want to list the contents of a directory based on the filesystem tree structure, you are wanting to sort by inode. You can do that using
ls -li | sort
If you want something else, please provide a sample input and a sample output.
Hope this helps
answered Nov 13 at 17:26
Lewis M
2925
2925
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
1
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
1
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
1
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
add a comment |
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
1
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
1
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
1
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
I have tried these. The thing is I want to sort the folders in the directory and not just display them .
– Nishant Singh
Nov 13 at 17:30
1
1
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
What do you mean by "sort the folders in the directory and not just display them"? What are you looking to do once the folders in a given directory have been sorted?
– Lewis M
Nov 13 at 17:32
1
1
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
The thing I am trying to achieve is sort the folders in a directory and then move the folders to another directory in a sorted order. Let me explain the scenario . We have a source folder where in we get documents per customer. For each customer we make a folder and then place his documents in those folder . Now we want to pick up folders in fcfs fashion i.e folder created first must be given priority . The approach that I have been asked to implement is first sort the folders in the source directory , then move these folders to a second directory with some additional conditions .
– Nishant Singh
Nov 13 at 18:12
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
Good. Additional information. That is helpful. Could you provide sample input and sample output as well? That will give us an even better idea of what you are trying to accomplish. If you want to supply things like creation times, modified times, etc, please do so. The more details you give us, the better we will be able to help you.
– Lewis M
Nov 13 at 18:19
1
1
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
@NishantSingh You should really edit your question and explain this – your original question really does not make a lot of sense without this information. Please also briefly read: xyproblem.info
– slhck
Nov 14 at 9:33
add a comment |
Nishant Singh is a new contributor. Be nice, and check out our Code of Conduct.
Nishant Singh is a new contributor. Be nice, and check out our Code of Conduct.
Nishant Singh is a new contributor. Be nice, and check out our Code of Conduct.
Nishant Singh 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%2fsuperuser.com%2fquestions%2f1375049%2fhow-to-reorder-folders-in-a-directory-in-linux%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
Directories have no intrinsic order. The order will depend on the system locale. By "reordering", do you mean listing the directories and sorting them? Please edit your question and explain your task more clearly, and also show the scripts/commands you have already tried.
– slhck
Nov 13 at 14:54
Please check . I have done the edits .
– Nishant Singh
Nov 13 at 14:59
@slhck: They frequently do, and it depends on the filesystem. In most cases the order is not changeable by the user, so I hope the OP really meant "reorder the folder list" as in
ls -ltc
...– grawity
Nov 13 at 15:59
1
By "physical" do you mean "visual"? Are you trying to change the order the items are listed in a Nautilus window? Please edit the question to include the Linux distribution (Ubuntu, for instance).
– Christopher Hostage
Nov 13 at 16:18
1
I am voting to close the question unless it is edited with the information given in the comments below. As it stands it's not answerable, as it is an XY problem.
– slhck
Nov 14 at 18:50