Results 1 to 8 of 8

Thread: Bash Script To Make Symlinks of Hidden Directories?

  1. #1
    Join Date
    Sep 2007
    Beans
    3

    Bash Script To Make Symlinks of Hidden Directories?

    Hi, I'm new to bash scripting. I wanted to know is there a way to make symlinks of the hidden directories in my home folder and move these symlinks into a special folder?

    What I want is this:

    /home/user/.hiddenfolder

    to

    /home/user/Preferences/hiddenfolder

    Why I would like this? Because in Mac OS X, application settings are stored in a folder like this:

    /users/user/Library

    I find it rather clean and organized, although I know the consequences of damaging the files in the process of editing these files. Anyways I've been trying to do the same thing under a sandbox situation in different folders, but to no avail. Again, how would I be able to do this?

  2. #2
    Join Date
    Apr 2008
    Location
    Wisconsin
    Beans
    766
    Distro
    Ubuntu

    Re: Bash Script To Make Symlinks of Hidden Directories?

    Code:
    ln -s .hiddenfolder /wherever/you/want/your/yourSymLink/to/be
    Last edited by Primefalcon; May 2nd, 2010 at 07:09 AM.

  3. #3
    Join Date
    Jan 2010
    Location
    Spain
    Beans
    151
    Distro
    Ubuntu Development Release

    Re: Bash Script To Make Symlinks of Hidden Directories?

    ln -s <destination> <linkname>

    Oops! I didn't refresh the page xD)

  4. #4
    Join Date
    Apr 2006
    Beans
    579
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Bash Script To Make Symlinks of Hidden Directories?

    My bash scripting is pretty messy, but this will do what you want if you run if from your home directory.:


    Code:
    for a in `ls -a | grep ^[.]`; do ln -s `pwd`'/'$a Preferences/`echo $a |sed 's/^[.]//'`; done
    edit:
    ______________
    BTW, I'm assuming the ~/Preferences folder already exists.
    Last edited by arsenic23; May 2nd, 2010 at 07:30 AM.

  5. #5
    Join Date
    Sep 2007
    Beans
    3

    Re: Bash Script To Make Symlinks of Hidden Directories?

    Quote Originally Posted by arsenic23 View Post
    My bash scripting is pretty messy, but this will do what you want if you run if from your home directory.:


    Code:
    for a in `ls -a | grep ^[.]`; do ln -s `pwd`'/'$a Preferences/`echo $a |sed 's/^[.]//'`; done
    edit:
    ______________
    BTW, I'm assuming the ~/Preferences folder already exists.
    Thank you for your code; however, I would like only symlinks to the hidden directories in the home directory into the Preferences directory and not the hidden files in the home directory. Is there a way to do this?

  6. #6
    Join Date
    Apr 2006
    Beans
    579
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Bash Script To Make Symlinks of Hidden Directories?

    Quote Originally Posted by N0WH3R3K1D View Post
    Thank you for your code; however, I would like only symlinks to the hidden directories in the home directory into the Preferences directory and not the hidden files in the home directory. Is there a way to do this?
    Oh sure, sorry. Here you go:

    Code:
    #!/bin/bash
    
    for a in `find . -maxdepth 1 -mindepth 1 -type d -name ".*"`; 
    do b=`echo $a | sed 's|^[.][/]||'`; 
    ln -s `pwd`'/'$b Preferences/`echo $b |sed 's/^[.]//'`;
    done
    Again, it's a little messy, but it works. (I'm obviously no hand at bash.)

  7. #7
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash Script To Make Symlinks of Hidden Directories?

    Quote Originally Posted by N0WH3R3K1D View Post
    Hi, I'm new to bash scripting. I wanted to know is there a way to make symlinks of the hidden directories in my home folder and move these symlinks into a special folder?

    What I want is this:

    /home/user/.hiddenfolder

    to

    /home/user/Preferences/hiddenfolder
    Code:
    ln -s /home/user/Preferences/hiddenfolder /home/user/.hiddenfolder

  8. #8
    Join Date
    Sep 2007
    Beans
    3

    Re: Bash Script To Make Symlinks of Hidden Directories?

    Quote Originally Posted by arsenic23 View Post
    Oh sure, sorry. Here you go:

    Code:
    #!/bin/bash
    
    for a in `find . -maxdepth 1 -mindepth 1 -type d -name ".*"`; 
    do b=`echo $a | sed 's|^[.][/]||'`; 
    ln -s `pwd`'/'$b Preferences/`echo $b |sed 's/^[.]//'`;
    done
    Again, it's a little messy, but it works. (I'm obviously no hand at bash.)
    Thanks a lot! It works perfectly!
    Gotta learn to do that myself.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •