You are not logged in.
I face a problem for which I have not found a satisfactory solution. I have a directory full of files (typically exercises for a course I teach, but no matter). What I want to do is the ability to sort these files in a specific manual order. The only solution I have found so far is to rename the files like this: 01_*** 02_*** 03_***. But then I cannot easily insert a file in the middle of the list. I would prefer never to rename the files (which make difficult to track the file down).
I know that ext4 has a directory order; I was thinking of using that but I have found no tool that allows to change the directory order. The only tool that I have seen that somehow support is "ls" with the "-U" option. It could have been the solution if more tools supported it.
Does someone have a solution or workaround to this problem? I can't imagine I am the only one having faced it.
Offline
What kind of "manual order"? "ls -U" will simply not sort them at all (but list the directory entries, this will not allow you to "insert" files either)
You could go for a sparse renaming 010_*** 020_*** 030_*** so you can always insert files 011_*** 012_*** … 01a_*** …
Otherwise there of course has to be some identifiable pattern in the name or metadata (eg. timestamps)
And then it's of course important what exactly you desire to display that order - it doesn't help you to "ls | sort" if you want to use some GUI filebrowser.
Speaking of which: some have (had?) the ability to store the geometry of icons.
Offline
I would like just to be able to manually sort the files. The sort order is not identifiable by a property of the file. These files correspond to exercises I want to give to students, which I sort in a logical order according to the course. But I reuse the same collection over time and sometimes I want to add an additional exercise.
I could indeed use a numbering of the form 010_*** 020_*** but it seems more like a hack to me.
As for the directory order, it should be possible, in theory, to change the directory order while keeping exactly the same files. If there was a tool that allowed me to do that and if the common file managers and tools supported displaying the files in directory order; then I could just use that. But unfortunately that does not exist; AFAIK (plus please tell me if I am wrong).
Offline
If the sort order is not identifiable by a property of the file, how would a file manager know how to sort them? It seems like a contradiction in terms.
Edit: You could do this *without* a file manager, by just maintaining a file which is just an ordered list of links in the directory (assuming the files are always named the same). It could be html, for example, but most note-taking software has this kind of functionality. As an example, emacs org-mode can do this. Just make sure to use relative links.
Last edited by monodromy (2018-11-06 18:49:22)
Offline
I'm pretty sure he perceives this from the perspective of a GUI FM and "manually sort" refers to the geometric positioning of the icons.
In this case, it's paramount to know which FM you intend to use - some have this feature, others simply don't.
In any case, if the sort order is not related to the file/metadata, you *will* require some external metadata (file list + attributes, whether geometry or ID)
Offline
@seth It would be nice to be able to sort the file using a graphical file manager indeed. But it would be nice to be able to use command line tools, too. I usually put some of the files in a website for the students to download and it would be nice to at least be able to easily retrieve the order in order to generate a webpage with the files in the good order. I currently use Thunar for my GUI file manager but also GNU tools (ls, mv, cp, etc.). I am open to any file manager that is reasonably light and does not depend on a specific desktop. Also I need to retrieve the order with simple command line tools. If you know something of the like that exists, I am open.
A hidden file in the directory having the information could do it. I was thinking of using the directory order. I don't think there is anything preventing you from changing the directory order; there is just no tools that support it. After all, under ext4, a directory is just a special file pointing to its content. We will have to rewrite the special file that is the directory.
Offline
It sounds like you need a non-standard filesystem. I'm not sure how much of a coder you are, but fuse comes to mind: https://wiki.archlinux.org/index.php/FUSE
I'm not saying this is the answer, but when I think "what would I do if I had this problem", writing a custom filesystem is one of the options I would consider. Doing basic things with fuse isn't too hard, so long as you've done some elementary coding in the past.
There are a lot of fuse tutorials out of there if you do a search, and bindings for at least a few popular languages.
Last edited by /dev/zero (2018-11-07 08:35:26)
Offline
vfat should be sufficiently stupid, ie. the directory order is the order in which files are added to the directory. So moving them from one dir into another in the "proper" order should get you this sorting.
ext4fs uses a hashed b-tree to index directories. This can be turned off but neither am I sure about the resulting order mechanism, nor is this probably a good idea performancewise.
Offline
Alternatively, you could use mtimes, and just use 'touch' to update them as required. You could even keep a file in the directory .order with content like the following:
touch a_first exercise
touch another_exerciseYou could edit that "hidden" file, insert, remove, or rearrange the lines as desired, then just source the file in that directory after any change:
. ./.orderThen list the files in order of mtime to see that order.
EDIT: I suppose you might need to add "sleep" commands to the order list too as mtimes are just whole second precision - so they'd all end up the same without a sleep. EDIT2: use `touch -t TIMESTAMP` instead, so the order file can finish instantly but set different times to each file.
Last edited by Trilby (2018-11-07 14:17:56)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
@Trilby. That might not be a bad idea...
Offline
EDIT2: use `touch -t TIMESTAMP` instead, so the order file can finish instantly but set different times to each file.
I thought prepending "touch " to each line wasn't so bad, but having to fiddle with TIMESTAMPs instead of simply reordering lines made me want to put together something like a one-liner to handle this. If you simply put one filename per line in .order, this works, because everything except the hours is optional for the date string accepted by the -d option:
$ nl .order | xargs -L 1 touch -d
$ ls -tr.. but only up to 24 files. Prepending @ to use seconds since epoch would be better, but it's not obvious how to do this with nl/xargs. GNU parallel is more flexible:
parallel touch -d '@{#}' '{}' < .orderand can be used as shebang in .order:
#!/usr/bin/parallel --shebang touch -d @{#} {}
a_first exercise
another_exerciseLast edited by Raynman (2018-11-08 09:53:48)
Offline