Useful Commands in Linux and centos

/home full issue(creating disk space)

find /home/*/ -name .trash | xargs rm -rf

Free Hosting
==================
changing permission for file only

find . -type f -exec chmod 644 {} \;

for directory
find . -type d -exec chmod 775 {} \;


 find /home/*/public_html -iname '*.mp3' -exec mv "{}" /home/delete \;
 find /home/*/public_html -iname 'backup-' -exec mv "{}" /home/delete \;

==================
( this will check how fast the sites are resoving also)
Use /dev/hda or /dev/sda or what ever is the drive in the server:
hdparm -tT /dev/hda
This command will show results like:
/dev/hda:
Timing cached reads:   8808 MB in  2.00 seconds = 4406.87 MB/sec
Timing buffered disk reads:  162 MB in  3.03 seconds =  53.44 MB/sec
If the second measurement is under 40MB/sec, the server is too slow and needs a hardware checkup
Monitoring the system:
Basic command line:
Processes and parent-child relationships
top
Show top processes
Report CPU statistics and input/output statistics for devices and partitions.
process status
print system information
cat /proc/version
Display Linux kernel version in use.
cat /etc/redhat-release
Display Red Hat Linux Release. (also /etc/issue)
Tell how long the system has been running. Also number of users and system's load average.
w
Show who is logged on and what they are doing.
List all currently loaded kernel modules.
Same as cat /proc/modules
Displays the system's current runlevel.
Displays/changes the system's node name. (Must also manually change hostname setting in /etc/sysconfig/network. Command will change entry in /etc/hosts)
service
Red Hat/Fedora command to display status of system services.
Example: service --status-all
Help: service --help


Memory Usage:
Linux Commands to Monitor Memory Usage:
Monitor virtual memory
Display amount of free and used memory in the system. (Also: cat /proc/meminfo)
Display/examine memory map and libraries (so). Usage: pmap pid
top
Show top processes
sar -B
Show statistics on page swapping.
time -v date
Show system page size, page faults, etc of a process during execution. Note you must fully qualify the command as "/usr/bin/time" to avoid using the bash shell command "time".
cat /proc/sys/vm/freepages
Display virtual memory "free pages".
One may increase/decrease this limit: echo 300 400 500 > /proc/sys/vm/freepages
cat /proc/meminfo
Show memory size and usage.

User Info Commands

who Displays currently logged in users.
Use who -uH for idle time and terminal info.
users Show all users logged in.
 w Displays currently logged in users and processes they are running. whoami Displays user id.
groups Display groups you are part of.
Use groups user-id to display groups for a given user.
 set Display all environment variables in your current environment.
 id Display user and all group ids.
Use id user-id to display info for another user id.
last Listing of most recent logins by users. Show where from, date and time of login (ftp, ssh, ...) Also see lastlog command.
Show last 100 logins: last -100
history Shell command to display previously entered commands.

RPM Command
Description
rpm -qilp program_package-ver.rpm
Query for information on package and list destination of files to be installed by the package.
You can also use the Gnome GUI program file-roller to view and read the contents of an RPM. Great tool for inspecting an RPM package and reading the package documentation before you decide to install the package.
rpm2cpio - < program_package-ver.rpm | cpio -id ./path/and/file-name
Extract a single file (with path) from the RPM package to the local directory.
rpm -Uvh program_package-ver.rpm
Upgrade the system with the RPM package
rpm -ivh program_package-ver.rpm
New Install
rpm -Fvh program_package-ver.rpm
Freshen install. Removes all files (including config files) of older version during upgrade.
rpm -q program_package
Query system RPM database (/var/lib/rpm), to see if package is installed.
rpm -qi program_package
Query system RPM database for info/description on package (if installed)
rpm -ql program_package
List all files on the system associated with the package.
rpm -qf file
Identify the package to which this file belongs.
rpm -e program_package
Uninstall package from your system
rpm -qa
List ALL packages on your system. Use this with grep to find families of packages.
rpm -qp --requires program_package-ver.rpm
List dependancies (files and packages) of RPM. List prerequisites.
rpm -q --whatrequires program_package
List dependant packages of RPM. What packages will break if this RPM is removed.
rpm -K --nogpg *.rpm
Non sure if RPM downloaded ok? Verify md5 sum.

RPM Flag
Description
--nodeps
RPM flag to force install even if dependency requirements are not met.
--force
Overwrite of other packages allowed.
--notriggers
Don't execute scripts which are triggered by the installation of this package.
--root /directory-name
Use the system chrooted at /directory-name. This means the database will be read or modified under /directory-name. (Used by developers to maintain multiple environments)
--ignorearch
Allow installation even if the architectures of the binary RPM and host don't match. This is often required for RPM's which were assembled incorrectly

Yum Commands:

YUM Command Description
yum -y install package-name
Install package.
yum -y install package-name.arch
Install package of specified architecture. This is common when installing Firefox "i386" on a "x86_64" platform.
i.e.: yum -y install firefox.i386
yum -y update package-name
yum -y update
yum -y --exclude=package-name update
Update package.
Update all packages on system for which updates are available.
Update all packages which have available updates excluding the specified package.
yum remove package-name
yum remove package-name-1 package-name
yum remove package-name-2
Remove package.
Remove packages.
yum clean headers
yum clean cache
yum clean all
Remove RPM header files.
Remove files from YUM cache: /var/cache/yum/
Clean up all YUM files left over from previous installations.
yum list package-name
yum list regex
       
List information about available packages from configured YUM repository. Will also list those which contain the specified regular expression search pattern.
yum list installed [regex-optional]
       
List installed packages. Same as rpm -qa
yum list available [regex-optional]
       
List all available packages.
yum check-update
Show which packages are available to be updated.
yum search partial-package-name
List all packages which match the string specied in the package name or description.
yum grouplist
yum groupinstall group-name
yum groupremove group-name
yum groupupdate group-name
   
List available package groups.
Install default packages in specified group.
Remove packages in group.
Update packages in group.
rhn_register
Register to a Red Hat Network hosted server. Typically useful for licensed Red Hat Enterprise Linux.


Hardware Info:

List devices and info on system hardware. Also IRQ's.(RPM package procinfo)
Also cat /proc/devices
list all PCI devices (result of probe) Also lspci -vvx and cat /proc/pci
cat /proc/interrupts
List IRQ's used by system and the device using the interrupt.
cat /proc/ioports
List I/O ports used by system.
cat /proc/dma
List DMA channels and device used by system.
cat /proc/cpuinfo
List info about CPU.

File compression/decompression utilities:

Basic file compression utilities: (and file extensions)
     gzip (.gz): Also see zcat, gunzip, gznew, gzmore
compress: gzip file-name
decompress: gzip -d file-name.gz
     bzip2 (.bz2): Also see: bunzip2, bzcat, bzip2recover
compress: bzip2 file-name
decompress: bunzip2 file-name.bz2
     compress (.Z): (Adaptive Lempel-Ziv compression) Also see: uncompress, zcat
compress: compress file-name
decompress: uncompress file-name.Z
(Provided by the RPM package ncompress)
     pack (.z): Also see: unpack
compress: pack file-name
decompress: unpack file-name.z
     zip (.zip): Compress files or groups of files. (R.P.Byrne compression) Compatible with PC PKZIP files. Also see: unzip
compress: zip file-name
decompress: unzip file-name.zip


Exim Command :-

Here are some useful things to know for managing an Exim 4 server.
Message-IDs and spool files


The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids.
There are three -- count 'em, THREE -- files for each message in the spool directory. If you're dealing with these files by hand, instead of using he appropriate exim commands as detailed below, make sure you get them all, and don't leave Exim with remnants of messages in the queue.

Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id.

Files in /var/spool/exim/input are named after the message-id, plus a suffix denoting whether it is the envelope header (-H) or message data (-D).

These directories may contain further hashed subdirectories to deal with larger mail queues, so don't expect everything to always appear directly on the top /var/spool/exim/input or /var/spool/exim/msglog directories; any searches or greps will need to be recursive. See if there is a proper way to do what you're doing before working directly on the spool files.

Queues information

Print a count of the messages in the queue:

root@localhost# exim -bpc
Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):

root@localhost# exim -bp
Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

root@localhost# exim -bp | exiqsumm
Generate and display Exim stats from a logfile:

root@localhost# eximstats /path/to/exim_mainlog
Generate and display Exim stats from a logfile, with less verbose output:

root@localhost# eximstats -ne -nr -nt /path/to/exim_mainlog
Generate and display Exim stats from a logfile, for one particular day:

root@localhost# fgrep 2007-02-16 /path/to/exim_mainlog | eximstats
Print what Exim is doing right now:

root@localhost# exiwhat
To delete frozen emails

exim -bp | awk '$6~"frozen" { print $3 }' | xargs exim -Mrm
To deliver emails forcefully

exim -qff -v -C /etc/exim.conf &
Searching the queue

Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep. Learn it. Know it. Live it. If you're not using this, and if you're not familiar with the various flags it uses, you're probably doing things the hard way, like piping `exim -bp` into awk, grep, cut, or `wc -l`.

Search the queue for messages from a specific sender:

root@localhost# exiqgrep -f [luser]@domain
Search the queue for messages for a specific recipient/domain:

root@localhost# exiqgrep -r [luser]@domain
Print just the message-id as a result of one of the above two searches:

root@localhost# exiqgrep -i [ -r | -f ] ...
Print a count of messages matching one of the above searches:

root@localhost# exiqgrep -c [ -r | -f ] ...
Print just the message-id of the entire queue:

root@localhost# exiqgrep -i
Managing the queue, Start a queue run:

root@localhost# exim -q -v
Start a queue run for just local deliveries:

root@localhost# exim -ql -v
Remove a message from the queue:

root@localhost# exim -Mrm [ ... ]
Freeze a message:

root@localhost# exim -Mf [ ... ]
Thaw a message:

root@localhost# exim -Mt [ ... ]
Deliver a specific message:

root@localhost# exim -M [ ... ]
Force a message to fail and bounce:

root@localhost# exim -Mg [ ... ]
Remove all frozen messages:

root@localhost# exiqgrep -z -i | xargs exim -Mrm
Remove all messages older than five days (86400 * 5 = 432000 seconds):

root@localhost# exiqgrep -o 1296000 -i | xargs exim -Mrm
Freeze all queued mail from a given sender:

root@localhost# exiqgrep -i -f luser@example.tld | xargs exim -Mf
View a message's headers:

root@localhost# exim -Mvh
View a message's body:

root@localhost# exim -Mvb
View a message's logs:

root@localhost# exim -Mvl

Comments

Popular Posts

Install and configure rsyslog Centralized logging server in CentOS

How to fix postfix/smtp Network is unreachable error

Could not join realm: Necessary packages are not installed: sssd-tools sssd libnss-sss libpam-sss adcli