DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on • Originally published at curiousprogrammer.dev on

Create a symlink for hidden files

I want to create a symlink for all hidden files excluding the hidden directories. I want to put my configuration files in my home directory into version control.

I need to exclude the hidden directories because they contain binaries and what not.

Using this one liner, I can create a symbolic link for every hidden file in my home directory to my working (or target) directory.

for f in .*; do if [[-f $f]]; then ln -s /home/me/$f /home/me/working/directory/$f; fi; done
Enter fullscreen mode Exit fullscreen mode

I execute this from my source directory.

I can verify that my symlinks exist in my target directory

cd /home/me/working/directory
ls -lah
Enter fullscreen mode Exit fullscreen mode

I should see a few lines that look like this:

lrwxrwxrwx. 1 me me 26 Jan 27 10:49 .zsh_history -> /home/me/.zsh_history
lrwxrwxrwx. 1 me me 20 Jan 27 10:49 .zshrc -> /home/me/.zshrc
Enter fullscreen mode Exit fullscreen mode

Top comments (0)