未加星标

How To Clear A Specific Command From Bash History In Linux

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏
Clear A Specific Command From Bash History In linux

As we all know, history command is used to view the list of recently-executed commands in Terminal. Not just commands, It will show you the list of recent activities in your Terminal. Every commands you execute in the Terminal will be recorded in a file called .bash_history in your HOME directory. To view the list of recently executed commands, just run:

history

You will see the most recent commands on the bottom. Simply press UP or DOWN arrow keys to select any previously executed command and run it again if you want to. Here is the sample output of history command from my Arch Linux.

[...]
485 sudo pacman -Su
486 sudo nano /etc/pacman.d/mirrorlist
487 sudo nano /etc/pacman.conf
488 fc-list | grep termi
489 fc-list | grep terminus
490 man rm
491 clear
492 ssh [email protected]
493 exit
494 sudo pacman -S powershell
495 yaourt -S powershell
496 clear
497 sudo pacman -Sy libreoffice
498 uname -r
499 clear
500 history

As you see in the above output, my history list file has around 500 recently executed commands. Each command has a number. And, the most recently executed commands will be saved in the bottom. Let us now get in to the topic. Just in case, have you ever wanted to clear a specific command from Bash history in Linux? It’s very easy! Follow the steps given below.

Say for example, to delete “sudo pacman -S powershell” command from the history, just run:

history -d 494

Here, -d flag deletes the selected command from the history file. 494 is the command number. Alternatively, you can edit .bash_history file and delete the commands of your choice.

Edit .bash_history file:

vi $HISTFILE

Or,

vi .bash_history

You will see the list of recently executed commands in this file. Just delete the commands you don’t want to see in the history command output.

To clear all history, just run:

history clear

Or,

history -c

Finally, run the following command to take effect the changes.

source ~/.bashrc

That’s it. Your history has been cleared now. This trick could be useful if you want to allow your junior admins or students to see what commands you have executed so far lately. For more details, check our details guide about history command in the following link.

How to clear Command line history in Linux

That’s all for now. If you find this guide useful, share it on your social networks and support us.

Cheers!

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: Linux
分页:12
转载请注明
本文标题:How To Clear A Specific Command From Bash History In Linux
本站链接:http://www.codesec.net/view/530409.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(15)