LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2015, 07:21 PM   #1
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Rep: Reputation: 16
Question How to delete history commands from 100 up to 150 at once on Centos


Hi

How can i delete history commands from 100 up to 150 at once on Centos?

Thanks
 
Old 02-16-2015, 12:52 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,480

Rep: Reputation: 620Reputation: 620Reputation: 620Reputation: 620Reputation: 620Reputation: 620
The history file is in~/.bash_history and is just a text file and so canbe manipulated like any other text file with head, tail, cat, sed etc
 
Old 02-16-2015, 04:04 PM   #3
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
May i have some examples please?
 
Old 02-16-2015, 04:50 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,322

Rep: Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470
Quote:
Originally Posted by ASTRAPI View Post
May i have some examples please?
Examples on how to edit a text file??? You have been registered here since 2007...in EIGHT YEARS, have you not yet figured out how to edit a simple text file???

You edit it with vi, nano, emacs, or any OTHER editor you choose to run. So "vi $HOME/.bash_history" would work for example
 
Old 02-16-2015, 05:42 PM   #5
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,480

Rep: Reputation: 620Reputation: 620Reputation: 620Reputation: 620Reputation: 620Reputation: 620
Quote:
Originally Posted by ASTRAPI View Post
May i have some examples please?
Seriously? If you need this sort of detailed handholding you shouldn't be trying to edit anything!
 
Old 02-16-2015, 06:46 PM   #6
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
I know how to edit a file but i am asking how can i delete history commands from 100 up to 150 at once using an ssh command (only one command).

Thanks
 
Old 02-16-2015, 07:13 PM   #7
Bret W
Member
 
Registered: Jan 2015
Posts: 33

Rep: Reputation: Disabled
Quote:
Originally Posted by ASTRAPI View Post
May i have some examples please?
First, check what command entries falls between 100 and 150.

Code:
history  | sed -n '100,150p' | less
if output from above is what you want to remove from history, then run

Code:
for i in {150..100}; do history -d "$i"; done ; sync
TIP

To delete entries manually, just type history -d <number>, then run sync when done.

If you don't want certain commands to be recorded to the history file, add ignorespace to the HISTCONTROL line usually found in /etc/profile. Now, if you precede a command with a space, it will not be recorded to the history file.

Last edited by Bret W; 02-16-2015 at 07:21 PM.
 
2 members found this post helpful.
Old 02-17-2015, 08:28 AM   #8
yx0p
LQ Newbie
 
Registered: Feb 2015
Posts: 14

Rep: Reputation: Disabled
Nice explanation Bret - this helped me out a bit too, especially with the ignorespace - useful thing to know.

Last edited by yx0p; 02-17-2015 at 08:29 AM.
 
Old 02-17-2015, 09:59 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,322

Rep: Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470Reputation: 4470
Quote:
Originally Posted by ASTRAPI View Post
I know how to edit a file but i am asking how can i delete history commands from 100 up to 150 at once using an ssh command (only one command).
And still, after eight years, you need assistance with figuring out a single command?? The most important question here would be WHY you want to do this. Be aware that any evidence you're trying to erase in that file will be given away by the fact that the command you're going to run will ALSO be logged in that history file. And anything of a more serious nature (say, anything you did with sudo), will be logged in the sudoers log file, and has probably left traces in several other parts of the system too.

If you're the administrator, there's no need to erase your personal user history log, since you already KNOW what's been done to your system. If you're NOT, and you're trying to cover your tracks to a misdeed...it is already too late.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] History utility error in Linux Mint 14; cannot delete history mintyninja41 Linux - Newbie 3 03-22-2013 07:36 AM
History commands u2u2u2 Linux - Newbie 1 04-13-2011 04:26 PM
Debian Quadcore with 150 mount.cifs going extremely slow on commands like 'ls' permalac Linux - Server 2 07-12-2010 03:40 AM
How to delete bash terminal history upto certain no. of commands sd|| Linux - Newbie 3 01-12-2010 03:13 PM
where is my history of commands? learnfast Linux - Newbie 3 03-14-2005 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration