{"id":3533,"date":"2021-11-03T05:54:57","date_gmt":"2021-11-03T05:54:57","guid":{"rendered":"https:\/\/ownwebservers.com\/kb\/?p=3533"},"modified":"2021-11-03T05:54:57","modified_gmt":"2021-11-03T05:54:57","slug":"how-to-remove-files-in-linux-terminal","status":"publish","type":"post","link":"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/","title":{"rendered":"How to Remove Files in Linux Terminal?"},"content":{"rendered":"<p>In this tutorial you will understand, how to use the\u00a0<strong>rm<\/strong>,\u00a0<strong>unlink<\/strong>\u00a0and\u00a0<strong>rmdir<\/strong> commands to delete files in Linux.<\/p>\n<h2>How to Remove Files<\/h2>\n<p>You can use\u00a0<strong>rm<\/strong>\u00a0(remove) or\u00a0<strong>unlink<\/strong>\u00a0command to remove or delete a file from the Linux command line.<\/p>\n<p>The\u00a0<strong>rm<\/strong>\u00a0command allows you to remove multiple files at once. With\u00a0<strong>unlink<\/strong>\u00a0command, you can delete only a single file.<\/p>\n<p>While removing files or directories you should be extra careful, as if the file is deleted, you won\u2019t be able to recover it easily.<\/p>\n<ul>\n<li>Use the\u00a0<strong>rm<\/strong>\u00a0or\u00a0<strong>unlink<\/strong>\u00a0command to delete a single file followed by the file name:<\/li>\n<\/ul>\n<blockquote><p>unlink \/home\/admin\/directoryname myfile<\/p>\n<p>rm \/home\/admin\/directoryname\/myfile<\/p><\/blockquote>\n<p>You will be notified for confirmation if the file is write-protected, as shown below. Type\u00a0<strong>y<\/strong>\u00a0and hit\u00a0<strong>Enter<\/strong>\u00a0key to remove the file, or else, it will be deleted without prompting if the file is not write-protected.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<blockquote><p>rm: remove write-protected regular empty file \u2018file\u2019?<\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<ul>\n<li>Use the\u00a0<strong>rm<\/strong>\u00a0command to delete multiple files at once followed by the file names separated with space:<\/li>\n<\/ul>\n<blockquote><p>rm \/home\/admin\/directoryname\/myfile1<\/p>\n<p>rm \/home\/admin\/directoryname\/myfile2<\/p>\n<p>rm \/home\/admin\/directoryname\/myfile3<\/p><\/blockquote>\n<p><strong>OR<\/strong><\/p>\n<blockquote><p>cd \/home\/admin\/directoryname<\/p>\n<p>rm myfile1 myfile2 myfile3<\/p><\/blockquote>\n<p><strong>OR<\/strong><\/p>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<blockquote><p>rm \/home\/admin\/directoryname\/myfile*<\/p><\/blockquote>\n<p>To match multiple files, you can use an asterisk\u00a0<strong>(*)<\/strong>\u00a0and regular expansions. Execute the following command to remove all\u00a0<strong>.pdf<\/strong>\u00a0files placed in the current directory:<\/p>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<blockquote><p>rm \/home\/admin\/directoryname\/*.pdf<\/p><\/blockquote>\n<\/div>\n<\/div>\n<p>Run the\u00a0<strong>ls<\/strong>\u00a0command to list the files if you are using regular expansions so that you can see what files will be deleted before running the\u00a0<strong>rm<\/strong>\u00a0command.<\/p>\n<ul>\n<li>Run the\u00a0<strong>rm<\/strong>\u00a0command with the\u00a0<strong>-i<\/strong>\u00a0option to verify each file before deleting it:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<blockquote><p>rm -i \/home\/admin\/directoryname\/myfile(s)<\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<\/div>\n<\/div>\n<ul>\n<li>You can run the\u00a0<strong>-f<\/strong>\u00a0(force) option with\u00a0<strong>rm<\/strong>\u00a0command to remove the files without prompting even if the files are write-protected:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<blockquote><p>rm -f \/home\/admin\/directoryname\/myfile(s)<\/p>\n<p>&nbsp;<\/p><\/blockquote>\n<\/div>\n<\/div>\n<ul>\n<li>You can also combine rm options. You can run the following command to delete all .txt files in the present directory without a prompt in verbose mode.<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<blockquote><p>rm -fv \/home\/admin\/directoryname\/*.txt<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you will understand, how to use the\u00a0rm,\u00a0unlink\u00a0and\u00a0rmdir commands to delete files in Linux. How to Remove Files You can use\u00a0rm\u00a0(remove) or\u00a0unlink\u00a0command to remove or delete a file from the Linux command line. The\u00a0rm\u00a0command allows you to remove multiple files at once. With\u00a0unlink\u00a0command, you can delete only a single file. While removing files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-3533","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v15.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Remove Files in Linux Terminal? - OWS KB<\/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:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Remove Files in Linux Terminal? - OWS KB\" \/>\n<meta property=\"og:description\" content=\"In this tutorial you will understand, how to use the\u00a0rm,\u00a0unlink\u00a0and\u00a0rmdir commands to delete files in Linux. How to Remove Files You can use\u00a0rm\u00a0(remove) or\u00a0unlink\u00a0command to remove or delete a file from the Linux command line. The\u00a0rm\u00a0command allows you to remove multiple files at once. With\u00a0unlink\u00a0command, you can delete only a single file. While removing files [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/\" \/>\n<meta property=\"og:site_name\" content=\"OWS KB\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-03T05:54:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\">\n\t<meta name=\"twitter:data1\" content=\"admin\">\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data2\" content=\"1 minute\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#website\",\"url\":\"https:\/\/ownwebservers.com\/kb\/\",\"name\":\"OWS KB\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/ownwebservers.com\/kb\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/#webpage\",\"url\":\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/\",\"name\":\"How to Remove Files in Linux Terminal? - OWS KB\",\"isPartOf\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/#website\"},\"datePublished\":\"2021-11-03T05:54:57+00:00\",\"dateModified\":\"2021-11-03T05:54:57+00:00\",\"author\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/#\/schema\/person\/4a40fe3fe17a08ddd1d7c113668e75f2\"},\"breadcrumb\":{\"@id\":\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/\",\"url\":\"https:\/\/ownwebservers.com\/kb\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/\",\"url\":\"https:\/\/ownwebservers.com\/kb\/how-to-remove-files-in-linux-terminal\/\",\"name\":\"How to Remove Files in Linux Terminal?\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#\/schema\/person\/4a40fe3fe17a08ddd1d7c113668e75f2\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/ownwebservers.com\/kb\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ba5db5841d48bd7517bb2583e13983e6d2fa56a4099a0b3c61ad2daefc321303?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/ownwebservers.com\/kb\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/3533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/comments?post=3533"}],"version-history":[{"count":1,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/3533\/revisions"}],"predecessor-version":[{"id":3534,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/posts\/3533\/revisions\/3534"}],"wp:attachment":[{"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/media?parent=3533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/categories?post=3533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ownwebservers.com\/kb\/wp-json\/wp\/v2\/tags?post=3533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}