One folder having two different locations on Ubuntu 18.04

As pointed out in the comments but not as a proper answer:

In many cases, a symbolic link is the easiest solution.

You can create them easily on the command line (using the ln command with -s parameter). You can create them easily using a GUI as well: Most file browsers (nautilus, ...) let you create a symbolic link using drag and drop (like for moving a file) while holding down a modifier key (CTRL+SHIFT).

Example for command line usage:

$ mkdir first_dir
$ ln -s ./first_dir ./second_dir
$ ls 
first_dir  second_dir

$ touch ./first_dir/test_1
$ touch ./second_dir/test_2

$ ls ./first_dir 
test_1  test_2

$ ls ./second_dir
test_1  test_2

Use bind mounts.

Suppose you have an existing directory /home/pandey/original and want to mirror it to /home/pandey/mirror so that everything you do in either of them is automatically done in the other one as well.

This doesn't require any syncing or copying between the two directories. A bind mount is just another view to the original directory and what happens in one also happens in the other.

  1. Create (as your user) the new directory /home/pandey/mirror:

    mkdir /home/pandey/mirror
    
  2. bind-mount the original directory to the newly created path. This requires root access:

    sudo mount --bind /home/pandey/original /home/pandey/mirror
    
  3. Enjoy.

To undo this, simply

sudo umount /home/pandey/mirror
rmdir /home/pandey/mirror

See also this question and its outstanding self-answer over on stackexchange about bind-mounts.


You can do it by setting a crontab job:

  • Open your terminal and type crontab -e
  • Press i in order to activate the insert mode of your vim editor.

You can enter the command you want to be done there, so you can copy all files of the folder in another folder. For example, if you want to copy all files in /home/user/folder_name to /home/user/public you should insert this command in your crontab file:

rsync /home/user/folder_name -r /home/user/public

This will copy all files in the desired interval. If you want to copy all files at 21:30 every day your edit should be:

 30 21 * * *  rsync /home/user/folder_name -r /home/user/public

For more information about crontab look here or use man crontab.