There are a lot of processes running on your Linux system. Here is a command that will let you know how long the process has been running:
#ps -eo "%p %c %t"|grep "sshd"
In response to the above command, you will get the following output:
2850 sshd 172-01:37:22
29532 sshd 125-09:07:10
In the above command %p is pid, %c is command and %t is elapsed time...
How to check the date and time the system was rebooted #terminal #reboot #security
Here is a simple command to check the system's reboot date and time:
#last reboot
reboot system boot 2.6.18-53.el5 Sat Aug 6 18:02 (8+04:45)
wtmp begins Sat Aug 6 18:02:07 2011
The command below will give you the date and time the system was booted:
#who -b
system boot 2011-08-24 09:4...
Securing files #terminal #security #file
Here is a simple tip to password protect your files:
vi -x test
This command will ask for an encryption key. You have to type the key twice. Then save and quit the opened file.
Now, whenever you open this file, it will ask for that password first...
Cut specific logs #file #vi #cut
If you need to cut specific logs from the complete log of any application, here is a tip that will
be of help.
Open the log file in a vi editor and set the editor to display the line number:
vi server.log
:set nu
The above process will provide you the line numbers in the logs. You can then search for
the specific string and note down the line number (e.g., 550). Now, note down the last line
number by using Shift+G (e.g., 780)
sed -n 550,780p...
Print a file with line numbers #file #nl
If you want a file with line numbers (say for printing), you can use the 'nl' command in Linux:
$ nl file.c
This prints the file with line numbers to standard output or this can be even redirected to a
file as shown below:
$nl file.c > output.txt
Here, output.txt will have the codes of file.c with each line having a line number...
Measuring the network throughput between two Linux systems #networking #throughput
Iperf is a tool that measures the bandwidth and the quality of a network link. It can be installed very easily on any Linux system. One host must be set as the client and the other one as the server. Make sure that iperf is installed on both systems. If it is not installed, then use your package manager to install it before trying this tip.
Now run iperf on one of the Linux systems as the server, as shown below:
linux-erv3:/home/test/Desktop...
Find your OS and distribution name #terminal #system configuration
Here is a tip that will let you know the name of the OS, along with other details:
[root@vl-pun-blg-qa27]# lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description: CentOS release 5.5 (Final)
Release: 5.5
Codename: Fina...
View the contents of tar and rpm files #tar #rpm
Here are two simple commands to show you the contents of the tar and rpm files.
1. To view the content of a tar file, issue the following command:
#tar -tvf /path/to/file.tar
2. To view the content of an rpm file, use the command given below:
#rpm -qlp /path/to/file.rp...
Find your MySQL configuration file #mysql #grep #file
We often have to administer a system that has been set up by someone else. In such a situation, it's difficult to find the correct configuration files for different applications. Here is a tip to find the correct configuration file for MySQL:
mysql -? | grep ".cnf...
Replacing '\n' with 'space' in each line of a file #replace #awk
You can use the awk statement given below to remove the '\n' from each line and replace it with a blank space:
awk '$1=$1' ORS=' ' /etc/passw...
Comment out hashes in large configuration files
Here is a small tip for system administrators, who need to tackle large configuration files, which include lots of commented lines (marked by #). With this tip you can remove all those hashes and provide only an uncommented configuration view for faster lookup into the file.
If you want to check the configuration file of the Squid proxy server, run the following command:
#cat squid.conf | egrep -v ^#
This will show only lines that do not start...
Run a linux command after every reboot
This tip allows you to run any Linux command or script just after system reboot. You can use the @reboot cron keyword.
If you have a script in your /home directory and it needs to be run on every boot, open the cron file in editable mode and add the following:
$crontab -e
@reboot /home/xyz/myscript.sh
Do remember to enable crond on boot...
Connecting to a remote Linux Machine
If you want to execute any command or script on a remote Linux machine, you can use ssh. Below are a few examples.
The syntax for running a command or script on a remote server is:
ssh [USER]@[IP] [command or script]
Let us look at how this can be done. Suppose you want to display the directory contents of /root of a remote host, you can run the following command:
[user@ubunu]$ ssh root@192.168.0.128 ls -l /root
root@192.168.0.128's...