Sponsored Content
Full Discussion: Restoring a file
Top Forums Shell Programming and Scripting Restoring a file Post 88917 by vino on Thursday 10th of November 2005 02:04:27 AM
Old 11-10-2005
Quote:
Originally Posted by zoolz
I'm new to Unix and have just wrote a little program to move files to a recycle bin (a Directory i created) and restore them. The problem is that i need to keep track of all the full filenames so that i can restore them to the right place. I did this by creating a file called delreg and putting the full filenames in it.
But i don't know how to write the full filename to the file or for that matter how to restore the file. My code so far looks like this
pwd >> /home/zoolz/delreg
$1 >> /home/zoolz/delreg
But this code only puts it on 2 lines.
Please if anyone can help it would be great because i seem to be banging my head against a wall
Check this out.

This will put the filename into a hidden file.

Code:
#! /bin/ksh
# ./delreg file

[ -z "$1" ] && echo "Need a file to delete" && exit 1 || FILE="$1"

# delreg is in the directory DIRNAME
DIRNAME=`pwd`

#  FILE will ibe either one of the following
#+ DIRNAME/FILE
#+ or /FILE
#+ //FILE will evaluate to /FILE

if [ -f "$DIRNAME/$FILE" ] ; then
echo "$FILE@@$DIRNAME/$FILE" >> /tmp/.delreg.list
#mv $FILE /tmp
exit 0
fi ;

if [ -f "/$FILE" ] ; then
echo "$FILE@@/$FILE" >> /tmp/.delreg.list
#mv "/$FILE" /tmp
exit 0
fi ;
echo "$1 is not a valid file"

Code:
[~/temp]$ ./delreg.ksh /etc/passwd
[~/temp]$ ./delreg.ksh /etc/pass
/etc/pass is not a valid file
[~/temp]$ ./delreg.ksh /etc
/etc is not a valid file
[~/temp]$ ./delreg.ksh delreg.ksh


Code:
[~/temp]$ cat /tmp/.delreg.list 
/etc/passwd@@//etc/passwd
delreg.ksh@@/home/vino/temp/delreg.ksh

The @@ is delimiter. The pattern goes as $FILENAME@@$LOCATION

This script does the delete part. You will have to extend on this script to recycle the file.

I dont know the behaviour of
Code:
./delreg.ksh delreg.ksh

I think it should move itself to /tmp

Uncomment the # in front of the mv statement.

vino
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Restoring a file from Tape

help please i have "inherited" a Sco Server (the administrator departed in a hurry...yes we are chasing him..) and haven't used Unix for 8 years. i have a file that i need to retrieve from a tape. i have been able to find the file on tape using the cpio -ivt command. however... the problem I... (3 Replies)
Discussion started by: mfischer
3 Replies

2. UNIX for Dummies Questions & Answers

Restoring a single file...???

Can anyone please help...? Managed to do a ufsdump of files to tape. Having trouble using ufsrestore to pull a single file back by filename?? I have dumped a single file to tape also because looking through the other threads, I noticed that you have to tell it to skip files before you get to... (1 Reply)
Discussion started by: Jonathan
1 Replies

3. Solaris

Restoring TAR'd file to different location

Is it possible to restore a TAR'ed file off of a tape to a location other than the original location? If so, how? (The MAN pages give examples of how to restore only to the originating location.) Thanks!! (1 Reply)
Discussion started by: FredSmith
1 Replies

4. UNIX for Dummies Questions & Answers

Blocksize problem restoring file from tape

I was recently given the responsibility of the unix box at our work. Without much training, I now have to go back and restore a file from tape. I'm having some trouble with it. I'm getting an error with the blocksize. The part of the script that does the tar looks like this: tar cvfX... (11 Replies)
Discussion started by: citrowske
11 Replies

5. UNIX for Dummies Questions & Answers

Restoring back a deleted file in unix.

Hi, Can any one tell me how to restore back the deleted file in unix? I know the file name. If i know the inode number of the file does help more to restore back the file? (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

6. Shell Programming and Scripting

restoring file to its default location...

Hello everyone, I am new to unix shell. I have a file called Path.txt....and i have data in that as 1 abhi 2 avi 3 ash so on..... 1 ,2 ,3 is the... (2 Replies)
Discussion started by: AbhijitIT
2 Replies

7. Red Hat

Issues restoring a large dump file

Post deleted. (0 Replies)
Discussion started by: Nobody_knows_me
0 Replies

8. Shell Programming and Scripting

Restoring a file to its original location

Hello everyone, I am attempting to make a recycling bin type application in shell script (tcsh). I have the whole part of the application done where someone can recycle files from one location to the recycling bin (the lower half of the program), this is not a problem. However I wanted to make... (7 Replies)
Discussion started by: tastybrownies
7 Replies

9. UNIX for Dummies Questions & Answers

Restoring deleted file with rm -rf

Is there a way I could recover a deleted text file with "rm -rf" command. Running CentOS 6.5. Thank you. (5 Replies)
Discussion started by: galford
5 Replies

10. UNIX for Advanced & Expert Users

CentOS7 restoring file capabilities

Quite an obscure question I think. We have a rebuild process for remote sites that allows us to PXE rebuild a till (actually a PC with a touch screen and various fancy bits) running CentOS. The current CentOS5 tills work just fine with a tar image restore and some personalisation. Sadly,... (4 Replies)
Discussion started by: rbatte1
4 Replies
MKMANIFEST(1)						      General Commands Manual						     MKMANIFEST(1)

NAME
mkmanifest - create a shell script to restore Unix filenames SYNOPSIS
mkmanifest [ files ] DESCRIPTION
Mkmanifest creates a shell script that will aid in the restoration of Unix filenames that got clobbered by the MSDOS filename restrictions. MSDOS filenames are restricted to 8 character names, 3 character extensions, upper case only, no device names, and no illegal characters. The mkmanifest program is compatible with the methods used in pcomm, arc, and mtools to change perfectly good Unix filenames to fit the MSDOS restrictions. EXAMPLE
I want to copy the following Unix files to a MSDOS diskette (using the mcopy command). very_long_name 2.many.dots illegal: good.c prn.dev Capital Mcopy will convert the names to: very_lon 2xmany.dot illegalx good.c xprn.dev capital The command: mkmanifest very_long_name 2.many.dots illegal: good.c prn.dev Capital > manifest would produce the following: mv very_lon very_long_name mv 2xmany.dot 2.many.dots mv illegalx illegal: mv xprn.dev prn.dev mv capital Capital Notice that "good.c" did not require any conversion, so it did not appear in the output. Suppose I've copied these files from the diskette to another Unix system, and I now want the files back to their original names. If the file "manifest" (the output captured above) was sent along with those files, it could be used to convert the filenames. SEE ALSO
arc(1), pcomm(1), mtools(1) local MKMANIFEST(1)
All times are GMT -4. The time now is 11:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy