How to clear Command line history in Linux/Centos

Sunday, March 19, 2017

How to delet Command line history in Linux/Centos :-



Clear Command line history in Linux/Centos -
There are lot of ways to clear Command line history.

1. Clear entire Command line history using ‘history’ command


To view the recently-executed commands -

>history

To clear the history, just run any one of the following command after you’re done:

>history -c

Or

>history -cw


2. Clear a Command line history using by inserting a blank space before each command


   using this way, we can clear/delete any particular command from the history. we need to put a blank space before any command. The command will not be recorded in history.

To do that, you must set HISTCONTROL environment variable’s value as “ignorespace” or “ignoreboth”.

export HISTCONTROL=ignorespace

Now, Let us see an example. I ran the following commands. And, I put a blank space in-front of the last command.

>clear

>uname -a

>sudo pacman -Syyu

>sudo wifi-menu

>ls

>sudo ping example.com


Now, run the ‘history’ command to view the recent-executed commands.

history
Sample output:

 3 clear
 4 export HISTCONTROL=ignorespace
 5 clear
 6 uname -a
 7 sudo pacman -Syyu
 8 sudo wifi-menu
 9 ls
 10 history

3. Clear or delete specific commands from history

This is another useful way to delete a particular command. Sometimes you might want to delete some critical commands, which causes damage to the system, from the history. This method will be helpful if you don’t want to clear the entire history.

Let us see an example. I ran the following commands.

>clear

>cal

>time

>ls

>uname -r

display the history command output:

history
sample output:

 3 clear
 4 cal
 5 time
 6 ls
 7 uname -r

 8 history

As you see in the above output, the history command displays the recently-executed commands.

To clear or delete a particular command from the history, do:

history -d
Here represents the line number of each command. For example, let us delete the “time” command with line number “5” from the history.

To do so, run:

history -d 5
Now, display the command line history to see if the command is remove or not.

history
Sample output:

 3 clear
 4 cal
 5 ls
 6 uname -r
 7 history
 8 history -d 5
 9 history


4. Delete Command line history permanently


One problem of using all above methods is they will only remove the commands from the active session i.e currently opened Terminal. That means if you have multiple Terminals running different commands, the ‘history’ command will only delete the history from where you run this command. The commands from other Terminals will still be available.

To remove all commands from history in all sessions (Terminals), you must remove the contents of .bash_history file. As you might know already, this file holds the list of commands that we run in the Terminal over time.

You can either clear this file manually each time or setup a cron job to clear it at regular intervals.

To clear the contents of this file manually each time, run:

cat /dev/null > ~/.bash_history
Like I said, this will delete the entire history of all sessions. The next day, however, this file will start to record the history. You should run this command everyday to clear the contents of this file.

Alternatively, you can schedule this task at regular interval using cron jobs.

To do so, run:

crontab -e
Add the following commands:

00 20 * * * cat /dev/null > ~/.bash_history


Why shouldn’t we clear Command line history?


Clearing Command line history is a good practice, however you must not clear history in some cases. Say for example, you want to repeat a command often. Would you type the command every time? That’s not necessary. Like I said already, the commands that you run on the Terminal will be retained in the ~/.bash_history file. Just hit the upper arrow in the keyboard, the list commands that you run recently will appear. Keep hitting the upper arrow key until you find the command that you want to run. Once you find the command that you want to run, just hit ENTER to execute. That’s it. You don’t have to type the command each time. Also, sometimes you won’t remember exactly how you executed a command in a previous session. In such cases, history command will come in help.

Read more...

How to Convert SSL Certificate File from CRT TO DER TO PEM Format?

Saturday, March 11, 2017

How to Convert SSL Certificate File from CRT TO DER TO PEM Format :-

There are following steps :-

1. Open a putty session to the Secure VM

2. Copy the obtained CRT file from the CSR to the working directory

3. Run the following command to first convert the CRT file to a DER file:
openssl x509 -in example.crt -out openssl.der -outform DER
             (Substitute example.crt as your current CRT filename)

4. Then run the following command to convert the openssl.der file which we just created, to a PEM file
openssl x509 -in openssl.der -inform DER -out openssl.pem -outform PEM

5. There you go.  Now you have a openssl.pem file which works for Netmail Secure.


Read more...

Restarting Linux Services using Command Line

Wednesday, March 1, 2017

Restarting Linux Services using Command Line:-


How to restart some listed services using command line in Linux/Centos/Ubuntu Server.

Lot of Services Example here.

1. Plesk Control Panel
    You can restart the Plesk interface by logging into your server using SSH & using the following command.

   etc/init.d/sw-cp-server restart


2. Email Services
   You can restart the email service by running the following commands.

   1) Restart qmail

     etc/init.d/qmail restart

   2) Restart Postfix 

       postfix stop
       postfix start

    3) Restart IMAP

      /etc/init.d/courier-imap stop
      /etc/init.d/courier-imap start


3. Webservices
    You can restart your webservices like httpd/apache2 by using the following command.

    1) Ubuntu

       /etc/init.d/apache2 restart

    2) CentOS

       /etc/init.d/httpd restart


4. DNS Services
    IF your websites are not being displayed, subdomains not displaying, issues with IPv4 and IPv6 address or getting error messages relating to dnsmg. You can restart your DNS services by running the following command.

    /etc/init.d/bind9 restart


5. MySQL database Services
    you can restart the service by using the following command.

   /etc/init.d/mysql restart


6. Unsure what service to reset?
      The following command will restart several services together.

     /etc/init.d/psa restart

Read more...

How To Find A Particular Text String In Files/Directory Linux

How To Find A Particular Text String In Files/Directory Linux :-


There are around thousands of text files on any Linux/Centos/Ubuntu or Unix based server. Need to Find and locate those files can be done with the find command.

You need to use the grep command. The grep command searches the given input Files for lines containing a match or a text string.

grep command syntax

The syntax is:

grep "your search string" directory-path

OR

grep [option] "your search string" directory-path

OR

grep -r "your search string" directory-path

OR

grep -r -H "your search string" directory-path

OR

egrep -R "word-1|word-2" directory-path

OR

egrep -w -R "word-1|word-2" directory-path


All Examples :-

Example 1.
In this example, search for a string called ‘my handler’ in all text (*.txt) files located in /home/user/ directory, use:

$ grep "my handler" /home/user/*.txt

OR
$ grep "my handler" ~/*.txt

Example 2.
Search all subdirectories recursively
You can search for a text string all files under each directory, recursively with -r option:
$ grep -r "my handler" /home/user/

OR
$ grep -R "my handler" /home/user/

Example 3.
Only display filenames
By default, the grep command prints the matching lines. You can pass -H option to print the filename for each match:
$ grep -H -r "my handler" /home/user

Sample outputs:

myfile.txt: my handler
handler.txt: my handler
...
To just display the filename use the cut command as follows:
$ grep -H -R somy /etc/* | cut -d: -f1

Sample outputs:

myfile.txt
handler.txt
......

Example 4.
Suppress file names
The grep command shows output on a separate line, and it is preceded by the name of the file in which it was found in the case of multiple files. You can pass the -h option to suppress inclusion of the file names in the output:
$ grep -h -R 'main()' ~/projects/*.c

Example 5.
Display only words
You can select only those lines containing matches that form whole words using the -w option. In this example, search for word ‘getMyProfile()’ only in ~/projects/ dirctory:
$ grep -w -R 'getMyProfile()' ~/projects/

Example 6.
Search for two or more words
Use the egrep command as follows:
$ egrep -w -R 'word1|word2' ~/projects/

Example 7.
Hide warning spam
grep command generate error message as follows due to permission and other issues:

No such file or directory
No such device or address
Permission denied

To hide all errors or warning message spam generated by the grep command, append 2>/dev/null to grep command. This will send and hide unwanted output to /dev/null device:
$ grep -w -R 'getMyProfile()' ~/projects/ 2>/dev/null

Example 8.
Display matched text in color
Pass the --color option to the grep command display matched text/words in color on the terminal:

grep --color 'word' file
grep --color -R 'word' /path/to/dir
grep --color -R "192.168.1.5" /etc/
grep --color -R -h "192.168.1.5" /etc/
grep --color -R -h "192.168.1.5" /etc/ 2>/dev/null
Sample outputs:

Fig.01: grep command in action with colors and hiding the warnings on screen
Fig.01: grep command in action with colors and hiding the warnings on screen

Example 9.
Ignore case
Our final example ignore case distinctions in both the search PATTERN and the input files:
grep -i -R 'word' /path/to/dir
grep -i -r 'income tax return' ~/accountingfiles/

Read more...

How To Restart IMAP Services ( dovecot IMAP server )

How To Restart IMAP Services ( dovecot IMAP server ) :-


How do I restart dovecot IMAP4 / IMAP in RHEL / CentOS / Fedora / Debian / Ubutnu Linux ?

Normally The default IMAP server port number is 143
In Linux you can install different IMAP servers also

Restart Dovecot IMAP mail server :-

Type the following command to start / stop and restart server under RHEL / CentOS / Fedora Linux:
# service dovecot start
# service dovecot stop
# service dovecot restart

Automatically reload sever next boot, enter:
# chkconfig dovecot on

To turn off auto loading on next boot, enter:
# chkconfig dovecot off



A Note About Debian / Ubuntu Linux User

Type the following command to start / stop and restart server under Debian / Ubuntu Linux:
# /etc/init.d/dovecot start
# /etc/init.d/dovecot stop
# /etc/init.d/dovecot restart

Use a text-based application called sysvconfig that allows you to configure which services are started at boot time for each runlevel including dovecot under Debian / Ubuntu Linux:
# sysvconfig

Read more...

Logs coming with systemd messages: Created slice & Starting Session

Logs coming with systemd messages: Created slice & Starting Session :-

Normally thiss issue is come Centos/Linux/RHEL7 newely installed system. when i check following in /var/log/messages all the time show.

Aug 23 06:40:20 example.com systemd: Created test user-0.test.
Aug 23 06:40:20 example.com systemd: Starting Session 150 of user root.
Aug 23 06:40:20 example.com systemd: Started Session 150 of user root.
Aug 23 06:40:20 example.com systemd: Created test user-0.test.
Aug 23 06:40:21 example.com systemd: Starting Session 151 of user root.
Aug 23 06:40:22 example.com systemd: Started Session 151 of user root.

Solution :-
These messages are normal and expected -- they will be seen any time a user logs in

To suppress these log entries in /var/log/messages, create a discard filter with rsyslog, e.g., run the following command:

echo 'if $programname == "systemd" and ($msg contains "Starting Session" or $msg contains "Started Session" or $msg contains "Created slice" or $msg contains "Starting user-") then stop' >/etc/rsyslog.d/ignore-systemd-session-slice.conf

Then restart the rsyslog service

systemctl restart rsyslog

Read more...

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP