{"id":7,"date":"2011-12-28T13:31:00","date_gmt":"2011-12-28T13:31:00","guid":{"rendered":"http:\/\/jjamwal.in\/blog\/?p=7"},"modified":"2011-12-28T13:31:00","modified_gmt":"2011-12-28T13:31:00","slug":"essential-os-basics-1-deleting-files-folders-in-linux","status":"publish","type":"post","link":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/","title":{"rendered":"Essential OS Basics 2: Deleting files &#038; folders in Linux"},"content":{"rendered":"<div style=\"text-align: left;\" dir=\"ltr\">This series of posts will contain a list of some very useful Linux commands that you might need every now and then. This one is\u00a0 a small tutorial on how to delete files in linux.<\/div>\n<div style=\"text-align: left;\" dir=\"ltr\">\u00a0First post on Linux networking <a href=\"http:\/\/jjamwal.in\/blog\/2011\/07\/basic-linux-networking.html\">here<\/a><\/div>\n<div style=\"text-align: left;\" dir=\"ltr\"><span style=\"text-decoration: underline;\"><strong><br \/>\n1. Delete files and directories<\/strong><\/span><strong><br \/>\n<\/strong><em><strong>rm command <\/strong><\/em><\/div>\n<div style=\"text-align: left;\" dir=\"ltr\">\n<p>Let us assume you want to delete some files in directory \/usr\/tmp . You first navigate to directory using command<\/p>\n<p><em><strong>cd \/usr\/tmp<\/strong><\/em><\/p>\n<p>Now if you want to delete a particular file use rm as following:<\/p>\n<p><strong><em>rm filename<\/em> <\/strong><\/p>\n<p>or you can run following command from whichever directory you are in.<\/p>\n<p><em><strong>rm \/usr\/tmp\/filename<\/strong><\/em><\/p>\n<p>But if you want to delete all the files in that directory, use rm as following:<\/p>\n<p><em><strong>rm *.*<\/strong><\/em><\/p>\n<p>To refine it further, if you want to delete only a few files but leave the rest, you\u2019ll have to use wild-cards. I\u2019ll explain it first using deleting by extension example. Let us assume that you have a collection of zip, mp3 and bin files (with extensions .zip, .mp3 and .bin respectively) and you want to delete only mp3 files, then execute :<\/p>\n<p><em><strong>rm *.mp3<\/strong><\/em><\/p>\n<p>It\u2019ll delete all mp3 files file leaving all zip and bin files intact. But if you want to delete .bin files too, just add the extension like this:<\/p>\n<p><em><strong>rm *.mp3 *.bin<\/strong><\/em><\/p>\n<p>In order to delete directories, you have to modify it a little by adding -rf, If you have a directory named DIR which you want to delete, execute<\/p>\n<p><em><strong>rm -rf DIR<\/strong><\/em><\/p>\n<p>As posted earlier, you can use *.* wildcard to delete everything in the directory including all the sub-directories:<\/p>\n<p><em><strong>rm -rf *<\/strong><\/em><\/p>\n<p>Similarly you can delete files based upon their names too. Executing<\/p>\n<p><em><strong>rm a*.mp3<\/strong><\/em><\/p>\n<p>will delete all mp3 files which start with alphabet a, while<\/p>\n<p><em><strong>rm -rf a*<\/strong><\/em><\/p>\n<p>will delete every file and directory which starts with a<\/p>\n<p>Apart from this, you might come across a scenario where you have to find and delete some type of files from multiple directories \/ folders. In this case I\u2019m assuming that you need to delete all mp3 files located in various sub-folders inside \/usr\/tmp\/. In such a case use find command<br \/>\n<strong><br \/>\n<em>find \/usr\/tmp\/ -type f -iname \u201cmp3\u2033 -delete<\/em><\/strong><\/p>\n<p>or<\/p>\n<p><em><strong>find \/usr\/tmp -type f -iname \u201cmp3\u2033 -exec rm -f {} ;<\/strong><\/em><\/p>\n<p>If you replace path <em><strong>\/usr\/tmp<\/strong><\/em> with just a <em><strong>\/<\/strong><\/em> it\u2019ll find and delete ALL mp3 files on your computer. So be careful<\/p>\n<p>Useful links:<\/p>\n<p><a href=\"http:\/\/www.cyberciti.biz\/\">http:\/\/www.cyberciti.biz<\/a><br \/>\n<a href=\"http:\/\/www.linuxquestions.org\/\">www.linuxquestions.org<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This series of posts will contain a list of some very useful Linux commands that you might need every now and then. This one is\u00a0 a small tutorial on how to delete files in linux. \u00a0First post on Linux networking here 1. Delete files and directories rm command Let us assume you want to delete&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,80],"tags":[228],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-linux-2","category-tutorial-2","tag-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Essential OS Basics 2: Deleting files &amp; folders in Linux - \u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Essential OS Basics 2: Deleting files &amp; folders in Linux - \u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?\" \/>\n<meta property=\"og:description\" content=\"This series of posts will contain a list of some very useful Linux commands that you might need every now and then. This one is\u00a0 a small tutorial on how to delete files in linux. \u00a0First post on Linux networking here 1. Delete files and directories rm command Let us assume you want to delete...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"\u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/jjamwalin\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/jjamwalin\" \/>\n<meta property=\"article:published_time\" content=\"2011-12-28T13:31:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jjamwal.in\/yayavar\/wp-content\/uploads\/2022\/01\/jjamwalin-logo-2-small.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jaidev Jamwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JaidevJamwal\" \/>\n<meta name=\"twitter:site\" content=\"@JaidevJamwal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jaidev Jamwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/\"},\"author\":{\"name\":\"Jaidev Jamwal\",\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/#\\\/schema\\\/person\\\/4b29cbc0fe18a86ec09a7c01177deac4\"},\"headline\":\"Essential OS Basics 2: Deleting files &#038; folders in Linux\",\"datePublished\":\"2011-12-28T13:31:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/\"},\"wordCount\":415,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/#\\\/schema\\\/person\\\/4b29cbc0fe18a86ec09a7c01177deac4\"},\"keywords\":[\"Linux\"],\"articleSection\":[\"linux\",\"Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/\",\"url\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/\",\"name\":\"Essential OS Basics 2: Deleting files & folders in Linux - \u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/#website\"},\"datePublished\":\"2011-12-28T13:31:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/essential-os-basics-1-deleting-files-folders-in-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Essential OS Basics 2: Deleting files &#038; folders in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/#website\",\"url\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/\",\"name\":\"\u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?\",\"description\":\"Travel, Defence, Books &amp; Photography\",\"publisher\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/#\\\/schema\\\/person\\\/4b29cbc0fe18a86ec09a7c01177deac4\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/#\\\/schema\\\/person\\\/4b29cbc0fe18a86ec09a7c01177deac4\",\"name\":\"Jaidev Jamwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/jjamwalin-logo-2-small.jpg\",\"url\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/jjamwalin-logo-2-small.jpg\",\"contentUrl\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/jjamwalin-logo-2-small.jpg\",\"width\":200,\"height\":200,\"caption\":\"Jaidev Jamwal\"},\"logo\":{\"@id\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/jjamwalin-logo-2-small.jpg\"},\"sameAs\":[\"http:\\\/\\\/jjamwal.in\",\"https:\\\/\\\/www.facebook.com\\\/jjamwalin\",\"https:\\\/\\\/www.instagram.com\\\/jamwal.jaidev\\\/\",\"https:\\\/\\\/x.com\\\/JaidevJamwal\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCuqw1ikTDrd3Lzf6RivuR6Q\"],\"url\":\"https:\\\/\\\/jjamwal.in\\\/yayavar\\\/author\\\/jaidev\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Essential OS Basics 2: Deleting files & folders in Linux - \u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"Essential OS Basics 2: Deleting files & folders in Linux - \u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?","og_description":"This series of posts will contain a list of some very useful Linux commands that you might need every now and then. This one is\u00a0 a small tutorial on how to delete files in linux. \u00a0First post on Linux networking here 1. Delete files and directories rm command Let us assume you want to delete...","og_url":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/","og_site_name":"\u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?","article_publisher":"https:\/\/www.facebook.com\/jjamwalin","article_author":"https:\/\/www.facebook.com\/jjamwalin","article_published_time":"2011-12-28T13:31:00+00:00","og_image":[{"width":200,"height":200,"url":"https:\/\/jjamwal.in\/yayavar\/wp-content\/uploads\/2022\/01\/jjamwalin-logo-2-small.jpg","type":"image\/jpeg"}],"author":"Jaidev Jamwal","twitter_card":"summary_large_image","twitter_creator":"@JaidevJamwal","twitter_site":"@JaidevJamwal","twitter_misc":{"Written by":"Jaidev Jamwal","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/#article","isPartOf":{"@id":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/"},"author":{"name":"Jaidev Jamwal","@id":"https:\/\/jjamwal.in\/yayavar\/#\/schema\/person\/4b29cbc0fe18a86ec09a7c01177deac4"},"headline":"Essential OS Basics 2: Deleting files &#038; folders in Linux","datePublished":"2011-12-28T13:31:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/"},"wordCount":415,"commentCount":0,"publisher":{"@id":"https:\/\/jjamwal.in\/yayavar\/#\/schema\/person\/4b29cbc0fe18a86ec09a7c01177deac4"},"keywords":["Linux"],"articleSection":["linux","Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/","url":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/","name":"Essential OS Basics 2: Deleting files & folders in Linux - \u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?","isPartOf":{"@id":"https:\/\/jjamwal.in\/yayavar\/#website"},"datePublished":"2011-12-28T13:31:00+00:00","breadcrumb":{"@id":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jjamwal.in\/yayavar\/essential-os-basics-1-deleting-files-folders-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jjamwal.in\/yayavar\/"},{"@type":"ListItem","position":2,"name":"Essential OS Basics 2: Deleting files &#038; folders in Linux"}]},{"@type":"WebSite","@id":"https:\/\/jjamwal.in\/yayavar\/#website","url":"https:\/\/jjamwal.in\/yayavar\/","name":"\u0905\u0930\u0947 \u092f\u093e\u092f\u093e\u0935\u0930 \u0930\u0939\u0947\u0917\u093e \u092f\u093e\u0926?","description":"Travel, Defence, Books &amp; Photography","publisher":{"@id":"https:\/\/jjamwal.in\/yayavar\/#\/schema\/person\/4b29cbc0fe18a86ec09a7c01177deac4"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jjamwal.in\/yayavar\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jjamwal.in\/yayavar\/#\/schema\/person\/4b29cbc0fe18a86ec09a7c01177deac4","name":"Jaidev Jamwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jjamwal.in\/yayavar\/wp-content\/uploads\/2022\/01\/jjamwalin-logo-2-small.jpg","url":"https:\/\/jjamwal.in\/yayavar\/wp-content\/uploads\/2022\/01\/jjamwalin-logo-2-small.jpg","contentUrl":"https:\/\/jjamwal.in\/yayavar\/wp-content\/uploads\/2022\/01\/jjamwalin-logo-2-small.jpg","width":200,"height":200,"caption":"Jaidev Jamwal"},"logo":{"@id":"https:\/\/jjamwal.in\/yayavar\/wp-content\/uploads\/2022\/01\/jjamwalin-logo-2-small.jpg"},"sameAs":["http:\/\/jjamwal.in","https:\/\/www.facebook.com\/jjamwalin","https:\/\/www.instagram.com\/jamwal.jaidev\/","https:\/\/x.com\/JaidevJamwal","https:\/\/www.youtube.com\/channel\/UCuqw1ikTDrd3Lzf6RivuR6Q"],"url":"https:\/\/jjamwal.in\/yayavar\/author\/jaidev\/"}]}},"_links":{"self":[{"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":0,"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jjamwal.in\/yayavar\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}