Skip to content

Commit a70d8aa

Browse files
authored
Answer Linux (bregman-arie#10311)
Answer : You executed a script and while still running, it got accidentally removed. Is it possible to restore the script while it's still running?
1 parent 193c430 commit a70d8aa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

topics/linux/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,20 @@ This is a good article about the topic: https://ops.tips/blog/how-linux-creates-
21432143
21442144
<details>
21452145
<summary>You executed a script and while still running, it got accidentally removed. Is it possible to restore the script while it's still running?</summary><br><b>
2146+
It is possible to restore a script while it's still running if it has been accidentally removed. The running script process still has the code in memory. You can use the /proc filesystem to retrieve the content of the running script.
2147+
1.Find the Process ID by running
2148+
```
2149+
ps aux | grep yourscriptname.sh
2150+
```
2151+
Replace yourscriptname.sh with your script name.
2152+
2.Once you have the PID, you can access the script's memory through the /proc filesystem. The script will be available at /proc/<PID>/fd/, where <PID> is the process ID of the running script. Typically, the script's file descriptor is 0 or 1.
2153+
2154+
You can copy the script content to a new file using the cp command:
2155+
```
2156+
cp /proc/<PID>/fd/0 /path_to_restore_your_file/yourscriptname.sh
2157+
```
2158+
Replace <PID> with the actual PID of the script and /path_to_restore_your_file/yourscriptname.sh with the path where you want to restore the script.
2159+
21462160
</b></details>
21472161
21482162
<a name="questions-linux-memory"></a>

0 commit comments

Comments
 (0)