{"id":79070,"date":"2026-11-17T01:52:28","date_gmt":"2026-11-17T01:52:28","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=79070"},"modified":"2026-11-17T01:52:28","modified_gmt":"2026-11-17T01:52:28","slug":"linux-basics-02-files","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=79070","title":{"rendered":"Linux Basics 02 \u2014 Paths, Files, and Links"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bangla.sitestree.com\/?name=linux-course-index\">Linux course index<\/a> \u00b7 <a href=\"https:\/\/bangla.sitestree.com\/?cat=1990\">Linux Basics category<\/a> \u00b7 Lesson 2 of 8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AI disclosure<\/strong> \u2014 AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Learning goal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate confidently, copy and rename a file, and explain the difference between hard links and symbolic links.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concepts and setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An absolute path starts at \/. A relative path starts at your current directory. A leading dot normally hides a name from plain ls. Quote paths containing spaces. Copying duplicates data, renaming changes a directory entry, a hard link adds another name for the same inode, and a symbolic link stores a path. Use a fresh temporary directory and never practise recursive deletion on a real project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Build a directory tree and compare links<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>lab=$(mktemp -d)\ncd &quot;$lab&quot; || exit\nmkdir -p docs archive\nprintf 'lab notes\\n' &gt; 'docs\/weekly notes.txt'\ncp 'docs\/weekly notes.txt' archive\/notes-copy.txt\nln 'docs\/weekly notes.txt' docs\/same-inode.txt\nln -s 'weekly notes.txt' docs\/shortcut.txt\nmv 'docs\/weekly notes.txt' 'docs\/renamed notes.txt'\nls -1 docs\nstat -c '%i %h %n' 'docs\/renamed notes.txt' docs\/same-inode.txt\nreadlink docs\/shortcut.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>renamed notes.txt\nsame-inode.txt\nshortcut.txt\n54123 2 docs\/renamed notes.txt\n54123 2 docs\/same-inode.txt\nweekly notes.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The file number is only an example. The two hard-linked names keep working after the rename, but the symbolic link now points to a missing relative path.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Distinguish a symlink from its target<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>test -L docs\/shortcut.txt &amp;&amp; printf 'link exists\\n'\ntest -e docs\/shortcut.txt || printf 'target missing\\n'\ncmp 'docs\/renamed notes.txt' archive\/notes-copy.txt &amp;&amp; printf 'copy matches\\n'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>link exists\ntarget missing\ncopy matches<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both test results matter. -e follows the link to the target, while -L checks the link itself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Questions only<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick-check questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>What does cd &#8211; do?<\/li>\n\n\n<li>Why does renaming the original path not break the hard link?<\/li>\n\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Assessment questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>Write a relative path from the lab root to the archive copy.<\/li>\n\n\n<li>What would you change in the ln -s command to make a new working shortcut inside docs?<\/li>\n\n\n<li>Would editing the hard-linked file necessarily change the separate copy? Explain.<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Questions and answers<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick-check answers<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li><strong>What does cd &#8211; do?<\/strong><br><strong>Answer<\/strong> \u2014 It switches to the previous working directory and normally prints that path.<\/li>\n\n\n<li><strong>Why does renaming the original path not break the hard link?<\/strong><br><strong>Answer<\/strong> \u2014 The hard link is a second directory entry for the same inode.<\/li>\n\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Assessment answer key<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li><strong>Write a relative path from the lab root to the archive copy.<\/strong><br><strong>Answer<\/strong> \u2014 archive\/notes-copy.txt.<\/li>\n\n\n<li><strong>What would you change in the ln -s command to make a new working shortcut inside docs?<\/strong><br><strong>Answer<\/strong> \u2014 Create a new link with ln -s &#8216;renamed notes.txt&#8217; docs\/new-shortcut.txt. Its target is relative to the link&#8217;s parent directory.<\/li>\n\n\n<li><strong>Would editing the hard-linked file necessarily change the separate copy? Explain.<\/strong><br><strong>Answer<\/strong> \u2014 No. cp made a separate file, while the hard link shares the original inode.<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Source articles on this site<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=9562\">\u0987\u0989\u09a8\u09bf\u0995\u09cd\u09b8\u0983 \u09a1\u09bf\u09b0\u09c7\u0995\u09cd\u099f\u09b0\u09bf \u09ac\u09cd\u09af\u09ac\u09b8\u09cd\u09a5\u09be\u09aa\u09a8\u09be (Unix folder\/directory Management)<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=9577\">\u0987\u0989\u09a8\u09bf\u0995\u09cd\u09b8\u0983 \u09ab\u09be\u0987\u09b2 \u09ac\u09cd\u09af\u09ac\u09b8\u09cd\u09a5\u09be\u09aa\u09a8\u09be (Unix \u2013 File Management)<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=78655\">30 mixed quiz questions on Linux Command Line Skills<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Continue the course<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Previous lesson 01 \u2014 Linux, the Shell, and Your First Lab. Next lesson 03 \u2014 Editing Text and Reading Files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bangla.sitestree.com\/?name=linux-course-index\">Linux course index<\/a> \u00b7 <a href=\"https:\/\/bangla.sitestree.com\/?cat=1990\">Linux Basics category<\/a> \u00b7 Lesson 2 of 8<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Navigate confidently, copy and rename a file, and explain the difference between hard links and symbolic links.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1990],"tags":[],"class_list":["post-79070","post","type-post","status-publish","format-standard","hentry","category-linux-basics","item-wrap"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":79102,"url":"http:\/\/bangla.sitestree.com\/?p=79102","url_meta":{"origin":79070,"position":0},"title":"Linux Administration Course \u2014 Start Here and Lesson Index","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"A 33-lesson Linux course from shell fundamentals to server administration, performance, and a recovery capstone.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79072,"url":"http:\/\/bangla.sitestree.com\/?p=79072","url_meta":{"origin":79070,"position":1},"title":"Linux Basics 04 \u2014 Pipes, Redirection, and Exit Status","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Route input, normal output, and errors, then detect a command failure inside a pipeline.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79071,"url":"http:\/\/bangla.sitestree.com\/?p=79071","url_meta":{"origin":79070,"position":2},"title":"Linux Basics 03 \u2014 Editing Text and Reading Files","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Edit a text file in a terminal and verify the exact lines you saved.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79076,"url":"http:\/\/bangla.sitestree.com\/?p=79076","url_meta":{"origin":79070,"position":3},"title":"Linux Basics 08 \u2014 Archives, Compression, and a Restore Test","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Create and inspect an archive, then prove that you can recover a file from it.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79074,"url":"http:\/\/bangla.sitestree.com\/?p=79074","url_meta":{"origin":79070,"position":4},"title":"Linux Basics 06 \u2014 File Permissions and umask","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Read a permission string, predict umask results, and choose a minimal permission change.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79075,"url":"http:\/\/bangla.sitestree.com\/?p=79075","url_meta":{"origin":79070,"position":5},"title":"Linux Basics 07 \u2014 Processes, Jobs, and Signals","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Identify a process you own, inspect its state, and stop it gracefully.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79070"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79070\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79070"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}