Академический Документы
Профессиональный Документы
Культура Документы
HardLinkvsSoftLink|GeekRide
Home(http://www.geekride.com/)
AutosBlog(http://www.geekride.com/auto)
LotsofotherStuff(http://www.geekride.com/misc)
Ubuntu12.10released(http://www.geekride.com/ubuntulatestreleased/)
TechTip:Monitoringwithkill(http://www.geekride.com/techtipmonitoringwithkill/)
HardLinkvsSoftLink
Monday,November5th,2012|ByNapster|35Comments(http://www.geekride.com/hardlinkvssoftlink/#comments)
Follow@linuxride
9,386followers
Once again, one of the very basic question asked in the interviews, What is the difference between Hard links and Soft
links. You can explain few basic things, but emphasizing on internals about the linux filesystem, is something which can
impresstheinterviewer.
WhatisaSoftLinkorSymbolicLinkorSymlink?
Symbolic links or Symlinks are the easiest to understand, because for sure you have used them, at least when you were
using Windows. Soft links are very similar to what we say Shortcut in windows, is a way to link to a file or directory.
Symlinksdoesntcontainanyinformationaboutthedestinationfileorcontentsofthefile,insteadofthat,itsimplycontains
thepointertothelocationofthedestinationfile.Inmoretechnicalwords,insoftlink,anewfileiscreatedwithanewinode,
whichhavethepointertotheinodelocationoftheoriginalfile.Thiscanbebetterexplainedwithadiagram:
(http://www.geekride.com/hardlinkvssoft
link/soft_link/)
WhatisaHardLink?
Hard link is a bit different object when compared to a
symlink. In softlink a new file and a new Inode is
created, but in hard link, only an entry into directory
structure is created for the file, but it points to the
inode location of the original file. Which means there is no new inode creation in the hard link. This can be explained like
this:
http://www.geekride.com/hardlinkvssoftlink/
1/11
6/13/2016
HardLinkvsSoftLink|GeekRide
(http://www.geekride.com/hardlinkvssoft
link/hard_link/)
2/11
6/13/2016
HardLinkvsSoftLink|GeekRide
dependsonyoursetup.
Howfileisdeletedhavinghardlinks:
So,asitsprettyclearfromtheabovearticlethathardlinksarejustthereferencetothemainfilelocation,andevenifyou
deleteonelink,thedatawillstillbeintact.So,toremoveahardlink,youneedtoremoveallthelinks,whicharereferringto
thefile.Oncethelinkcountgoesto0,thentheinodeisremovedbythefilesystem,andfileisdeleted.
FAQs:
Q.WhatistheonelineanswertothequestionWhatisthemaindifferencebetweenhardlinks&softlinks?
A.A softlink will have a different Inode number than the source file, which will be having a pointer to the source file but
hardlinkwillbeusingthesameInodenumberasthesourcefile.
Q.HowcanIfindalltheSoftLinksinmysystem?
A.Usethiscommandforthesamefind/etctypelexeclsli{}\
Q.HowcanIfindallthefileshavingHardLinksinmysystem?
A.Usethiscommandforthesamefind/links+2typefexeclsli{}\
Q.Howtofindwhetherafileisasoftlink?
A.Simplyusingthiscommandlslwilltellyouwhetherafileispointingtosomeotherfileornot.
Q.Howtocheckwhetherafilehaveanysoftlinkpointingtoit?
A.Tillnow,Iamnotawareofanywaytodothat.IfIwillfindany,Iwillsurelyupdatemypost.
Q.HowcanIfindoutthesourcefileofahardlink?
A.No,youcantfindoutthesourcefileofahardlink.Oncehardlinkiscreated,thereisnowaytotellwhichwasthefirst
filecreated.
Q.CanImakeaSoftlinktoaHardlinkandViceVersa?
A.Yes,bothsoftlinksandhardlinksactsasnormalfilesofthefilesystem,soyoucandoboth.
To understand the above article in much better way, you should go through the following article, which will give you much
clearpictureabouttheinodes.
UnderstandingLinux/UnixFilesystemInodes(http://www.geekride.com/understandingunixlinuxfilesysteminodes/)
References:
1.InodesinLinuxFilesystem(http://www.geekride.com/understandingunixlinuxfilesysteminodes/)
2.Techthrob.com(http://techthrob.com/2010/09/26/softlinksvshardlinksaquickexplanation/)
3.maxipedia.com(http://www.maxipedia.com/difference+between+symbolic+link+and+hard+link)
4.lwn.net(http://lwn.net/Articles/294667/)
If you enjoyed this post, make sure you subscribe to my RSS feed (http://feeds.feedburner.com/GeekRide
LinuxTipsTricksHacks)!!!!
Relatedcontent:
http://www.geekride.com/hardlinkvssoftlink/
3/11
6/13/2016
HardLinkvsSoftLink|GeekRide
1.UnderstandingLinux/UnixFilesystemInode(http://www.geekride.com/understandingunixlinuxfilesystem
inodes/)
2.ForkBomb(http://www.geekride.com/forkbomblinux/)
3.ETAGsvsExpireHeaders(http://www.geekride.com/etagsvsexpireheaders/)
4.TechTip:Monitoringwithkill(http://www.geekride.com/techtipmonitoringwithkill/)
7Comments
Sortby Oldest
Addacomment...
AndyWoodheadUnixAdministratoratManheim
YoualsoforgottomentionthathardlinksMUSTbeonthesamedisk.
Symlinkscangotodifferentdisks.ALsowithhardlinks,ifyoudeletethefile
youlinkedtothefilestillexistsastherearestilllinkstothedata.Ina
symlink,ifyoudeletethelinkedfileyouwillhaveabrokenlink
LikeReply
2Nov21,201210:53am
HariDhanalakotiVivekanandaSchoolofPGStudies
Nicepost,keepupthegoodwork.
LikeReplyJan7,20155:45pm
SajinVkWorksatProntoSoftware
Howtocheckwhetherafilehaveanysoftlinkpointingtoit?
cantweusethesamecommandwhichisusedtofindsoftlinks
find/typel|xargslsl|grep"file_name"
LikeReplyFeb3,201510:42am
KGuruNathanSupportEngineeratSolartisTechnologyServices
nicepost
LikeReplyJun20,20155:20am
GururajSMorabadWorksatHPInvent
Clearlyunderstood..Goodone
LikeReplyJun30,20152:44pm
Load2morecomments
FacebookCommentsPlugin
{35Comments.....browsethroughorwriteone(#commentform)}
1.bellssays:
November6,2012at7:25PM(http://www.geekride.com/hardlinkvssoftlink/#comment70388)
Inmoretechnicalwords,insoftlink,anewfileiscreatedwithanewinode,whichhavethepointertotheinode
http://www.geekride.com/hardlinkvssoftlink/
4/11
6/13/2016
HardLinkvsSoftLink|GeekRide
locationoftheoriginalfile.
inodelocationandinodenumberdifferent?
whenmoveafile,theinodenumberisnotchange,whataboutinodelocation??
Reply(/hardlinkvssoftlink/?replytocom=70388#respond)
Napstersays:
November8,2012at2:46PM(http://www.geekride.com/hardlinkvssoftlink/#comment70744)
InodenumberisjusttheaddresswhereInodeislocated.
Takeanexampleofahouseaddress,likeHouseNo110.
So,thelocationoftheHouseisdifferent,butitcanbereachedbyitsnumber,110.
ThatsthesamecasewithInodes.
InLaymansterms,theybotharesame.
Whenafilemoves,boththeinodenumberandtheinodelocationremainssame.
Hopethathelped.
Reply(/hardlinkvssoftlink/?replytocom=70744#respond)
bellssays:
January16,2013at9:37PM(http://www.geekride.com/hardlinkvssoftlink/#comment85631)
thankyou
Reply(/hardlinkvssoftlink/?replytocom=85631#respond)
2.AndyWoodhead(http://www.facebook.com/ActionParsnip)says:
November21,2012at10:53AM(http://www.geekride.com/hardlinkvssoftlink/#comment73683)
YoualsoforgottomentionthathardlinksMUSTbeonthesamedisk.Symlinkscangotodifferentdisks.
ALsowithhardlinks,ifyoudeletethefileyoulinkedtothefilestillexistsastherearestilllinkstothedata.
Inasymlink,ifyoudeletethelinkedfileyouwillhaveabrokenlink:)
Reply(/hardlinkvssoftlink/?replytocom=73683#respond)
Napstersays:
November22,2012at6:00PM(http://www.geekride.com/hardlinkvssoftlink/#comment73957)
ThanxAndy.
Willupdatemyblog.
Reply(/hardlinkvssoftlink/?replytocom=73957#respond)
3.Connelsays:
January13,2013at3:28PM(http://www.geekride.com/hardlinkvssoftlink/#comment85081)
Veryinformativeblog.Goodtoread.
Reply(/hardlinkvssoftlink/?replytocom=85081#respond)
4.Elex(http://www.linuxamination.blogspot.in)says:
May17,2013at5:51PM(http://www.geekride.com/hardlinkvssoftlink/#comment115751)
PleasemakechangeinHardLinkDiagram.ItshowsthereSoftLinkCreated.ItshouldbeHardLink
Created.
Beginnerscanbeconfusedbecauseofmisprint.
http://www.geekride.com/hardlinkvssoftlink/
5/11
6/13/2016
HardLinkvsSoftLink|GeekRide
Pleasechangeittohardlink.
Thanks
Regards
Elex
Reply(/hardlinkvssoftlink/?replytocom=115751#respond)
5.Moneybags(http://finance.google.com/)says:
September19,2013at2:32AM(http://www.geekride.com/hardlinkvssoftlink/#comment146272)
Inyoursecondgraphic,IthinkyoushouldnotcallwhatisvisibletotheuseraSoftLinkitsconfusing.
RecommendyoucallthatboxjustLinksinceallhardlinksareactuallynormalfilelinksanyway(theresno
differencebetweentheoriginalfileandthesecondlink).
Reply(/hardlinkvssoftlink/?replytocom=146272#respond)
6.RoseHosting(http://www.rosehosting.com)says:
October27,2013at3:23AM(http://www.geekride.com/hardlinkvssoftlink/#comment156432)
Excellentwaytoexplainthings.Maybeonthehardlinksillustrationdiagramtheuservisiblepartshouldve
stateLinkCreatedorsimilarratherthanSoftLinkCreated,buthowever,veryslickwaytorepresent
thedifferences.Nicepost,keepupthegoodwork.
Regards!
Reply(/hardlinkvssoftlink/?replytocom=156432#respond)
7.Miguel(http://www.facebook.com/profile.php?id=100003451581988)says:
December28,2013at8:26PM(http://www.geekride.com/hardlinkvssoftlink/#comment186519)
overcurrentchangemeansthatyourUSBportcaonntsustainthediskenergyrequirements.IthinkUSB
portshaveamaximum500mAouptut(andsomelaptopsevenless).IhaveaUSB3GmodemwithaY
cablethatgetsenergyfromtwoUSBports.MyDelllaptophas4USBportsandthemodemonlyworkswith2of
themtheother2caonntgiveenoughcurrent.AndifyouhavemoreUSBdevices,theyalladdup.Tryremovingall
otherUSBdevicesorusingaexternalpoweredUSBhubbetweenyoulaptop/PCandthedisk.
Reply(/hardlinkvssoftlink/?replytocom=186519#respond)
8.
seoconsultancyservices
(http://www.planetaprodental.com/forum/your_seo_assistance_moral_web_optimization_and_competitor_monitoring)
says:
February26,2014at1:38PM(http://www.geekride.com/hardlinkvssoftlink/#comment211930)
allthetimeiusedtoreadsmallerarticlesorreviewsthatalsocleartheirmotive,andthatisalsohappeningwiththis
post
whichIamreadingnow.
Reply(/hardlinkvssoftlink/?replytocom=211930#respond)
9.notdave(http://jabber.me)says:
March3,2014at3:01PM(http://www.geekride.com/hardlinkvssoftlink/#comment214607)
/bits/now/tvshowhere
IwanttoaddtoexportsforNFSserverbutwithoutusingquotesorbackslashtoovercomespaces
http://www.geekride.com/hardlinkvssoftlink/
6/11
6/13/2016
HardLinkvsSoftLink|GeekRide
ubuntu:rightclick,makelink,renameto
/bits/now/thatoneshow
usingthatin/etc/exportsforNFSserver.
restartNFSserver:complainsaboutspaces!?!?
Reply(/hardlinkvssoftlink/?replytocom=214607#respond)
10.Chloie(http://url.sorgol.com/3s)says:
March20,2014at12:18AM(http://www.geekride.com/hardlinkvssoftlink/#comment234522)
Thisisamemototheadmin.IcametoyourpageviaBingbutitwashardtofindasyouwerenotonthe
firstpageofsearchresults.Iknowyoucouldhavemorevisitorstoyourwebsite.Ihavefoundacompany
whichofferstodramaticallyincreaseyourrankingsandtraffictoyoursite:http://ppbw.de/p79azImanagedtoget
closeto1000visitors/dayusingtheirservices,youcouldalsogetalotmoretargetedtrafficfromGooglethanyou
havenow.Theirservicesbroughtsignificantlymorevisitorstomysite.Ihopethishelps!
Reply(/hardlinkvssoftlink/?replytocom=234522#respond)
11.svgsays:
March29,2014at11:11PM(http://www.geekride.com/hardlinkvssoftlink/#comment244835)
Q.HowcanIfindallthefileshavingHardLinksinmysystem?
A.Usethiscommandforthesamefind/links+2typefexeclsli{}\
Ibelievethisisincorrect.Itshouldbe+1(not+2)meaningMORETHAN1link.Ifyouuse+2,youwillgetalistof
inodesthathave3ormorelinks.Itstricky.Itsnot>=(asyouwouldexpect).Itsjust>.
Thanksfortheterrificpost.Ineededalinkrefresher.)
Reply(/hardlinkvssoftlink/?replytocom=244835#respond)
12.largechickencoop(https://www.youtube.com/watch?v=N6gPWCqPDdE)says:
April29,2014at8:46PM(http://www.geekride.com/hardlinkvssoftlink/#comment263446)
Youmightalsodiscoverthataneggortwohasbeencrackedopen.
Dependingontheclimateaswellasthebreeds,some
hensyieldevenmoreorperhapsmuchlesseggs
Reply(/hardlinkvssoftlink/?replytocom=263446#respond)
13.Aravindsays:
July31,2014at7:23PM(http://www.geekride.com/hardlinkvssoftlink/#comment327555)
Q.Howtocheckwhetherafilehaveanysoftlinkpointingtoit?
A.Tillnow,Iamnotawareofanywaytodothat.IfIwillfindany,Iwillsurelyupdatemypost.
Answer:Ithink,aftercreatingasoftlink,ifwedolsl,theoutputshowstheletterlatbeginingwherethe
permissionsareshown.
Reply(/hardlinkvssoftlink/?replytocom=327555#respond)
Napstersays:
March15,2015at6:38PM(http://www.geekride.com/hardlinkvssoftlink/#comment416692)
HiAravind
Youareanswering,howtocheckwhetherthefile/directoryyouareseeingisasoftlinkorarealfile/directory.I
http://www.geekride.com/hardlinkvssoftlink/
7/11
6/13/2016
HardLinkvsSoftLink|GeekRide
wascuriousaboutwhetherthereisawaytoknowatthesource,whetherthereisasymlinkpointingtoit.
Reply(/hardlinkvssoftlink/?replytocom=416692#respond)
14.Pallabsays:
September17,2014at6:25PM(http://www.geekride.com/hardlinkvssoftlink/#comment369157)
Hi,
Thanksforsharingtheinfo:)
Onecommentregthepost,
2ndimageisshowingassoftlinkbutitshouldbehardlink
Reply(/hardlinkvssoftlink/?replytocom=369157#respond)
15.venkisays:
October15,2014at4:11PM(http://www.geekride.com/hardlinkvssoftlink/#comment391361)
Greatarticleandwellexplained.Cheers
Reply(/hardlinkvssoftlink/?replytocom=391361#respond)
16.Johnsays:
December12,2014at8:46AM(http://www.geekride.com/hardlinkvssoftlink/#comment416021)
Veryhelpful,clearexamplesandagooddidactictone.Theusageconditionexplanationwasuseful.
Reply(/hardlinkvssoftlink/?replytocom=416021#respond)
17.HariDhanalakoti(https://www.facebook.com/hari.dhanalakoti)says:
January7,2015at5:45PM(http://www.geekride.com/hardlinkvssoftlink/#comment416130)
Nicepost,keepupthegoodwork.
Reply(/hardlinkvssoftlink/?replytocom=416130#respond)
18.ShellScript|dhirendrainterviewprepare(https://dhirendrainterviewprepare.wordpress.com/2015/01/30/shellscript/)
says:
January30,2015at4:42PM(http://www.geekride.com/hardlinkvssoftlink/#comment416189)
[]http://www.geekride.com/hardlinkvssoftlink/[]
Reply(/hardlinkvssoftlink/?replytocom=416189#respond)
19.SajinVk(https://www.facebook.com/app_scoped_user_id/10152701522946158/)says:
February3,2015at10:42AM(http://www.geekride.com/hardlinkvssoftlink/#comment416200)
Howtocheckwhetherafilehaveanysoftlinkpointingtoit?
cantweusethesamecommandwhichisusedtofindsoftlinks
find/typel|xargslsl|grep"file_name"
Reply(/hardlinkvssoftlink/?replytocom=416200#respond)
20.SajinVk(https://www.facebook.com/app_scoped_user_id/10152701522946158/)says:
February3,2015at10:42AM(http://www.geekride.com/hardlinkvssoftlink/#comment416201)
Howtocheckwhetherafilehaveanysoftlinkpointingtoit?
cantweusethesamecommandwhichisusedtofindsoftlinks
find/typel|xargslsl|grep"file_name"
Reply(/hardlinkvssoftlink/?replytocom=416201#respond)
http://www.geekride.com/hardlinkvssoftlink/
8/11
6/13/2016
HardLinkvsSoftLink|GeekRide
21.Whatisthedifferencebetweenahardlinkandasymboliclink?(http://popularubuntuquestions.com/whatisthe
differencebetweenahardlinkandasymboliclink/)says:
April27,2015at2:17PM(http://www.geekride.com/hardlinkvssoftlink/#comment416989)
[]noobandexWindozeuserfriendlyexplanation,withnicediagramsandaFAQcheckoutthispage
http://www.geekride.com/hardlinkvssoftlink/.Theircopyrightrestrictionspreventmefromexcerptingtheirstuff,so
sufficeitthatIprovide[]
Reply(/hardlinkvssoftlink/?replytocom=416989#respond)
22.zaidrashwani(http://zrashwani.com)says:
May24,2015at12:28AM(http://www.geekride.com/hardlinkvssoftlink/#comment417349)
veryinformativeandclearexplanation,
Thankyou
Reply(/hardlinkvssoftlink/?replytocom=417349#respond)
23.KGuruNathan(https://www.facebook.com/app_scoped_user_id/971582289560795/)says:
June19,2015at11:50PM(http://www.geekride.com/hardlinkvssoftlink/#comment417471)
nicepost
Reply(/hardlinkvssoftlink/?replytocom=417471#respond)
24.GururajSMorabad(https://www.facebook.com/app_scoped_user_id/10153007259707898/)says:
June30,2015at9:14AM(http://www.geekride.com/hardlinkvssoftlink/#comment417481)
Clearlyunderstood..Goodone
Reply(/hardlinkvssoftlink/?replytocom=417481#respond)
25.HowtoinstallDBFitonEC2|OptimalDataEngine(http://www.ode.ninja/howtoinstalldbfitonec2/)says:
July8,2015at1:27AM(http://www.geekride.com/hardlinkvssoftlink/#comment417491)
[]links,whicharelikeshortcutsinwindows.Thereissomethinginthebootsequencewhichrequiressymbolic
ratherthanhardlinks./etc/init.disthefolderfor[]
Reply(/hardlinkvssoftlink/?replytocom=417491#respond)
26.NaveenGupta(https://www.facebook.com/app_scoped_user_id/929868403744563/)says:
August8,2015at4:17AM(http://www.geekride.com/hardlinkvssoftlink/#comment417559)
NycExplanation
Reply(/hardlinkvssoftlink/?replytocom=417559#respond)
27.Ubuntu:Whatisthedifferencebetweenahardlinkandasymboliclink?UbuntuLinuxQuestions
(http://ubuntu.itsprite.com/ubuntuwhatisthedifferencebetweenahardlinkandasymboliclink/)says:
October13,2015at10:30PM(http://www.geekride.com/hardlinkvssoftlink/#comment417731)
[]noobandexWindozeuserfriendlyexplanation,withnicediagramsandaFAQcheckoutthispage
http://www.geekride.com/hardlinkvssoftlink/.Theircopyrightrestrictionspreventmefromexcerptingtheirstuff,so
sufficeitthatIprovide[]
Reply(/hardlinkvssoftlink/?replytocom=417731#respond)
28.HuangJie(https://www.facebook.com/app_scoped_user_id/852021814895352/)says:
November11,2015at10:55AM(http://www.geekride.com/hardlinkvssoftlink/#comment417841)
veryclearexplanation
Reply(/hardlinkvssoftlink/?replytocom=417841#respond)
http://www.geekride.com/hardlinkvssoftlink/
9/11
6/13/2016
HardLinkvsSoftLink|GeekRide
29.lnlnsfs.symlinkrequireIT (http://tech.itdadao.com/8953.html)says:
May30,2016at9:50AM(http://www.geekride.com/hardlinkvssoftlink/#comment418043)
[]http://www.geekride.com/hardlinkvssoftlink/[]
Reply(/hardlinkvssoftlink/?replytocom=418043#respond)
30.lnlnsfs.symlinkrequire| (http://www.shellsec.com/news/23427.html)says:
May30,2016at11:02AM(http://www.geekride.com/hardlinkvssoftlink/#comment418044)
[]http://www.geekride.com/hardlinkvssoftlink/[]
Reply(/hardlinkvssoftlink/?replytocom=418044#respond)
31.Mausamsays:
May30,2016at10:51PM(http://www.geekride.com/hardlinkvssoftlink/#comment418045)
Explationisverygoos
Reply(/hardlinkvssoftlink/?replytocom=418045#respond)
LeaveaReply
Name(required)
Mail(willnotbepublished)(required)
Website
SubmitComment
AreYouHuman#
2=ten
Notifymeoffollowupcommentsviaemail
Notifymeoffollowupcommentsbyemail.
Notifymeofnewpostsbyemail.
Ubuntu12.10released(http://www.geekride.com/ubuntulatestreleased/)
TechTip:Monitoringwithkill(http://www.geekride.com/techtipmonitoringwithkill/)
http://www.geekride.com/hardlinkvssoftlink/
10/11
6/13/2016
HardLinkvsSoftLink|GeekRide
LinuxRide/GeekRide
1,431likes
LikePage
Share
Bethefirstofyourfriendstolikethis
Follow@linuxride
9,386followers
SubscriptionOptions:
(http://feeds.feedburner.com/GeekRideLinuxTipsTricksHacks)(http://feeds.feedburner.com/GeekRide
LinuxTipsTricksHacks)(https://plus.google.com/106162734322241117293)
Subscribeforemailupdates
Subscribe
Search
Categories
Categories SelectCategory
GotsomethinginMind
IfthereissomethingyougotinMind,letusknowandwewillwriteaboutit.Usethecontactuspage.
20092012GeekRide.AllrightsreservedTermsofUse(http://www.geekride.com/disclaimer/)|CopyrightInfo
(http://www.geekride.com/copyright/)|ContactUs(http://www.geekride.com/contactus/)
http://www.geekride.com/hardlinkvssoftlink/
11/11