Last active
          December 30, 2015 08:15 
        
      - 
      
- 
        Save JoryTony/dd8893bb115702b53dac to your computer and use it in GitHub Desktop. 
    NIX ex: forced directory replacements (mount bind)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # This is only meant as an example. | |
| # If you are intending a permanent patch, you should just fix the directory structure. | |
| # This tool is primarily for when alterations to the existing tree are impossible, or prohibitively demanding. | |
| # Prep example folders and files | |
| cd ~ | |
| mkdir bindTest | |
| mkdir bindTest2 | |
| touch bindTest/file | |
| touch bindTest2/file2 | |
| # replace the ref of one folder, to point to another | |
| # similar to soft-links, almost an alias | |
| # both paths will look like a real folder/files | |
| # changes to either one will affect both (it is still just one folder) | |
| # mount -o bind [source (abs)] [destination (abs)] | |
| mount -o bind $(pwd)/bindTest2 $(pwd)/bindTest | |
| mount | grep bindTest | |
| ls -al bindTest | |
| # you should see only file2 | |
| touch bindTest/file1-2 | |
| touch bindTest2/file2-2 | |
| ls -al bindTest | |
| ls -al bindTest2 | |
| # you should see file2, file1-2, file2-2 | |
| umount $(pwd)/bindTest | |
| ls -al bindTest | |
| ls -al bindTest2 | |
| # all back to normal | |
| # bindTest contains only: file | |
| # bindTest2 contains: file2, file1-2, file2-2 | |
| # cleanup after ourselves | |
| rm -rf bindTest | |
| rm -rf bindTest2 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This is really only for when there's no other option (hard-links and softlinks).
I only found this particularly useful in two cases: