When one directory is moved to other destination path, then i want to log the entry of original source path and entry of the path where it moved.

any command is already available ? or any other way of doing this task?


D1 = /home/user/Documents/test
D2 = /home/user/Documents/Data/test

when i moved D1 directory to the destination path to D2 directory then i want to log, like

"test" directory is moved from D1 to D2 path



I did this small script.

$1 $2
mv $1 $2
echo ${d1} + "was move to " ${d1} >>log.txt

Save it with the NAME.sh where name can be the name you want.

Take in consideration that the file log.txt has to exist. Also you should put the absolute path Ex. /home/user/log.txt

It should work, I test it and works. On the backgroud it is the same mv command. If you want to se nice the code, here is a link on paste ubuntu

  • Diego, this script will work for only static path. I want to get this for dynamic directory path. I am getting all the changed directory using this command "find /Users/ghanshyam/ -type d -mmin", In this result can i get the changed directory path.(source path and where it is moved) – Ghanshyam Rathod Sep 30 '12 at 2:50
  • I don't understand yoo well. For example, in this script I create a logs file. Copy the script file to /bin that way I can use it on the terminal like I use cp, mv. rm, etc. And it works. It tells me where the directory has been move – Diego Sep 30 '12 at 18:25
  • Here i am generating the log of modified directories, with the use of "find" command. find command gives me the all the modified directory details. In log i want to add some more details like if some directories are moved or copied then it will log down the source path(the path where it is previous before moving) and the destination path(after moving the directory). – Ghanshyam Rathod Oct 1 '12 at 1:46
  • well, add the find line to the script that will be all. $1 is the folder to be move, and $2 is the destiny folder. – Diego Oct 1 '12 at 3:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.