1

I'm trying to organise my directories for different classes such that each of them has a todo folder.

something like this:

|--classes/
|  |--classOne/
|  |  |--todo/
|  |  |  |--read.pdf
|  |  |--otherFiles.md
|  |--classTwo
|  |  |--todo/
|  |  |  |--read.pdf
|  |  |--otherFiles.md
|  |--classThree
|  |  |--todo/
|  |  |  |--read.pdf
|  |  |--otherFiles.md

I'm wondering if it's possible to have a folder called todo_buffer external to this hierarchy that can aggregate data from all of the individual todo folders.

It's possible to just create a small application, but is there a unix-utility that will allow me to do this? I was thinking along the line of symbolic links.

  • If you're thinking about symbolic links, what have you tried so far? – roaima Jan 26 at 20:35
  • 1
    I've only used symlinks in the context of ln -s, where i'm just soft linking two files and truncating their path. I read the ln manpage, but couldn't figure out how I might achieve this, which is why I turned to SE – ZM- Jan 26 at 23:17
1

stow it will create the symlinks, and maintain them. You have to run it to get it to update. However you could use inotify-wait, to trigger an update.

  • The next question would be how to get stow to only stow the files in the todo directories, and how to get inotify-wait to trigger that. – Kusalananda Jan 26 at 21:35
  • OK so ask another question, but have a go first. If you show no effort, then you may not get a good response. – ctrl-alt-delor Jan 27 at 17:37
1
#!/bin/sh

mkdir -p todo_buffer

for todo in classes/class*/todo/read.pdf
do
    class=${todo%/todo/read.pdf} # Get the name of
    class=${class#classes/}      # the class directory

    ln -s "../$todo" "todo_buffer/$class-read.pdf"
done

This script is supposed to be run in the parent directory of the classes directory. It will simply create a todo_buffer directory and then proceed to loop over the pathnames of the read.pdf files in the todo subdirectories of each class.

This assumes that the directory structure below the classes directory is as you have shown, with each class having a subdirectory called class<something>.

For each read.pdf file, a symbolic link is created in the todo_buffer directory.

The symbolic links points to ../classes/.../todo/read.pdf, i.e. it's relative to the location of the link. If you need absolute pathnames for the links, replace ../ with $PWD/ in the call to ln -s.

Given the following directories and files:

.
|-- classes
|   |-- class-1
|   |   |-- otherFiles.md
|   |   `-- todo
|   |       `-- read.pdf
|   |-- class-2
|   |   |-- otherFiles.md
|   |   `-- todo
|   |       `-- read.pdf
|   `-- class-3
|       |-- otherFiles.md
|       `-- todo
|           `-- read.pdf
`-- script.sh

7 directories, 7 files

Running the script would generate:

todo_buffer/
|-- class-1-read.pdf -> ../classes/class-1/todo/read.pdf
|-- class-2-read.pdf -> ../classes/class-2/todo/read.pdf
`-- class-3-read.pdf -> ../classes/class-3/todo/read.pdf

0 directory, 3 files
0

Can you clarify your requirements and the context of your problem further?

  1. Would you use the "tool" to aggregate your todo_buffer folder AFTER you populated all the todo folders or BEFORE in order for you to more easily populate these todo folders?

  2. Would each individual todo folders contain similar filenames (as shown in your example) but with actual different content?

Symbolic links might be what you are looking for (yet I feel you would need to write a small script) but it really depends on what you want to exactly achieve.

Symbolic link works with the same logic as a copy or a move:

ln -s {src} {dst}        

where {src} is the file where the link should be pointing to and {dst} is the symbolic name.

Suppose all your files are in todo_buffers and you only want to create symbolic links in each of the todo folders then:

cd {some path}/classes/classOne/todo   
ln -s {path to todo_buffer}/todo_buffer/read.pdf  read.pdf  
cd {some path}/classes/classTwo/todo  
ln -s {path to todo_buffer}/todo_buffer/read.pdf  read.pdf  
cd {some path}/classes/classThree/todo  
ln -s {path to todo_buffer}/todo_buffer/read.pdf  read.pdf  
...  
  • There may be similarly named files within the todo folder, but that's unlikely. Any recommendations for how to setup the symlinks? I read the ln manpage, but couldn't figure out how I might achieve this. – ZM- Jan 26 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.