{"id":15097,"date":"2019-03-08T12:44:29","date_gmt":"2019-03-08T15:44:29","guid":{"rendered":"https:\/\/blog.hostinger.io\/br-tutoriais\/?p=15097"},"modified":"2024-08-30T20:44:31","modified_gmt":"2024-08-30T23:44:31","slug":"como-renomear-arquivo-linux","status":"publish","type":"post","link":"\/br\/tutoriais\/como-renomear-arquivo-linux","title":{"rendered":"Como renomear arquivo Linux"},"content":{"rendered":"<p><span style=\"font-weight: 400\">O terminal &eacute; uma ferramenta insubstitu&iacute;vel para administradores de servidores <a href=\"\/br\/servidor-vps\"><strong>VPS Linux<\/strong><\/a>. Ele oferece aos usu&aacute;rios do Linux uma das melhores ferramentas de produtividade para salvar os recursos da sua m&aacute;quina. &nbsp;<\/span><\/p><p><span style=\"font-weight: 400\">Para efetivamente usar o potencial do Linux, voc&ecirc; precisa ter um conhecimento profundo dos fundamental. Isso inclui comandos simples, como renomear arquivos e pastas existentes. Neste tutorial, voc&ecirc; vai aprender como renomear pastas no Linux.<\/span><\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheatsheet-BR.pdf\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/Linux-cheat-sheet-BR.png\/public\" alt=\"\" class=\"wp-image-30351\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/Linux-cheat-sheet-BR.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/Linux-cheat-sheet-BR.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/Linux-cheat-sheet-BR.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/Linux-cheat-sheet-BR.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/Linux-cheat-sheet-BR.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-como-renomear-arquivo-linux-com-o-comando-mv\"><b>Como Renomear Arquivo Linux Com o Comando mv <\/b><\/h2><p><span style=\"font-weight: 400\">O comando <\/span><b>mv <\/b><span style=\"font-weight: 400\">&eacute; um dos mais f&aacute;ceis de usar. Voc&ecirc; pode fazer duas coisas b&aacute;sicas, mas essenciais enquanto lida com arquivos Linux. Um deles &eacute; mover arquivos de um local para outro. O outro &eacute; renomear um ou mais arquivos atrav&eacute;s do terminal. <\/span><\/p><p><span style=\"font-weight: 400\">Vamos ver como renomear arquivos com comando <\/span><b>mv<\/b><span style=\"font-weight: 400\"> funciona no Linux.<\/span><\/p><p><span style=\"font-weight: 400\">Primeiro, acessaremos a <a href=\"\/br\/tutoriais\/o-que-e-cli\"><strong>linha de comando<\/strong><\/a> usando <strong><a href=\"https:\/\/www.ssh.com\/ssh\/protocol\/\" target=\"_blank\" rel=\"noopener\">SSH<\/a><\/strong>. <\/span><a href=\"https:\/\/www.hostinger.com\/br\/tutoriais\/como-se-conectar-servidor-vps-usando-terminal-ssh\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 400\"><strong>Este tutorial<\/strong><\/span><\/a><span style=\"font-weight: 400\"> pode te ajudar, caso queira entender mais sobre isso.<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">ssh your-user@your-server<\/span><\/pre><p><span style=\"font-weight: 400\">Se voc&ecirc; est&aacute; usando um computador local, ao inv&eacute;s de um servidor, ent&atilde;o temos que abrir o terminal pelo menu principal. <\/span><\/p><p><span style=\"font-weight: 400\">Depois disso, &eacute; preciso saber como o comando <\/span><b>mv<\/b><span style=\"font-weight: 400\"> funciona. Para fazer isso, vamos executar o seguinte: <\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">mv --help<\/span><\/pre><p><span style=\"font-weight: 400\">Como podemos ver na imagem, o uso b&aacute;sico do comando <\/span><b>mv<\/b><span style=\"font-weight: 400\"> funciona assim:<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">mv [option] [SOURCE]...[DIRECTORY]<\/span><\/pre><p><span style=\"font-weight: 400\">Aqui est&atilde;o algumas das op&ccedil;&otilde;es mv mais populares:<\/span><\/p><ul class=\"wp-block-list\">\n<li><b>-f<\/b><span style=\"font-weight: 400\"> &ndash; n&atilde;o mostra mensagem antes de sobrescrever um arquivo.<\/span><\/li>\n\n\n\n<li><b>-i<\/b><span style=\"font-weight: 400\"> &ndash; mostra um mensagem de aviso antes de sobrescrever um arquivo.<\/span><\/li>\n\n\n\n<li><b>-u<\/b><span style=\"font-weight: 400\"> &ndash; somente move um arquivo se for novo ou n&atilde;o existir no destino. <\/span><\/li>\n\n\n\n<li><b>-v<\/b><span style=\"font-weight: 400\"> &ndash; exibe o que o comando faz.<\/span><\/li>\n<\/ul><p><span style=\"font-weight: 400\">E os par&acirc;metros s&atilde;o: <\/span><\/p><p><b>[SOURCE]<\/b><span style=\"font-weight: 400\"> &ndash; o destino de origem do arquivo.<\/span><\/p><p><b>[DESTINATION]<\/b><span style=\"font-weight: 400\"> &ndash; o diret&oacute;rio de destino.<\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-renomear-arquivo-linux-usando-o-comando-mv\"><b>Renomear Arquivo Linux Usando o Comando mv <\/b><\/h2><p><span style=\"font-weight: 400\">Se voc&ecirc; quer renomear um arquivo, voc&ecirc; pode fazer como mostra: <\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">mv file1 newnamefile1<\/span><\/pre><p><span style=\"font-weight: 400\">Suponha que estamos localizados no diret&oacute;rio e existe um arquivo chamado <\/span><b>file1.txt <\/b><span style=\"font-weight: 400\">e queremos alterar o nome para <\/span><b>file2.txt<\/b><span style=\"font-weight: 400\">.<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">mv file1.txt file2.txt<\/span><\/pre><p><span style=\"font-weight: 400\">Simples assim! &nbsp;Por&eacute;m, se voc&ecirc; precisa de recursos mais avan&ccedil;ados, voc&ecirc; precisa usar o comando de renomear, que vamos mostrar abaixo.<\/span><\/p><pre class=\"wp-block-preformatted\">cd \/home\/user\/docs\/files\nmv file1.txt file2.txt<\/pre><h3 class=\"wp-block-heading\" id=\"h-renomear-multiplos-arquivos-linux-usando-o-comando-mv\"><b>Renomear M&uacute;ltiplos Arquivos Linux Usando o Comando mv<\/b><\/h3><p>O comando <strong>mv<\/strong> pode ser usado somente para renomear um arquivo, mas tamb&eacute;m ser usado com outros comandos para renomear m&uacute;ltiplos arquivos.<\/p><p>Vamos usar os comandos <strong>find<\/strong>, <strong>for<\/strong> e <strong>while<\/strong> e renomear m&uacute;ltiplos arquivos Linux.<\/p><p>Por exemplo, quanto tentar mudar todos os arquivos no seu diret&oacute;rio atual da extens&atilde;o .txt para a extens&atilde;o .pdf, voc&ecirc; vai usar o comando:<\/p><pre class=\"wp-block-preformatted\">for f in *txt; do\n   mv -- \"$f\" \"${f%.txt}.pdf\"\ndone<\/pre><p>Isso vai criar um processo interno (<strong>for<\/strong>) que vai buscar uma lista de arquivos com a extens&atilde;o .txt. Ele vai, ent&atilde;o, substituir cada extens&atilde;o .txt com a extens&atilde;o .pdf. Ent&atilde;o, ele vai terminar o processo automaticamente (<strong>done<\/strong>).<\/p><p>Se quiser recursos mais avan&ccedil;ados, voc&ecirc; vai precisar usar o comando rename.<\/p><h3 class=\"wp-block-heading\" id=\"h-renomear-arquivo-linux-usando-o-comando-rename\"><strong>Renomear Arquivo Linux Usando o Comando Rename<\/strong><\/h3><p><span style=\"font-weight: 400\">O comando <\/span><b>mv<\/b><span style=\"font-weight: 400\"> &eacute; usado tanto para mover arquivos para outros locais como para renomear arquivos. Por&eacute;m, voc&ecirc; tamb&eacute;m pode usar o comando <\/span><b>rename<\/b><span style=\"font-weight: 400\">, que d&aacute; um pouco mais de controle. <\/span><\/p><p><span style=\"font-weight: 400\">Muitas distribui&ccedil;&otilde;es Linux incluem isso por padr&atilde;o. Se voc&ecirc; n&atilde;o tem instalado, voc&ecirc; pode instalar facilmente com um simples comando. <\/span><\/p><p><span style=\"font-weight: 400\">No caso de <\/span><b>Debian, Ubuntu, Linux Mint<\/b><span style=\"font-weight: 400\"> e derivados:<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">sudo apt install rename<\/span><\/pre><p><span style=\"font-weight: 400\">Mas se estamos usando o CentOS ou RHEL:<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">sudo yum install rename<\/span><\/pre><p><span style=\"font-weight: 400\">Depois disso, voc&ecirc; pode come&ccedil;ar a usar. Em geral, a sintaxe b&aacute;sica de renomear comandos parecem com isto:<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">rename 's\/old-name\/new-name\/' files<\/span><\/pre><p><span style=\"font-weight: 400\">Parece complexo no in&iacute;cio, mas &eacute; mais simples do que voc&ecirc; imagina. <\/span><\/p><p><span style=\"font-weight: 400\">Neste exemplo, vamos criar uma pasta chamada <\/span><b>filetorename<\/b><span style=\"font-weight: 400\"> e usar o comando touch. Vamos criar 5 arquivos. <\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">mkdir filetorename<\/span><\/pre><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">cd filetorename<\/span><\/pre><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">touch file{1..5}.txt<\/span><\/pre><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">ls<\/span><\/pre><p><span style=\"font-weight: 400\">Com o &uacute;ltimo comando <\/span><b>ls<\/b><span style=\"font-weight: 400\">, voc&ecirc; pode visualizar os arquivos que foram criados.<\/span><\/p><p><span style=\"font-weight: 400\">Se voc&ecirc; quer renomear o &uacute;nico arquivo chamado <\/span><b>file1.txt<\/b><span style=\"font-weight: 400\">, a senten&ccedil;a deve ser assim: <\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">rename &lsquo;s\/file1\/newfile1\/&rsquo; file1.txt<\/span><\/pre><p><span style=\"font-weight: 400\">Se voc&ecirc; quer trocar as extens&otilde;es de todos os arquivos, para <\/span><b>.php<\/b>, por exmeplo<span style=\"font-weight: 400\">, n&oacute;s podemos usar o seguinte: <\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">rename &lsquo;s\/.txt\/.php\/&rsquo; *.txt<\/span><\/pre><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">ls<\/span><\/pre><p><span style=\"font-weight: 400\">N&oacute;s tamb&eacute;m podemos especificar outros diret&oacute;rios onde os arquivos que voc&ecirc; quer renomear s&atilde;o: <\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">rename &lsquo;s\/.txt\/.php\/&rsquo; FILE\/PATH<\/span><\/pre><p><span style=\"font-weight: 400\">Tamb&eacute;m queremos mencionar que renomear o uso com a express&atilde;o regular <strong><a href=\"https:\/\/www.perl.org\/\" target=\"_blank\" rel=\"noopener\">Perl<\/a><\/strong>, significa que este comando tem possibilidades amplas. <\/span><\/p><p><span style=\"font-weight: 400\">E para finalizar, &eacute; uma &oacute;tima ideia verificar todos as op&ccedil;&otilde;es de comando. Voc&ecirc; pode visualiz&aacute;-las no terminado ao executar:<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">rename &ndash;help<\/span><\/pre><p>Alguns outros exemplos de uso do comando <strong>rename<\/strong> s&atilde;o:<\/p><ul class=\"wp-block-list\">\n<li>Converter nome de arquivos para caixa alta:<\/li>\n<\/ul><pre class=\"wp-block-preformatted\">rename 'y\/a-z\/A-Z\/' *<\/pre><ul class=\"wp-block-list\">\n<li>Converter nomes de arquivos para caixa baixa:<\/li>\n<\/ul><pre class=\"wp-block-preformatted\">rename 'y\/A-Z\/a-z\/' *<\/pre><ul class=\"wp-block-list\">\n<li>Substituir espa&ccedil;os nos nomes de arquivos por sublinhados:<\/li>\n<\/ul><pre class=\"wp-block-preformatted\">rename 'y\/ \/_\/' *<\/pre><h3 class=\"wp-block-heading\" id=\"h-remover-o-comando-rename\"><strong>Remover o Comando Rename<\/strong><\/h3><p><span style=\"font-weight: 400\">Se voc&ecirc; n&atilde;o deseja ter o rename instalado no seu sistema, remova isto usando o gerenciador de software. Ou do terminal.<\/span><\/p><p><span style=\"font-weight: 400\">Para <\/span><b>Debian, Ubuntu, Linux Mint<\/b><span style=\"font-weight: 400\"> e derivados:<\/span><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">sudo apt remove rename<\/span><\/pre><p><span style=\"font-weight: 400\">E para <\/span><b>CentOS<\/b><span style=\"font-weight: 400\"> e <\/span><b>RHEL<\/b><\/p><pre class=\"wp-block-preformatted\"><span style=\"font-weight: 400\">sudo yum remove rename<\/span><\/pre><p><span style=\"font-weight: 400\">&Eacute; isto, o <strong>rename<\/strong> foi removido da sua m&aacute;quina Linux. <\/span><\/p><figure class=\"wp-block-image size-large\"><a href=\"\/br\/servidor-vps\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2023\/02\/BR-VPS-hosting_in-text-banner-1.png\/public\" alt=\"\" class=\"wp-image-32923\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2023\/02\/BR-VPS-hosting_in-text-banner-1.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2023\/02\/BR-VPS-hosting_in-text-banner-1.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2023\/02\/BR-VPS-hosting_in-text-banner-1.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2023\/02\/BR-VPS-hosting_in-text-banner-1.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2023\/02\/BR-VPS-hosting_in-text-banner-1.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-resumo\"><b>Resumo<\/b><\/h2><p><span style=\"font-weight: 400\">Renomear arquivo Linux usando o terminal &eacute; uma tarefa simples e pr&aacute;tica, mas nem por isso sem import&acirc;ncia. Entender como fazer isto &eacute; algo que todo gerenciador de servidor deve saber. <\/span><\/p><p><span style=\"font-weight: 400\">Como vimos, temos dois comandos para fazer isto. Um mais simples que o outro, mas os dois muito eficientes.<\/span><\/p><p><span style=\"font-weight: 400\">Recomendamos que continue pesquisando os comandos e aumentando a qualidade do seu dia a dia no trabalho. &nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O terminal &eacute; uma ferramenta insubstitu&iacute;vel para administradores de servidores VPS Linux. Ele oferece aos usu&aacute;rios do Linux uma das melhores ferramentas de produtividade para salvar os recursos da sua m&aacute;quina. &nbsp; Para efetivamente usar o potencial do Linux, voc&ecirc; precisa ter um conhecimento profundo dos fundamental. Isso inclui comandos simples, como renomear arquivos e [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/br\/tutoriais\/como-renomear-arquivo-linux\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":92,"featured_media":15098,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_title":"","rank_math_description":"Veja como \u00e9 simples renomear arquivo Linux com nosso tutorial passo a passo que demonstra o uso de dois comandos.","rank_math_focus_keyword":"renomear arquivo linux","footnotes":""},"categories":[4915],"tags":[4852,6374],"class_list":["post-15097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps","tag-linux","tag-renomear-arquivo-linux"],"hreflangs":[{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-renomear-arquivo-linux","default":1},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-renomear-arquivo-linux","default":0}],"acf":[],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/15097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/users\/92"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/comments?post=15097"}],"version-history":[{"count":17,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/15097\/revisions"}],"predecessor-version":[{"id":45625,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/15097\/revisions\/45625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/media\/15098"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/media?parent=15097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/categories?post=15097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/tags?post=15097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}