Diagnosing directory deletions on Linux
up vote
0
down vote
favorite
Yesterday evening I lost all of my project, or to be more exact, the directory tree named f/ that was in my home directory.
I restored from a backup.
A few minutes ago it disappeared again (fortunately for me, I started backing up with every rebuild since then and I rebuild often so no losses this time). I'm not aware of any executable I could have run or written myself that could've done this.
Since the issue seems to be isolated to ~/f/, I think it's some buggy script that wanted to do rm -rf and instead did rm -r f.
How can I find the culprit?
linux
add a comment |
up vote
0
down vote
favorite
Yesterday evening I lost all of my project, or to be more exact, the directory tree named f/ that was in my home directory.
I restored from a backup.
A few minutes ago it disappeared again (fortunately for me, I started backing up with every rebuild since then and I rebuild often so no losses this time). I'm not aware of any executable I could have run or written myself that could've done this.
Since the issue seems to be isolated to ~/f/, I think it's some buggy script that wanted to do rm -rf and instead did rm -r f.
How can I find the culprit?
linux
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Yesterday evening I lost all of my project, or to be more exact, the directory tree named f/ that was in my home directory.
I restored from a backup.
A few minutes ago it disappeared again (fortunately for me, I started backing up with every rebuild since then and I rebuild often so no losses this time). I'm not aware of any executable I could have run or written myself that could've done this.
Since the issue seems to be isolated to ~/f/, I think it's some buggy script that wanted to do rm -rf and instead did rm -r f.
How can I find the culprit?
linux
Yesterday evening I lost all of my project, or to be more exact, the directory tree named f/ that was in my home directory.
I restored from a backup.
A few minutes ago it disappeared again (fortunately for me, I started backing up with every rebuild since then and I rebuild often so no losses this time). I'm not aware of any executable I could have run or written myself that could've done this.
Since the issue seems to be isolated to ~/f/, I think it's some buggy script that wanted to do rm -rf and instead did rm -r f.
How can I find the culprit?
linux
linux
asked Nov 23 at 16:58
PSkocik
602623
602623
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Assuming rm is indeed involved and it's /bin/rm:
sudo ln /bin/rm /bin/rm-real
Create a log directory writable to anyone:
mkdir /tmp/rm-logdir
chmod a+w /tmp/rm-logdir
Write a wrapper script (named
script) like this:
#!/bin/sh
pstree -spa "$$" >> "/tmp/rm-logdir/$$"
exec /bin/rm-real "$@"
Adjust ownership and permissions of the script so it can mimic
rm(non-POSIX fast way:chmod --reference=/bin/rm script; sudo chown --reference=/bin/rm script).
Replace
/bin/rmwith the script:
sudo mv script /bin/rm
From now on anything that calls
/bin/rmwill be logged to a file in/tmp/rm-logdir.
Wait for the problem to occur again.
Examine files in
/tmp/rm-logdir. One of them will hopefully contain something like this:
systemd,1
`-tmux: server,2652
`-bash,8605
`-rm,15100 /bin/rm -r f
`-pstree,15101 -spa 15100
with command line arguments and PIDs; note the last but one line. The above is in fact an example from my tests in Kubuntu, where I run
rm -r fin interactivebash. Another example (not triggered directly by me) was:
systemd,1
`-kdeinit5,1679
`-ksmserver,1700
`-rm,16400 /bin/rm /home/kamil/.config/session/kate_10d8d5de64000154299531000000017000020_1542995310_707537
`-pstree,16401 -spa 16400
It proves other tools (
ksmserverin this case) use the wrapper script.
Notes:
pstreeis not required by POSIX, it may be unavailable. You can useps, you can read information directly from/proc.- In multi-user environment the solution is not safe. Anyone can write to the log directory. This is deliberately set to capture anyone's
rminvocations in a lazy, quick and dirty way. But then anyone can spoof the results.
To revert:
sudo mv /bin/rm-real /bin/rm
(note this will overwrite the script, so if there's no other copy of it, the script itself will be lost).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Assuming rm is indeed involved and it's /bin/rm:
sudo ln /bin/rm /bin/rm-real
Create a log directory writable to anyone:
mkdir /tmp/rm-logdir
chmod a+w /tmp/rm-logdir
Write a wrapper script (named
script) like this:
#!/bin/sh
pstree -spa "$$" >> "/tmp/rm-logdir/$$"
exec /bin/rm-real "$@"
Adjust ownership and permissions of the script so it can mimic
rm(non-POSIX fast way:chmod --reference=/bin/rm script; sudo chown --reference=/bin/rm script).
Replace
/bin/rmwith the script:
sudo mv script /bin/rm
From now on anything that calls
/bin/rmwill be logged to a file in/tmp/rm-logdir.
Wait for the problem to occur again.
Examine files in
/tmp/rm-logdir. One of them will hopefully contain something like this:
systemd,1
`-tmux: server,2652
`-bash,8605
`-rm,15100 /bin/rm -r f
`-pstree,15101 -spa 15100
with command line arguments and PIDs; note the last but one line. The above is in fact an example from my tests in Kubuntu, where I run
rm -r fin interactivebash. Another example (not triggered directly by me) was:
systemd,1
`-kdeinit5,1679
`-ksmserver,1700
`-rm,16400 /bin/rm /home/kamil/.config/session/kate_10d8d5de64000154299531000000017000020_1542995310_707537
`-pstree,16401 -spa 16400
It proves other tools (
ksmserverin this case) use the wrapper script.
Notes:
pstreeis not required by POSIX, it may be unavailable. You can useps, you can read information directly from/proc.- In multi-user environment the solution is not safe. Anyone can write to the log directory. This is deliberately set to capture anyone's
rminvocations in a lazy, quick and dirty way. But then anyone can spoof the results.
To revert:
sudo mv /bin/rm-real /bin/rm
(note this will overwrite the script, so if there's no other copy of it, the script itself will be lost).
add a comment |
up vote
1
down vote
accepted
Assuming rm is indeed involved and it's /bin/rm:
sudo ln /bin/rm /bin/rm-real
Create a log directory writable to anyone:
mkdir /tmp/rm-logdir
chmod a+w /tmp/rm-logdir
Write a wrapper script (named
script) like this:
#!/bin/sh
pstree -spa "$$" >> "/tmp/rm-logdir/$$"
exec /bin/rm-real "$@"
Adjust ownership and permissions of the script so it can mimic
rm(non-POSIX fast way:chmod --reference=/bin/rm script; sudo chown --reference=/bin/rm script).
Replace
/bin/rmwith the script:
sudo mv script /bin/rm
From now on anything that calls
/bin/rmwill be logged to a file in/tmp/rm-logdir.
Wait for the problem to occur again.
Examine files in
/tmp/rm-logdir. One of them will hopefully contain something like this:
systemd,1
`-tmux: server,2652
`-bash,8605
`-rm,15100 /bin/rm -r f
`-pstree,15101 -spa 15100
with command line arguments and PIDs; note the last but one line. The above is in fact an example from my tests in Kubuntu, where I run
rm -r fin interactivebash. Another example (not triggered directly by me) was:
systemd,1
`-kdeinit5,1679
`-ksmserver,1700
`-rm,16400 /bin/rm /home/kamil/.config/session/kate_10d8d5de64000154299531000000017000020_1542995310_707537
`-pstree,16401 -spa 16400
It proves other tools (
ksmserverin this case) use the wrapper script.
Notes:
pstreeis not required by POSIX, it may be unavailable. You can useps, you can read information directly from/proc.- In multi-user environment the solution is not safe. Anyone can write to the log directory. This is deliberately set to capture anyone's
rminvocations in a lazy, quick and dirty way. But then anyone can spoof the results.
To revert:
sudo mv /bin/rm-real /bin/rm
(note this will overwrite the script, so if there's no other copy of it, the script itself will be lost).
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Assuming rm is indeed involved and it's /bin/rm:
sudo ln /bin/rm /bin/rm-real
Create a log directory writable to anyone:
mkdir /tmp/rm-logdir
chmod a+w /tmp/rm-logdir
Write a wrapper script (named
script) like this:
#!/bin/sh
pstree -spa "$$" >> "/tmp/rm-logdir/$$"
exec /bin/rm-real "$@"
Adjust ownership and permissions of the script so it can mimic
rm(non-POSIX fast way:chmod --reference=/bin/rm script; sudo chown --reference=/bin/rm script).
Replace
/bin/rmwith the script:
sudo mv script /bin/rm
From now on anything that calls
/bin/rmwill be logged to a file in/tmp/rm-logdir.
Wait for the problem to occur again.
Examine files in
/tmp/rm-logdir. One of them will hopefully contain something like this:
systemd,1
`-tmux: server,2652
`-bash,8605
`-rm,15100 /bin/rm -r f
`-pstree,15101 -spa 15100
with command line arguments and PIDs; note the last but one line. The above is in fact an example from my tests in Kubuntu, where I run
rm -r fin interactivebash. Another example (not triggered directly by me) was:
systemd,1
`-kdeinit5,1679
`-ksmserver,1700
`-rm,16400 /bin/rm /home/kamil/.config/session/kate_10d8d5de64000154299531000000017000020_1542995310_707537
`-pstree,16401 -spa 16400
It proves other tools (
ksmserverin this case) use the wrapper script.
Notes:
pstreeis not required by POSIX, it may be unavailable. You can useps, you can read information directly from/proc.- In multi-user environment the solution is not safe. Anyone can write to the log directory. This is deliberately set to capture anyone's
rminvocations in a lazy, quick and dirty way. But then anyone can spoof the results.
To revert:
sudo mv /bin/rm-real /bin/rm
(note this will overwrite the script, so if there's no other copy of it, the script itself will be lost).
Assuming rm is indeed involved and it's /bin/rm:
sudo ln /bin/rm /bin/rm-real
Create a log directory writable to anyone:
mkdir /tmp/rm-logdir
chmod a+w /tmp/rm-logdir
Write a wrapper script (named
script) like this:
#!/bin/sh
pstree -spa "$$" >> "/tmp/rm-logdir/$$"
exec /bin/rm-real "$@"
Adjust ownership and permissions of the script so it can mimic
rm(non-POSIX fast way:chmod --reference=/bin/rm script; sudo chown --reference=/bin/rm script).
Replace
/bin/rmwith the script:
sudo mv script /bin/rm
From now on anything that calls
/bin/rmwill be logged to a file in/tmp/rm-logdir.
Wait for the problem to occur again.
Examine files in
/tmp/rm-logdir. One of them will hopefully contain something like this:
systemd,1
`-tmux: server,2652
`-bash,8605
`-rm,15100 /bin/rm -r f
`-pstree,15101 -spa 15100
with command line arguments and PIDs; note the last but one line. The above is in fact an example from my tests in Kubuntu, where I run
rm -r fin interactivebash. Another example (not triggered directly by me) was:
systemd,1
`-kdeinit5,1679
`-ksmserver,1700
`-rm,16400 /bin/rm /home/kamil/.config/session/kate_10d8d5de64000154299531000000017000020_1542995310_707537
`-pstree,16401 -spa 16400
It proves other tools (
ksmserverin this case) use the wrapper script.
Notes:
pstreeis not required by POSIX, it may be unavailable. You can useps, you can read information directly from/proc.- In multi-user environment the solution is not safe. Anyone can write to the log directory. This is deliberately set to capture anyone's
rminvocations in a lazy, quick and dirty way. But then anyone can spoof the results.
To revert:
sudo mv /bin/rm-real /bin/rm
(note this will overwrite the script, so if there's no other copy of it, the script itself will be lost).
edited Nov 23 at 18:24
answered Nov 23 at 18:11
Kamil Maciorowski
22.8k155072
22.8k155072
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377854%2fdiagnosing-directory-deletions-on-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown