Solaris - /usr/bin/rm file


 
Thread Tools Search this Thread
Operating Systems Solaris Solaris - /usr/bin/rm file
# 8  
Old 08-26-2010
Replacing the rm command does only part of the job. It does not help if a compiled program deletes a file via system call. There are also shells (like ksh93) which have a builtin rm command,

It's the same like under Windows, where the recycle bin is a feature of the graphical shell, not the operating system. If you open a command window and delete a file, then it is gone and not in the recycle bin.
# 9  
Old 08-28-2010
HI hergp...

thn hw to proceed further.. can u brife it... as said earlier i was planning to create an alias rm.
# 10  
Old 08-30-2010
Can you elaborate, in which cases the recycle bin should work and in which not?

Creating an alias to your own shell script (as robsonde suggested) works only for scripts or interactive shells that use this alias -> all others ... no effect

Replacing /usr/bin/rm with a script to place the file in the recylce bin works for all scripts and interactive shells -> no effect on compiled programs or shells with builtin rm command. And I doubt that it is such a great idea to replace an operating system command.

Writing a kernel module which intercepts the unlink system call and places the files to be deleted in the recycle bin -> effect on the whole system, but extremly high sophisticated and with a lot of side effects.

So, what should it be?
# 11  
Old 08-30-2010
If you are running Solaris 10 or newer, dtrace allows a userland implementation of such a kernel module:
Code:
#!/bin/ksh

[[ ! -d /var/tmp/trashcan ]] && pfexec mkdir /var/tmp/trashcan
export IFS="$(printf "\t")"
dtrace -qwn '
syscall::fsat:entry /arg0 == 5/ {
  printf("%d\t%d\t%d\t%s\t%s\n", walltimestamp, pid, uid, cwd, copyinstr(arg2));
  stop()
}
syscall::unlink:entry {
  printf("%d\t%d\t%d\t%s\t%s\n", walltimestamp, pid, uid, cwd, copyinstr(arg2));
  stop()
}' | while read walltimestamp pid uid cwd filename
do
  save=/var/tmp/trashcan/$(basename $filename).$(date +%Y%m%d-%H%M%S)
  cd $cwd
  echo "$walltimestamp: $uid [$cwd] [$filename]" >> /var/tmp/trashcan/logs
  cp "$filename" "$save"
  prun $pid
done

File removal performance will be strongly impacted by this script. Moreover, beware of disk full situations that might quickly happen should you let it running forever.
These 2 Users Gave Thanks to jlliagre For This Post:
# 12  
Old 08-30-2010
Great use of dtrace, jlliagre! Thanks for the idea.
# 13  
Old 08-30-2010
HI Jiliarge,

Could you pls explain the wat it does and wat should i do... still am a student in Solaris :-(
# 14  
Old 08-30-2010
It does precisely what hergp suggested: "Writing a kernel module which intercepts the unlink system call and places the files to be deleted in the recycle bin".
The recycle bin is /var/tmp/trashcan. Every deleted file is placed there suffixed by its deletion date.
A log file, /var/tmp/trashcan/log, is telling who deleted what and when.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. BSD

FreeBSD: /usr/bin/ld not looking in /usr/local/lib

I'm not sure if this is the default behavior for the ld command, but it does not seem to be looking in /usr/local/lib for shared libraries. I was trying to compile the latest version of Kanatest from svn. The autorgen.sh script seems to exit without too much trouble: $ ./autogen.sh checking... (2 Replies)
Discussion started by: AntumDeluge
2 Replies

2. Solaris

What is the difference between xpg4/bin and usr/bin?

Hi Experts, I found that the same commands(sort, du, df, find, grep etc.) exists in both dir. What is the difference to use them? i.e: to use xpg4/bin/grep and usr/bin/grep My OS version is SunOS 5.10 Regards, Saps (7 Replies)
Discussion started by: saps19
7 Replies

3. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

4. UNIX for Dummies Questions & Answers

Alias /usr/bin to /bin in profile

Hi! All the basic linux commands, ie. echo, find, etc, are located in /bin. I have a couple of programs that have these commands pointed towards /usr/bin, ie, /usr/bin/echo (even though the actual 'echo' command is in /bin). How can I alias or redirect or link the /usr/bin to /bin just for this... (6 Replies)
Discussion started by: dancerat
6 Replies

5. UNIX for Advanced & Expert Users

#!/usr/bin/env : perl no such file or directory

hi i have some perl scripts with shebang line as (#! /usr/bin/env perl ) instead of actual absolute path of perl ( i know why its that way ) everything works fine from command line , the problem is when i am trying to run those scripts from web ( local web tool ) it throws error as /usr/bin/env :... (6 Replies)
Discussion started by: zedex
6 Replies

6. Solaris

How do I link ld in /usr/ucb/ to /usr/ccs/bin?

Hi all, below is the problem details: ora10g@CNORACLE1>which ld /usr/ucb/ld ora10g@CNORACLE1>cd /usr/ccs/bin ora10g@CNORACLE1>ln -s /usr/ucb/ld ld ln: cannot create ld: File exists ora10g@CNORACLE1> how to link it to /usr/ccs/bin? (6 Replies)
Discussion started by: SmartAntz
6 Replies

7. Solaris

/usr/bin/cut not working with largefiles on Solaris 10

I have a person running a perl script that is parsing > 2G log files and pipes to cut -d " " -f 1,6,7,8... The script itself is in a nfs mounted home directory. It runs fine when started from a solaris 8 box but fails after about 400 lines when started from the solaris 10 box. The solaris... (1 Reply)
Discussion started by: wottie
1 Replies

8. UNIX for Dummies Questions & Answers

Difference between /bin, /usr/bin, /sbin ?

Hi All, Can somebody tell me the difference between /bin, /usr/bin, /sbin ? Thanx in advance, Saneesh Joseph (3 Replies)
Discussion started by: saneeshjose
3 Replies

9. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question