Kunaljain's Weblog

October 19, 2007

Linux Tips and Tricks

Filed under: Linux Tips & Tricks — Kunal Jain @ 19:01

Easily finding Strings with grep color highlighting feature

Append the following lines in .bashrc and .bash_profile file

export GREP_COLOR=’1;37;41′
alias grep=’grep –color=auto’

Keeping files save from accidental overwritting

This happens many times you accidentally use redirecting output using > operator

For example you type a command

$ ls -l *.c > output.txt

if the file output.txt is already exists and is a regular file it will be overwritten. So how you tell Shell not to delete file data / contents by mistake?

you need to set noclobber variable. It can keep you from accidentally destroying your existing files by redirecting input over an already-existing file

Task: Set noclobber i.e Preventing Overwriting

$ set -o noclobber

Note:- “o -> Alphabetic character ‘o’ in small case”

Now try to write a file called output.txt

$ cat > output.txt


ls -l > output.txt


bash: output.txt: cannot overwrite existing file

Add set -o noclobber to your .bashrc file

$ echo`set -o noclobber` >> .bashrc

To Shutdown System Immediately

# shutdown -h now


# shutdown -h 0

However on the production server above command is dangerous as it won’t allow users to save work/data. It is better to give users a warning and then take down the server

# shutdown +5 “***Server is going down please save your work***”

Display List of Last Reboot Entries

Whenever you issue shutdown/reboot command a entry created in /var/log/wtmp file. Don’t open or modify this binary data file. You can read this log file with the help of “last” command

# last reboot | less

Display List of Last Shutdown Entries (Includes Run Level Changes)

# last -x | less

or even better entry try

# last -x | grep shutdown | less

Note:- The file /var/log/wtmp is log file which stores previous login sessions and use last command access information.

Linux Disable the Ctrl-Alt-Delete Shutdown Keys

On a production server it is recommended that you disable the [Ctrl]-[Alt]-[Delete] shutdown. It is configured using /etc/inittab. The inittab describe which processes is started at bootup and during normal operation. You need to open this file and remove or comment it Ctrl-Alt-Delete entry

To open /etc/inittab file, enter

# vi /etc/inittab

Search for the line that reads as follows:

ca:12345:ctrlaltdel:/sbin/shutdown -tl-a-r now

and remove or comment out the above line by putting the hash mark (#) in front of it

#ca:12345:ctrlaltdel:/sbin/shutdown tl-a-r now

Save the file and exit to the shell prompt. Reboot system to take effect or type the command

# init q


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: