{"id":6755,"date":"2019-10-26T05:08:40","date_gmt":"2019-10-26T05:08:40","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=6755"},"modified":"2019-10-28T05:50:11","modified_gmt":"2019-10-28T05:50:11","slug":"how-to-remove-files-and-directories-using-linux-terminal","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/","title":{"rendered":"How to Delete Files and Directories in Linux Terminal?"},"content":{"rendered":"<p>You will learn in this step by step guide, how to use the <strong>rm<\/strong>, <strong>unlink<\/strong> and <strong>rmdir<\/strong> commands to delete files and directories in Linux.<\/p>\n<h2>How to Remove Files<\/h2>\n<p>You can use <strong>rm<\/strong> (remove) or <strong>unlink<\/strong> command to remove or delete a file from the Linux command line.<\/p>\n<p>The <strong>rm<\/strong> command allows you to remove multiple files at once. With <strong>unlink<\/strong> command, 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&#8217;t be able to recover it easily.<\/p>\n<ul>\n<li>Use the <strong>rm<\/strong> or <strong>unlink<\/strong> command to delete a single file followed by the file name:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">unlink \/home\/admin\/directoryname myfile<\/p>\n<p style=\"padding-left: 30px;\">rm \/home\/admin\/directoryname\/myfile<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">You will be notified for confirmation if the file is write-protected, as shown below. Type <strong>y<\/strong> and hit <strong>Enter<\/strong> key to remove the file, or else, it will be deleted without prompting if the file is not write-protected.<\/p>\n<div class=\"vlt-box\">\n<div class=\"box-title\" style=\"padding-left: 30px;\">Output<\/div>\n<div class=\"box-content\" style=\"padding-left: 30px;\">\n<p style=\"padding-left: 30px;\">rm: remove write-protected regular empty file &#8216;file&#8217;?<\/p>\n<\/div>\n<\/div>\n<ul>\n<li>Use the <strong>rm<\/strong> command to delete multiple files at once followed by the file names separated with space:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rm \/home\/admin\/directoryname\/myfile1<\/p>\n<p style=\"padding-left: 30px;\">rm \/home\/admin\/directoryname\/myfile2<\/p>\n<p style=\"padding-left: 30px;\">rm \/home\/admin\/directoryname\/myfile3<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">OR<\/p>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">cd \/home\/admin\/directoryname<\/p>\n<p style=\"padding-left: 30px;\">rm myfile1 myfile2 myfile3<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">OR<\/p>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rm \/home\/admin\/directoryname\/myfile*<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">To match multiple files, you can use an asterisk <strong>(*)<\/strong> and regular expansions. Execute the following command to remove all <strong>.pdf<\/strong> files placed in the current directory:<\/p>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rm \/home\/admin\/directoryname\/*.pdf<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">Run the <strong>ls<\/strong> command to list the files if you are using regular expansions so that you can see what files will be deleted before running the <strong>rm<\/strong> command.<\/p>\n<ul>\n<li>Run the <strong>rm<\/strong> command with the <strong>-i<\/strong> option to verify each file before deleting it:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rm -i \/home\/admin\/directoryname\/myfile(s)<\/p>\n<\/div>\n<\/div>\n<ul>\n<li>You can run the <strong>-f<\/strong> (force) option with <strong>rm<\/strong> command 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<p style=\"padding-left: 30px;\">rm -f \/home\/admin\/directoryname\/myfile(s)<\/p>\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<p style=\"padding-left: 30px;\">rm -fv \/home\/admin\/directoryname\/*.txt<\/p>\n<\/div>\n<\/div>\n<h2>How to Remove Directories (Folders)<\/h2>\n<p>You can delete\/remove directories (folders) by using the <strong>rmdir<\/strong> and <strong>rm<\/strong> command in Linux.<\/p>\n<p><strong>rmdir<\/strong> is a command-line function that deletes empty directories\/folders while <strong>rm<\/strong> command deletes directories and their contents recursively.<\/p>\n<ul>\n<li>Run either <strong>rmdir<\/strong> or <strong>rm -d<\/strong> command to remove an empty directory followed by the directory name:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rmdir \/home\/admin\/directoryname<\/p>\n<p style=\"padding-left: 30px;\">rm -d \/home\/admin\/directoryname<\/p>\n<\/div>\n<\/div>\n<ul>\n<li>Use the <strong>rm<\/strong> command with the <strong>-r<\/strong> (recursive) option to delete non-empty directories and all the files inside them:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rm -r \/home\/admin\/directoryname<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">You will be prompted to confirm the deletion if a directory or a file inside the directory is write-protected.<\/p>\n<ul>\n<li>Run <strong>rm<\/strong> command with the <strong>-r<\/strong> (recursive) and <strong>-f<\/strong> options to delete non-empty directories and all the files without being prompted:<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">rm -rf \/home\/admin\/directoryname<\/p>\n<\/div>\n<\/div>\n<ul>\n<li>Run the <strong>rm -r<\/strong> command followed by the directory names separated by space to delete multiple directories at once.<\/li>\n<\/ul>\n<div class=\"vlt-box\">\n<div class=\"box-content\">\n<p style=\"padding-left: 30px;\">cd \/home\/admin\/directoryname<\/p>\n<p style=\"padding-left: 30px;\">rm -r directoryname1 directoryname2 directoryname3<\/p>\n<\/div>\n<\/div>\n<p style=\"padding-left: 30px;\">You can also use the asterisk <strong>(*)<\/strong> and regular expansions to match multiple directories the same as with files.<\/p>\n<h3>Conclusion<\/h3>\n<p>By now you are aware of how to use the Linux rm, rmdir and unlink commands to delete files and directories safely with the command line.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You will learn in this step by step guide, how to use the rm, unlink and rmdir commands to delete files and directories in Linux. How to Remove Files You can use rm (remove) or unlink command to remove or delete a file from the Linux command line. The rm command allows you to remove [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,4],"tags":[],"class_list":["post-6755","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-howtos","category-web-hosting-faq"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Delete Files and Directories in Linux Terminal?<\/title>\n<meta name=\"description\" content=\"You will learn in this KB article, how to remove files and directories with Linux Command Line using the Linux rm, rmdir and unlink command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Delete Files and Directories in Linux Terminal?\" \/>\n<meta property=\"og:description\" content=\"You will learn in this KB article, how to remove files and directories with Linux Command Line using the Linux rm, rmdir and unlink command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-26T05:08:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-28T05:50:11+00:00\" \/>\n<meta name=\"author\" content=\"Ajit\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ajit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/\",\"name\":\"How to Delete Files and Directories in Linux Terminal?\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"datePublished\":\"2019-10-26T05:08:40+00:00\",\"dateModified\":\"2019-10-28T05:50:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7cd39cafedd7652b49b849e5e331cd48\"},\"description\":\"You will learn in this KB article, how to remove files and directories with Linux Command Line using the Linux rm, rmdir and unlink command.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Delete Files and Directories in Linux Terminal?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7cd39cafedd7652b49b849e5e331cd48\",\"name\":\"Ajit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/589d86e7a8ab32a9165a816c5a907b0d?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/589d86e7a8ab32a9165a816c5a907b0d?s=96&d=blank&r=g\",\"caption\":\"Ajit\"},\"description\":\"With over 8+ years of experience in the digital marketing industry, I have achieved extensive exposure to result-oriented methodologies. And expertise in different domains like Datacentre Services, Cloud computing technology, Web hosting industry and many more.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/ajit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Delete Files and Directories in Linux Terminal?","description":"You will learn in this KB article, how to remove files and directories with Linux Command Line using the Linux rm, rmdir and unlink command.","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:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/","og_locale":"en_GB","og_type":"article","og_title":"How to Delete Files and Directories in Linux Terminal?","og_description":"You will learn in this KB article, how to remove files and directories with Linux Command Line using the Linux rm, rmdir and unlink command.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2019-10-26T05:08:40+00:00","article_modified_time":"2019-10-28T05:50:11+00:00","author":"Ajit","twitter_misc":{"Written by":"Ajit","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/","name":"How to Delete Files and Directories in Linux Terminal?","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"datePublished":"2019-10-26T05:08:40+00:00","dateModified":"2019-10-28T05:50:11+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7cd39cafedd7652b49b849e5e331cd48"},"description":"You will learn in this KB article, how to remove files and directories with Linux Command Line using the Linux rm, rmdir and unlink command.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-remove-files-and-directories-using-linux-terminal\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"How to Delete Files and Directories in Linux Terminal?"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7cd39cafedd7652b49b849e5e331cd48","name":"Ajit","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/589d86e7a8ab32a9165a816c5a907b0d?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/589d86e7a8ab32a9165a816c5a907b0d?s=96&d=blank&r=g","caption":"Ajit"},"description":"With over 8+ years of experience in the digital marketing industry, I have achieved extensive exposure to result-oriented methodologies. And expertise in different domains like Datacentre Services, Cloud computing technology, Web hosting industry and many more.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/ajit\/"}]}},"views":530,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/6755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=6755"}],"version-history":[{"count":1,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/6755\/revisions"}],"predecessor-version":[{"id":6759,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/6755\/revisions\/6759"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=6755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=6755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=6755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}