LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   show contents of one directory in another. (https://www.linuxquestions.org/questions/linux-newbie-8/show-contents-of-one-directory-in-another-4175511508/)

dorlack 07-18-2014 09:37 AM

show contents of one directory in another.
 
drawing a total blank hope you guys can help me out.

I am trying to remember the command to link directories.

I need to show the contents of /var/home_volume in /home. I was abe to this once before and I remember it not being the normal symbolic link process.

The last time I did this was to display /home in a folder called /workspace. So if i created a new user in /home it showed up in /workspace.

IDK maybe it is a symbolic link but /home is already created. I could have sworn there is another method. Hope I am able to get my point across.

austintx 07-18-2014 10:16 AM

The ordinary symlink should work.
ln -s /var/home_volume $HOME/home_volume

You can also automount at boot in fstab using bind.
Something like this:
UUID=f7927995-b098-42be-ada0-987857f5177a /var ext4 defaults,noatime 0 0
/var/home_volume $HOME/Documents auto bind 0 0

T3RM1NVT0R 07-18-2014 10:19 AM

@ Reply
 
Directories cannot be hard link but you can soft link them. As you said you want to show contents of one directory to be shown in other. You can use:

Code:

ln -s <parent directory> <directory you want to show contents in>, example: ln -s <home> <home_test>
Remember that the other directory where you want to show the contents should not already exist. It will be automatically get created by ln -s.

dorlack 07-18-2014 10:23 AM

The folders are already created. I wanted to avoid rebuilding them. Symbolic link will require the folder to not exist right?

T3RM1NVT0R 07-18-2014 10:33 AM

Yes that is correct. However, you can have a sub-folder inside that which contains symlink to your parent folder. Example:

Code:

/tmp/test_dir (already exist)
/tmp/test_dir1 (already exist)

get into /tmp/test_dir1 and then run:

ln -s /tmp/test_dir testing

This will create a child directory under /tmp/test_dir1/testing which will actually point to /tmp/test_dir.

suicidaleggroll 07-18-2014 10:35 AM

So what you're saying is, /var/home_volume already exists and has files/dirs inside. In addition, /home already exists and has files/dirs inside. And you want to merge these two directories so that all files/dirs from BOTH locations are shown side-by-side in /home ?

The cleanest way, I would think, would be to move the contents of /home to /var/home_volume, delete /home, and then symlink or bind mount /var/home_volume to /home. If that's not an option, I suppose you could loop through all files/dirs in /var/home_volume and symlink them inside of /home
Code:

for i in /var/home_volume/*; do ln -s $i /home/; done
But this would have to be repeated every time a new file/dir is added in /var/home_volume, it wouldn't be added to /home automatically. It would be pretty messy though, and how would you handle files with the same name in both locations? You'd be better off thinking of a new way to do things, IMO.

All of the above suggestions are explaining how to make a symlink of /var/home_volume INSIDE of /home, so you would have to go to /home/home_volume to see it. It doesn't sound like that's what you want.


All times are GMT -5. The time now is 02:48 PM.