In this blog we will learn about mv command .First of all lets open our terminal , We can press ctrl+alt+ t to do this .
1.We can use mv command with some options and then you have a source and then a destination . Basic command looks like : mv options source destination .Using the mv command we change name of our desired file . The command looks like : mv filename newname .Content of the file will remain same .
I want to create a new file and move the content of file newfile1.txt to file newfile2.txt and want to transfer all the content of newfile1 to newfile2 so we can just use mv and then file to which is a source and then I can just write newfile2.txt . So the command will look : mv newfile1.txt newfile2.txt .So if the file doesn’t really exist then it’s going to create the file.
2.Now for example I want to move file to another directory I can just use mv and then on the filename and then my directory name .Basic command looks like : mv filename directoryname .
so in this way you cant ransfer the file or move the file to other directory using the move command . But if you move a file which exist in the previous directory , the file you are moving will overwrite the existing file in the directory.
3.To prevent the overwriting you need to use -i as options in the command . So the command will look like : mv -i filename directory . This command will ask you if you want to overwrite the file that already exist in the directory .
You have to answer yes or no for the question .
4.Now , I want to transfer one directory inside another directory . I can use the move command to do this .Basic commad look like : mv source_directory destination_directory . It will move the source directory to destination directory .
5.Now there are many command which we can use for like: mv -v file1 directory name . It gives you explanation what this command has done.or more detail you have this command : man mv .