How to check OS version in RedHat
# cat /proc/version
How to check Distribution version
# cat /etc/*release
How to Zip a file/folder
Zip a Single File
To make a zip of single file, execute the below command:
#zip file.zip file1 file2
Zip Multiple Files
To make a zip of multiple files, execute the below command:
#zip file.zip file1 file2
Zip Single Folder
To make a zip of folder/directory, execute the below command:
#zip file.zip dir1
To make a optional zip of folder/directory, execute the below command:
#zip -option file.zip dir1
How to Set a Cronjob in Linux
Introduction
A crontab is a simple text file with a list of commands meant to be run at specified times. It is edited with a command-line utility. These commands (and their run times) are then controlled by the cron daemon, which executes them in the system background. Each user has a crontab file which specifies the actions and times at which they should be executed, these jobs will run regardless of whether the user is actually logged into the system. There is also a root crontab for tasks requiring administrative privileges. This system crontab allows scheduling of system wide tasks (such as log rotations and system database updates).
Syntax
Minutes Hours Day-of-Month Month-field Day-of-Week /path/to/Command
Set Cronjob
To set the cronjob that runs every 5 minutes
# crontab -e */5 * * * * /root/backup.sh
How to Check Memory in Linux
Following are some useful commands to check the memory status of machine:
free Command
Use free command to check the memory, buffers, cache memory
# free -m total used free shared buffers cached Mem: 6082 5801 280 0 155 3887 -/+ buffers/cache: 1759 4322 Swap: 1707 33 1674
top Command
Top command tells the detailed information of CPU i.e time, load average, CPU utilization, memory, swap memory.
# top top - 09:36:16 up 33 days, 16:47, 2 users, load average: 0.49, 0.47, 0.52 Tasks: 157 total, 1 running, 155 sleeping, 1 stopped, 0 zombie Cpu(s): 30.0%us, 2.4%sy, 0.0%ni, 67.0%id, 0.5%wa, 0.0%hi, 0.0%si, 0.1%st Mem: 6228500k total, 5975956k used, 252544k free, 159264k buffers Swap: 1748984k total, 34100k used, 1714884k free, 3980880k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 11774 www-data 20 0 99.8m 56m 6780 S 55 0.9 1:02.52 apache2 21086 www-data 20 0 100m 54m 5620 S 39 0.9 0:04.14 apache2 21075 www-data 20 0 66524 19m 4848 S 4 0.3 0:21.04 apache2
htop Command
Install htop on server, htop command also tells the detailed information of CPU i.e time, load average, CPU utilization, memory, swap memory but in a nice format.
# htop
Check Memory Consumption Processes
Process that are eating more memory
# ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20
How to Change Hostname in Linux
Method 1: Command Line
Step 1: Edit in /etc/sysconfig/network File
In order to change the hostname edit the following file:
# sudo nano /etc/sysconfig/network HOSTNAME=server.tecdistro.com
Step 2: Modify /etc/hosts File
Edit /etc/hosts File and enter the hostname along with IP Address of server for local use.
# vi /etc/hosts 127.0.0.1 tecdistro.com localhost.localdomain localhost 159.8.18.70 tecdistro.com tecdistro.com
Step 3: Modify the Hostname
# hostname tecdistro.com
# hostname tecdistro.com
Step 4: Restart Network
Now restart the network:
/etc/init.d/network restart
Method 2: GUI Environment
Step 1: Execute setup Command
# setup
Select Network Configuration Tab
Step 2: Select DNS Configuration
Step 3: Modify the Hostname
Once the changes have made, Select SAVE & QUIT and press ENTER key from keyboard.