In: Computer Science
Linux Directories, File Properties, and the File System in C
Understanding Unix/Linux Programming
Your version of mv command
root@PANKAJ:~/mydir# mv --version # Checking version of
mv
mv (GNU coreutils) 8.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute
it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Parker, David MacKenzie, and Jim Meyering.
root@PANKAJ:~/mydir# cat > testfile1 # Creating a
file in name testfile1
Hello, this is testfile1.
^Z
[4]+ Stopped cat > testfile1
root@PANKAJ:~/mydir# cat > testfile2 # Creating a
file in name testfile2
Hello, this is testfile2.
^Z
[5]+ Stopped cat > testfile2
root@PANKAJ:~/mydir# mkdir testdirectory # Creating a directory in name testdirectory
root@PANKAJ:~/mydir# mv testfile1 testdirectory # Move testfile1 to testdirectory
root@PANKAJ:~/mydir# # Below command Renames testfile2 to testfile3 as there is no such directory
root@PANKAJ:~/mydir# mv testfile2 testfile3
root@PANKAJ:~/mydir# #Let us now test if our command
worked or not
root@PANKAJ:~/mydir# cat testfile2 # display content of
testfile2
cat: testfile2: No such file or directory
root@PANKAJ:~/mydir# cat testfile3
Hello, this is testfile2.
root@PANKAJ:~/mydir# cat testfile1
cat: testfile1: No such file or directory
root@PANKAJ:~/mydir# cd testdirectory # Changing working
directory to testdirectory
root@PANKAJ:~/mydir/testdirectory# cat
testfile1
Hello, this is testfile1.
-----------------------------------------------------
On analyzing last 5 commands it is clear that mv command has moved
the file to the target directory if the directory was found else it
just renamed it.
-----------------------------------------------------