Loading the good stuff
unsplashunsplash
Gradient background

Create a symlink for hidden files

Clarice Bouwer

Software Engineering Team Lead and Director of Cloudsure

Sunday, 27 January 2019 · Estimated 1 minute read

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.

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

I execute this from my source directory.

I can verify that my symlinks exist in my target directory

Copy
cd /home/me/working/directory
ls -lah

I should see a few lines that look like this:

Copy
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

Share this article on…


Subscribe to my newsletter

Get notified monthly about any new articles, tutorials, and courses. I promise to keep the emails short and sweet, and never spam you.

By signing up you acknowledge the Privacy Policy. Please keep an eye out in your junk/spam folder for the confirmation email.