How To Make Writing to .bash_history Immediate

In Red Hat Linux, this is accomplished by adding a small script to the system’s profile.d directory. It is possible to edit existing files like bashrc but you may lose those changes when upgrading. I usually create a custom profile script that contains this as well as other global variables and place it at /etc/profile.d. For this post, we’ll create and get this setup.

It’s best if you login or su as root before you begin.

Create the file for the script

vim /etc/profile.d/

Add this to the script


# Location of this script: /etc/profile.d/

# Purpose of script is to makes writing to .bash_history immediate
shopt -s histappend

# End of script

Save the script and exit by typing


and press Enter. This writes and quits out of the vim editor.

Set permissions and ownership of file

chown root:root /etc/profile.d/
chmod 644 /etc/profile.d/

Make the script executable

chmod +x /etc/profile.d/

Log completely out, log back in, run a couple of commands (any commands like history, ls, etc.), and then check the history by running:

cat .bash_history

You should see the last couple of commands you just ran.


A quick break-down of the script itself

The first command changes the .bash_history file mode to append. And the second configures the ‘history -a’ command to be run at the shell. The ‘-a’ immediately writes the current/new lines to the .bash_history file.


How To Install GUI on Red Hat or CentOS

So you installed Red Hat or CentOS 7 using minimal install and all has been well. Now, you find that you’d like to install the GUI and don’t want to re-install the OS from scratch. No problem.

Start by installing yum-utils

yum install yum-utils

To list software groups, enter

yum grouplist

Output will be similar to this

Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
Available environment groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management

To install “Server with GUI” group, enter:

yum groupinstall "Server with GUI"

Once the installation is finished, you need to change system’s runlevel to runlevel 5. Changing runlevel on RHEL 7 and CentOS 7 is done by use of systemctl command.

systemctl enable --force

Depending on your previous installations you may need to accept Redhat License after you reboot your system.


CentOS 7

Simple Backup Script for Apache Web Server /w Mysql DB

Share on LinkedIn

This script may not be as clean as others but it gets the job done.

The purpose of this script is to backup both your entire web directory and database to a compressed file with date stamps. What you do with it from there is up to you.

Target: Web Directory and specific DB Instance – MUST know database name for this script

Environment Settings
Create /temp and /backups directories in /

mkdir temp
mkdir backups

See what’s in the directory by running the ls command


Output will be similar to this:

backups bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys temp tmp usr var

Create Script in / directory


The only items that need to be changed in this script are the items in ‘red‘.

#! /bin/bash
TIMESTAMP=$(date +"%F")

mkdir -p "$BACKUP_DIR/mysql"
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD $DATABASE | gzip > "$BACKUP_DIR/mysql/$DATABASE.gz"

mkdir -p "$BACKUP_DIR/web_dir"
tar --create --gzip --file=$DESTDIR$FILENAME $SRCDIR

tar --create --gzip --file=/backups/My-Backup-$TIMESTAMP.tgz $BACKUP_DIR

rm -rf /temp/*

echo "Backup of DB and Web Directory Complete!"

Make Script Executable

chmod +x

Run cron job every day at 1130pm

sudo crontab -e

Add the following to your cronjob:

30 23 * * * /bin/bash /

To Extract Backup files, you will need tar -zxvf for the main file and web directory file. You will need to use gzip -d for the database file.