![]() ![]() mv old_filename another_directory/new_filenameĪn example for you: :~$ mv new_sample.txt my_dir/same_sample.txtĭrwxrwxr-x 2 abhi abhi 4096 Jul 5 06:06 my_dir rw-rw-r- 1 abhi abhi 348 Jul 5 04:52 new_sample.txtĪctually, you can rename a file and move to another location at the same time. The second argument of the command is the new file name instead of the directory location. To rename a file, you have to move the file to the same location but with a different name. I don't know if it was the real intent behind the mv command or just an unintended use. Yes, you can even rename the files with mv command in Ubuntu. The contents of the directory remain the same with all their file permissions and timestamps: :~$ ls -l new_dir/my_dir/ Now, you'll see the my_dir under the new_dir: :~$ ls -l new_dir I move this directory under another directory: :~$ mv my_dir new_dir I have a directory with a few files in it: :~$ ls -l my_dir Not very clear? Let me show with a real example. The above command will move the dir directory to another_directory location. You can use the same mv command to move a directory from one place to another with all its contents. There is no separate command for moving directories. Move a directory from one place to another Take a look at this example: :~$ mv file1.txt file2.txt file3.txt my_dirĭrwxrwxr-x 2 abhi abhi 4096 Jul 5 06:10 my_dir mv file1 file2 file3 destination_directory You can move them all in a single command. ![]() If you have multiple files to move to the same destination, you don't need to do it one by one. rw-rw-r- 1 abhi abhi 348 Jul 5 04:52 sample.txt And as you can see, the file is no longer in the current directory as it is moved to the my_dir location. I move the sample.txt file to the my_dir from the current directory. You'll have to check the target directory location. You won't see any output that tells you if the file was moved or not. The actual intended use for the mv command in Ubuntu is to move a file from one place to another. Let's see some practical examples of this mv command in Ubuntu Linux. It is mandatory to have another filename or directory location otherwise you'll see "mv: missing destination file operand after" error. The mv command has a simple syntax: mv source_file target_file_location I'll show you all the important stuff about the mv command in this guide. You can use the mv command to move and rename folders as well. It can also be used to rename files if you move them to the same location but with a different name. It's like a cut-paste operation as the original file moves to another location. The mv command is used for moving a file from one location to another in Ubuntu terminal. ![]()
0 Comments
Leave a Reply. |