November 29th, 2012, 12:25 PM
File source path backup
What I am trying to do is to move selected file from root into the created by me folder and then restore it back to its original location by shell script. Point is that I know how to automate the creation of a folder( if it exists - do nothing) and coping a file but I have no idea how to keep the source path of the file before its moved so I can restore it back with another script I simple don't know how to do it. I tried many web sites in order to find good answer and I couldn't find anything that I would understand.
November 29th, 2012, 03:20 PM
See example below, You could 'zip' the file and see contents with 'unzip' showing directory/filename:
zip /path/to/zipfilename.zip /path/to/file_to_zip
unzip -l /path/to/zipfilename.zip
December 2nd, 2012, 12:27 PM
If its a backup, then I have no idea why you would want to move the file.
However, if you're only copying the file over, check the man page for cp and look at using the --parents switch (this will preserve the dir structure in your backup dir). For example:
# cp --parents /home/test/folder/files/file.log /backups
# ls -la /backups/home/test/folder/files
drwxr-xr-t. 2 root root 4096 Dec 2 17:24 .
drwxrwxrwx. 4 root root 4096 Dec 2 17:20 ..
-rw-r--r--. 1 root root 0 Dec 2 17:20 file.log
The No Ma'am commandments:
1.) It is O.K. to call hooters 'knockers' and sometimes snack trays
2.) It is wrong to be French
3.) It is O.K. to put all bad people in a giant meat grinder
4.) Lawyers, see rule 3
5.) It is O.K. to drive a gas guzzler if it helps you get babes
6.) Everyone should car pool but me
7.) Bring back the word 'stewardesses'
8.) Synchronized swimming is not a sport
9.) Mud wrestling is a sport