{"id":15634,"date":"2019-02-23T12:24:43","date_gmt":"2019-02-23T12:24:43","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15634"},"modified":"2025-04-28T07:56:58","modified_gmt":"2025-04-28T07:56:58","slug":"how-to-rename-files-in-linux","status":"publish","type":"post","link":"\/uk\/tutorials\/how-to-rename-files-in-linux","title":{"rendered":"How to Rename Files in Linux Using the mv and rename Commands"},"content":{"rendered":"<p>A command-line terminal is an essential tool for administrating Linux systems, including a VPS. It lets users execute various Linux commands to simplify management tasks, like renaming files and folders.<\/p><p>However, executing commands may seem daunting for new VPS hosting users with minimal technical knowledge. To help beginners get started, we will explain how to rename files in Linux remote servers.<\/p><p>We will also explore how to use Hostinger VPS features to rename files in Linux efficiently. You will learn how to gain full root access to your server using the built-in Browser terminal and generate commands using our AI assistant, <strong>Kodee<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-rename-files-in-linux-with-the-mv-command\">How to Rename Files in Linux With the mv Command<\/h2><p>The <strong>mv <\/strong>or <strong>move<\/strong> command is used for two essential tasks in handling files in Terminal &ndash; moving files between locations and renaming them.<\/p><p>To run <strong>mv <\/strong>on Linux, connect to your VPS via SSH to access the command-line interface. You can <a href=\"\/uk\/tutorials\/how-to-use-putty-ssh\">use an SSH client like PuTTY<\/a> or Terminal. For a local system, you can directly run the <strong>mv<\/strong> command via Terminal.<\/p><p>All Hostinger <a href=\"\/uk\/vps-hosting\">VPS hosting solutions<\/a> support remote connection via SSH, allowing users to access their servers securely. Our hosting also provides full root support to ensure users can run various management commands without permission issues.<\/p><p>You will also need the VPS IP address and username to log in. For Hostinger users, navigate to the VPS menu on the top bar and select the relevant plan. Then, get the login credentials in the <strong>SSH Access<\/strong> tab.<\/p><p>Open Terminal and enter the following command. Remember to replace <strong>your-user<\/strong> with the username and <strong>your-server<\/strong> with the VPS IP address:<\/p><pre class=\"wp-block-preformatted\">ssh your-user@your-server<\/pre><p>Once connected, run the following command to learn more about how the mv command works:<\/p><pre class=\"wp-block-preformatted\">mv --help<\/pre><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/uk\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\">mv Command Syntax and Options<\/h3><p>The basic <strong>mv <\/strong>command syntax is as follows:<\/p><pre class=\"wp-block-preformatted\">mv option SOURCE...DIRECTORY<\/pre><p><strong>SOURCE <\/strong>refers to the file&rsquo;s origin directory, while <strong>DESTINATION <\/strong>is its target path.<\/p><p>The<strong> option <\/strong>is an additional parameter for modifying the command&rsquo;s output. Here are several popular<strong> mv <\/strong>options:<\/p><ul class=\"wp-block-list\">\n<li><strong>-f<\/strong> &ndash; shows no message before overwriting a file.<\/li>\n\n\n\n<li><strong>-i<\/strong> &ndash; displays warning messages before overwriting a file.<\/li>\n\n\n\n<li><strong>-u<\/strong> &ndash; only moves a file if it is new or doesn&rsquo;t exist in the destination.<\/li>\n\n\n\n<li><strong>-v<\/strong> &ndash; explains what the command does.<\/li>\n<\/ul><h3 class=\"wp-block-heading\" id=\"h-rename-a-file-on-linux-using-the-mv-command\">Rename a File on Linux Using the mv Command<\/h3><p>To rename a file, use the following <strong>mv<\/strong> command syntax. Note that this only works if you are in the same directory as the file:<\/p><pre class=\"wp-block-preformatted\">mv oldnamefile1 newnamefile1<\/pre><p>If there is a file called<strong> file1.txt <\/strong>which you want to rename to <strong>file2.txt<\/strong>, enter the following:<\/p><pre class=\"wp-block-preformatted\">mv file1.txt file2.txt<\/pre><p>If you are not in the file&rsquo;s location, you must change the current working directory using the<strong> cd <\/strong>command. For example:<\/p><pre class=\"wp-block-preformatted\">cd \/home\/user\/docs\/files<\/pre><pre class=\"wp-block-preformatted\">mv file1.txt file2.txt<\/pre><h3 class=\"wp-block-heading\" id=\"h-rename-multiple-files-with-the-mv-command\">Rename Multiple Files With the mv Command<\/h3><p>By default, the <strong>mv<\/strong> command can only rename one file. To change multiple files&rsquo; names, combine <strong>mv<\/strong> with other commands. You must also use the<strong> find<\/strong>,<strong> for<\/strong>, or<strong> while<\/strong> loops to repeat the commands until the desired result is met.<\/p><p>To do so, create a new bash script file with the<strong> .sh<\/strong> extension using the <a href=\"\/uk\/tutorials\/linux-touch-command-with-useful-examples\/\"><strong>touch<\/strong> command<\/a>. Open it <a href=\"\/uk\/tutorials\/how-to-install-and-use-nano-text-editor\">using a text editor like <strong>nano<\/strong><\/a> and write the loop. For example, enter the following to change all files in your current directory from the <strong>TXT<\/strong> extension to <strong>PDF<\/strong>:<\/p><pre class=\"wp-block-preformatted\">for f in *txt; do\n   mv -- \"$f\" \"${f%.txt}.pdf\"\ndone<\/pre><p>This command creates a for loop to examine the list of <strong>TXT<\/strong> files in the directory. It will then replace each <strong>TXT <\/strong>extension with<strong> PDF<\/strong>. After all the files turn into <strong>PDF<\/strong>, the loop ends.<\/p><p>To run the bash script, enter the command below. Replace the file name and directory path according to your own:<\/p><pre class=\"wp-block-preformatted\">bash \/path\/to\/file\/script.sh<\/pre><p>If you encounter an error, ensure your current user account has the execute permission over the file. Otherwise, enter the <a href=\"\/uk\/tutorials\/how-to-change-linux-permissions-and-owners\">chmod command to change the privilege<\/a>:<\/p><pre class=\"wp-block-preformatted\">sudo chmod +x \/path\/to\/file\/script.sh<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-rename-files-on-linux-using-the-rename-command\">How to Rename Files on Linux Using the rename Command<\/h2><p>The <strong>rename<\/strong> command gives you more flexibility in modifying the files. Many Linux configurations include this command by default. If your system doesn&rsquo;t have one, install it via Terminal.<\/p><p>Hostinger&rsquo;s VPS hosting environment is optimized for users to use Linux commands for server management efficiently. In addition to offering various Linux distributions, we use powerful hardware to provide optimal performance, ensuring smooth command-line operations.<\/p><p>Moreover, we have <a href=\"https:\/\/support.hostinger.com\/en\/articles\/1583267-where-are-hostinger-servers-located\" target=\"_blank\" rel=\"noopener\">data centers worldwide<\/a>. Users can choose the closest one to their location, reducing input latency to improve responsiveness when managing a server remotely.<\/p><h3 class=\"wp-block-heading\">How to Install the rename Command<\/h3><p>Depending on your server operating system, the installation command for <strong>rename<\/strong> differs. For Debian, Ubuntu, Linux Mint, and their derivatives, use the following command:<\/p><pre class=\"wp-block-preformatted\">sudo apt install rename<\/pre><p>Meanwhile, use this command if you are operating CentOS 9 or RHEL:<\/p><pre class=\"wp-block-preformatted\">sudo yum install rename<\/pre><p>For Arch Linux, run this command:<\/p><pre class=\"wp-block-preformatted\">yay perl-rename ## or yaourt -S perl-rename<\/pre><h3 class=\"wp-block-heading\">rename Command Syntax<\/h3><p>Once installed, you can start using the <strong>rename<\/strong> command. Here&rsquo;s its basic syntax:<\/p><pre class=\"wp-block-preformatted\">rename 's\/old-name\/new-name\/' files<\/pre><p>For example, we will create a new <strong>filetorename<\/strong> folder with the <strong>mkdir<\/strong> command. Then, we&rsquo;ll switch to the directory and use the<strong> touch<\/strong> command to create five files within the directory. Here are the commands:<\/p><pre class=\"wp-block-preformatted\">mkdir filetorename<\/pre><pre class=\"wp-block-preformatted\">cd filetorename<\/pre><pre class=\"wp-block-preformatted\">touch file{1..5}.txt<\/pre><pre class=\"wp-block-preformatted\">ls<\/pre><p>The<strong> ls<\/strong> command will list the current directory&rsquo;s content, namely the five new files. <\/p><h3 class=\"wp-block-heading\">rename Command Examples<\/h3><p>To rename a single file called<strong> file1.txt<\/strong>, the command will look like this:<\/p><pre class=\"wp-block-preformatted\">rename &lsquo;s\/file1\/newfile1\/&rsquo; file1.txt<\/pre><p>To change all files&rsquo; extensions, for example, to<strong> PHP<\/strong>, use the following commands:<\/p><pre class=\"wp-block-preformatted\">rename &lsquo;s\/.txt\/.php\/&rsquo; *.txt<\/pre><pre class=\"wp-block-preformatted\">ls<\/pre><p>If the file you want to rename is in another location, specify its directory in your command. Here&rsquo;s what the command might look like:<\/p><pre class=\"wp-block-preformatted\">rename &lsquo;s\/.txt\/.php\/&rsquo; FILE\/PATH<\/pre><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>The rename command uses a regular expression of <a href=\"https:\/\/www.perl.org\/\" target=\"_blank\" rel=\"noopener\">Perl<\/a>, meaning it has extensive possibilities.<\/p>\n                <\/div>\n\n\n\n<\/p><p>To list all the<strong> rename <\/strong>command options in Terminal, run the following:<\/p><pre class=\"wp-block-preformatted\">rename &ndash;help<\/pre><p>The <strong>rename<\/strong> command has various use cases. One of the most common uses is converting filenames to uppercase or lowercase. Here are their commands:<\/p><pre class=\"wp-block-preformatted\">rename 'y\/a-z\/A-Z\/' *<\/pre><pre class=\"wp-block-preformatted\">rename 'y\/A-Z\/a-z\/' *<\/pre><p>You can also replace a character with another using the command. For instance, this command will replace spaces in filenames with underscores:<\/p><pre class=\"wp-block-preformatted\">rename 'y\/ \/_\/' *<\/pre><h3 class=\"wp-block-heading\" id=\"h-how-to-remove-rename-command\">How to Remove Rename Command<\/h3><p>If you want to remove the <strong>rename<\/strong> command from your system, uninstall it using Software Manager or Terminal. For this tutorial, we will use Terminal.<\/p><p>Use the following command for Debian, Ubuntu, Linux Mint, and their derivatives:<\/p><pre class=\"wp-block-preformatted\">sudo apt remove rename<\/pre><p>For CentOS and RHEL, run this command instead:<\/p><pre class=\"wp-block-preformatted\">sudo yum remove rename<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-rename-files-with-hostinger-vps\">How to Rename Files With Hostinger VPS<\/h2><p>There are two main ways to rename files on your Hostinger VPS: using command-line tools or installing a control panel with a file manager.<\/p><p>If you&rsquo;re comfortable with commands, use the built-in <strong>Browser terminal<\/strong> to access your VPS directly from your web browser &mdash; no third-party SSH client required. This is especially useful if the SSH port is closed due to security settings.<\/p><p>To access <strong>Browser terminal<\/strong>:<\/p><ol class=\"wp-block-list\">\n<li>Log in to hPanel and select <strong>VPS &rarr; Manage<\/strong> next to your plan.<\/li>\n\n\n\n<li>Click <strong>Browser terminal<\/strong> on the right side of the dashboard.<\/li>\n\n\n\n<li>Enter your root username and password if prompted.<\/li>\n<\/ol><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69dfa4813a72d\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/02\/hpanel-vps-overview-browser-terminal-highlighted-1024x378.png\" alt=\"The Browser terminal button in VPS' Overview page of hPanel\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Once you&rsquo;re connected, use the <strong>mv<\/strong> command to rename files. For example:<\/p><pre class=\"wp-block-preformatted\">mv oldname.txt newname.txt<\/pre><p>You can also ask our AI assistant <strong>Kodee<\/strong> to generate commands for you. Just enter a prompt like &ldquo;Rename a file in my VPS&rdquo; and Kodee will give you the exact command.<\/p><p>If you prefer a graphical interface, you can install a control panel like <strong>CyberPanel<\/strong> or <strong>cPanel<\/strong> through the <strong>Operating System<\/strong> menu in the VPS dashboard. These panels come with built-in file managers that let you rename files via a visual interface.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>To rename files in Linux, connect to your remote server using Terminal or an SSH client. Then, use the <strong>mv <\/strong>or<strong> rename<\/strong> command to change the file name. Both work similarly, but<strong> rename<\/strong> provides more flexibility.<\/p><p>You can also use these commands to rename multiple files simultaneously. For the<strong> mv<\/strong> command, you must combine it with loops to repeat the renaming process for all files. Meanwhile,<strong> rename <\/strong>lets you do so in bulk by default.<\/p><p>Hostinger VPS offers various features to simplify renaming tasks. For instance, our Browser terminal lets you execute these commands without Terminal or an SSH client. Moreover, you can also install a control panel to easily manage files via a GUI.<\/p><p>In addition to robust features, Hostinger provides a high-performance VPS hosting environment to ensure responsive command-line operations. Moreover, our multiple data center locations help reduce latency when users connect to their servers remotely.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-rename-files-in-linux-faq\">How to Rename Files In Linux FAQ<\/h2><p>In this section, we will answer several common questions about renaming files in Linux using a command line.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1664962658364\"><h3 class=\"schema-faq-question\">What Linux Command Lets You Rename Files?<\/h3> <p class=\"schema-faq-answer\">Use the <strong>mv <\/strong>command on Linux to rename files and folders. Since the Linux system understands renaming files as moving them to another location, you can use this command to change a file name.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1664962675527\"><h3 class=\"schema-faq-question\">How Do You Rename Multiple Files In Linux?<\/h3> <p class=\"schema-faq-answer\">There are different ways to rename multiple files in Linux. It&rsquo;s possible to batch rename using <strong>mmv<\/strong> or bulk-rename files with the<strong> rename<\/strong> utility. Moreover, you can use <strong>Emacs<\/strong> or <strong>Thunar<\/strong> file manager to execute the task.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>A command-line terminal is an essential tool for administrating Linux systems, including a VPS. It lets users execute various Linux commands to simplify management tasks, like renaming files and folders. However, executing commands may seem daunting for new VPS hosting users with minimal technical knowledge. To help beginners get started, we will explain how to [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/uk\/tutorials\/how-to-rename-files-in-linux\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Rename Files In Linux Using the Command Line","rank_math_description":"Every Linux user should learn the fundamental terminal command lines. Here's how you can rename files on any Linux Distribution.","rank_math_focus_keyword":"rename file linux","footnotes":""},"categories":[22644,22640],"tags":[],"class_list":["post-15634","post","type-post","status-publish","format-standard","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-rename-files-in-linux","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/renommer-fichier-linux","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/renombrar-archivos-linux","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/rename-file-linux","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-rename-files-in-linux","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-rename-files-in-linux\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-rename-files-in-linux\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/renombrar-archivos-linux","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/renombrar-archivos-linux","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/renombrar-archivos-linux","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-rename-files-in-linux","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-rename-files-in-linux","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-rename-files-in-linux","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-rename-files-in-linux","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/15634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/comments?post=15634"}],"version-history":[{"count":38,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/15634\/revisions"}],"predecessor-version":[{"id":125558,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/15634\/revisions\/125558"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media?parent=15634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/categories?post=15634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/tags?post=15634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}