{"id":136,"date":"2023-09-12T22:16:53","date_gmt":"2023-09-13T01:16:53","guid":{"rendered":"https:\/\/difusao.tech\/blog\/?p=136"},"modified":"2023-09-04T22:29:03","modified_gmt":"2023-09-05T01:29:03","slug":"apagar-todos-os-arquivos-e-diretorios-de-uma-diretorio-no-linux-menos-o-diretorio-corrente","status":"publish","type":"post","link":"https:\/\/difusao.tech\/blog\/apagar-todos-os-arquivos-e-diretorios-de-uma-diretorio-no-linux-menos-o-diretorio-corrente\/","title":{"rendered":"Apagar todos os arquivos e diret\u00f3rios de uma diret\u00f3rio no linux menos o diret\u00f3rio corrente"},"content":{"rendered":"\n<p>Vamos realizar a limpeza de um diret\u00f3rio apagando todo o seu conte\u00fado menos o diret\u00f3rio corrente utilizando um shell script simples.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"760\" height=\"226\" src=\"https:\/\/difusao.tech\/blog\/wp-content\/uploads\/2023\/09\/image-9.png\" alt=\"\" class=\"wp-image-137\" srcset=\"https:\/\/difusao.tech\/blog\/wp-content\/uploads\/2023\/09\/image-9.png 760w, https:\/\/difusao.tech\/blog\/wp-content\/uploads\/2023\/09\/image-9-300x89.png 300w\" sizes=\"auto, (max-width: 760px) 100vw, 760px\" \/><\/figure>\n\n\n\n<p>No script acima fizemos:<\/p>\n\n\n\n<p>Definimos uma vari\u00e1vel para o path do nosso diret\u00f3rio: diretorio&#8221;\/home\/teo\/Downloads\/teste&#8221;<\/p>\n\n\n\n<p>Colocamos a data e hora em outra vari\u00e1vel: data=<code>date +%d\/%m\/%Y%r<\/code>`<\/p>\n\n\n\n<p>Fizemos a busca dentro do diret\u00f3rio por todos os arquivos e pastas e para cada correspondencia encontrada executamos o comando para remover: find &#8220;$diretorio&#8221; -mindepth 1 -exec rm -rf {} +<\/p>\n\n\n\n<p>E no final colocamos uma mensagem dentro de um arquivo de log para verificar se a execu\u00e7\u00e3o est\u00e1 sendo realizada corretamente: echo &#8220;Mensgem&#8221; > logrmftp.txt<\/p>\n\n\n\n<p>Salve em um arquivo .sh, delete.sh e execute o arquivo.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vamos realizar a limpeza de um diret\u00f3rio apagando todo o seu conte\u00fado menos o diret\u00f3rio corrente utilizando um<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,38],"tags":[87,183,182,83],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-aplicativos-gnu-linux","category-gnu-linux-bsd-unix-like-e-software-livre","tag-linux","tag-sh","tag-shell-script","tag-terminal"],"_links":{"self":[{"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":1,"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":138,"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions\/138"}],"wp:attachment":[{"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/difusao.tech\/blog\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}