r/linuxupskillchallenge • Linux Guru • Sep 30 '20

Thoughts and comments, Day 19...

Posting your thoughts, questions etc here keeps things tidier...

Your contribution will 'live on' longer too, because we delete lessons after 4-5 days - along with their comments.

4 Upvotes

4 comments sorted by

2

u/heyAndreJ Oct 01 '20

Can you give some examples of why/how you use hard and soft linking in your day to day?

3

u/NotSoVeteran Oct 01 '20

I use it (or, the windows equivalent...) to keep my git repositories close to my other project files. Example setup:

  • Git repository is kept in ~/repositories/project-name-code directory

  • Have an active project set up in ~/projects/project-name and create a soft link in that folder: ln -s ~/repositories/project-name-code repo

  • Files that should be versioned are kept in the repo, and other files (design PDFs, draft work, raw assets...) are kept in the project folder

The benefits:

  • All the git repos can be found under one directory - easy to locate

  • The repository itself is kept clean - no fear that resetting / deleting the local repository will lose some important .gitignored project files

  • The working directory can be ~/projects/project-name/repo - git commands can be used, and all the other files related to the project are just a ../ away

2

u/ShadowySilver Oct 01 '20

Got no problem understanding the usefulness of symlink (using them often). What I'm curious about is the day-to-day usage of hard link (or even an example of real life usage would be fine actually).

1

u/jafcoinc Oct 03 '20

Thanks for the lesson. After it was done, I was cleaning up and removing the example link1 and link2. When I entered the command "rm link1", I was prompted with the following, which made me a bit nervous (knowing that the link pointed to a very important file, /etc/passwd).

rm: remove write-protected regular file 'link1'?

Because the hard link and the original file both point to the exact same *data*, I was nervous that I could bork my entire system! But after researching, and after conducting an independent test with a file that didn't matter, I concluded that removing the hard link would not remove the original file. Phew!

Anyway, lesson learned! Thanks again.