0

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
slhck
  • 235,242

1 Answers1

0

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

Lewis M
  • 377