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:




  1. 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.

  2. 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









share|improve this question









New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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















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:




  1. 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.

  2. 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









share|improve this question









New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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













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:




  1. 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.

  2. 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









share|improve this question









New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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:




  1. 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.

  2. 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






share|improve this question









New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 13 at 15:59









slhck

157k46434461




157k46434461






New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 13 at 14:52









Nishant Singh

11




11




New contributor




Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Nishant Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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














  • 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








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










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






share|improve this answer





















  • 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











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});






Nishant Singh is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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

























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






share|improve this answer





















  • 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















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






share|improve this answer





















  • 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













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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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










Nishant Singh is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

How do I know what Microsoft account the skydrive app is syncing to?

When does type information flow backwards in C++?

Grease: Live!