简体   繁体   English

如何清除在 linux 中执行的 bash 脚本的 shell 的历史记录?

[英]how to clear history of shell that a bash script executed from it in linux?

I have a bash script in Linux and i want to clear history of shell that my script executed from it.我在 Linux 中有一个 bash 脚本,我想清除我的脚本从它执行的 shell 的历史记录。

I know that history -c clears current session history, but i want to clear parent session history.我知道history -c清除当前 session 历史记录,但我想清除父 session 历史记录。

My script is look like this:我的脚本是这样的:

#!/bin/bash

# my code

history -c

cat /dev/null > ~/.bash_history

but it doesn't work!但它不起作用!

How can i do this?我怎样才能做到这一点?

I try this and it works, but after re switch to root user:我尝试了这个并且它有效,但是在重新切换到root用户之后:

su - root -c "history -c"
su - root -c "cat /dev/null > ~/.bash_history"

history -c
cat /dev/null > ~/.bash_history

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM