

mv source-directory target-directoryįor example, to move a directory path /tmp/logs to ~/data/logs you would run the following command. We specify the source directory and give a target directory. Moving directories work the same as moving files. mv student1.txt student2.txt /var/students Moving Directories on Linux mv source-file-1 source-file-2 target-pathįor example, to move student1.txt and student2.txt to /var/students, you would run the following command. The last path will be treated as the target. When executing the mv command, each file listed will be considered a source with the last path being the exception. The mv command accepts multiple source files, which means we can move two or more files at the same time. mv student1.txt /var/students/class1-student1.txt Moving Multiple files on Linux mv old-filename /new/path/new-filenameįor example, to move a file named student1.txt to /var/students and rename it to class1-student1.txt, you would run the following command. When mv moves the file, it will be given a new name. You simply give the target path a different name. mv /home/student1/lab-work.log /var/labs/student1/lab-work.log Moving and Renaming files on LinuxĪ file can be renamed during a move process using the mv command. mv source-file /new/pathįor example, to move a file from /home/student1/lab-work.log to /var/labs/student1/lab-work.log, you would run the following command. To move a file to another location we use the same method as renaming a file, except the file path should be different. Provided the file target is the same directory, all file attributes will remain, including permissions. To rename a file named student1 to student10, for example, you would run the following command.

The mv command will take the source file specified and rename it to the target file. For renaming files, only two arguments are needed, which are the source file and the target file. The command accepts two or more arguments. To rename a file in Linux you use the mv command. This means the operations done on one can be also done on the other, with very few exceptions.Īs such, you will notice that commands used to perform actions on files are identical with directories.
#Rename linux how to
In the above rename command, we are able to rename all the files with the desire file name.In this tutorial, you will learn how to use the mv command to move and renames files and directories on Linux.įiles and directories on Linux as very similar, from a filesystem point of view. We need to remove all the special character name form the multiple files. We do not need the special format of the file.

The filename is starting with some special format “like ff_”. In the data directory, we are having a number of files. As per the requirement, we can remove the specific part of the filename from multiple files. In the linux rename command, there is the facility to remove or delete the unwanted part of the file name. Before doing any file extension changes rename command displays the file extension output. As per the above command, we are changing the multiple file extension from “.orc” to “.png”. Before doing any changes on file level we need to check how the file will look like after changing to any other file extension. In the data directory, we are having multiple files with the file extension of “.orc”. We can use the “-n” option with the rename command to check the final changes happen on the file name. In rename command, we are having the functionality to see the final changes of all the multiple files without changes of actual file names. In the above rename command, we are able to rename all the files from upper case letter to lower case letter present in the working directory. In the data directory, we are having the number of files that are in upper case letter name. In rename command, we are having the functionality to rename the files name from upper case letter to lower case letter. No need to select indivisible files.Įxample #3 – To Rename File Name in Lowercase. In the same directory, we are able to do that on all files present in it. With the help of rename command, we are able to rename the file name from lower case to upper case. We are having multiple / number of files in it. We are creating one data directory, in the same directory. With the help of rename command, we are able to rename all the file names from lower case letter to upper case letters.

As per the above rename command, we are renaming “.html” extension to “.orc” extension.Įxample #2 – To Rename File Name in Uppercase. With the help of the rename command, we are able to rename all the file extension to different file extension. In the same directory, we have multiple files in it with different file extensions.
