PDA

View Full Version : [ubuntu] Bash Script To Make Symlinks of Hidden Directories?



N0WH3R3K1D
May 2nd, 2010, 07:02 AM
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?

Primefalcon
May 2nd, 2010, 07:07 AM
ln -s .hiddenfolder /wherever/you/want/your/yourSymLink/to/be

xumuk37
May 2nd, 2010, 07:26 AM
ln -s <destination> <linkname>

Oops! I didn't refresh the page xD)

arsenic23
May 2nd, 2010, 07:27 AM
My bash scripting is pretty messy, but this will do what you want if you run if from your home directory.:



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.

N0WH3R3K1D
May 3rd, 2010, 02:33 AM
My bash scripting is pretty messy, but this will do what you want if you run if from your home directory.:



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?

arsenic23
May 4th, 2010, 02:16 PM
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:


#!/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.)

Drenriza
May 4th, 2010, 02:20 PM
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


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

N0WH3R3K1D
May 4th, 2010, 08:18 PM
Oh sure, sorry. Here you go:


#!/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.