Monday, April 11, 2011

Replace local home directory with an existing partition

Find the UUID of the partition:
$ blkid /dev/sda1
... or ...
$ ls -l /dev/disk/by-uuid

Edit /etc/fstab file:
UUID=xxxxxxxxx /home ext3 defaults,noexec,nosuid 1 2

Move home to old-home, then remount partition.
$ mv /home /old-home
$ mkdir /home
$ mount -o remount /home

Friday, March 25, 2011

Find and delete large files

Find files larger than 1GB (display filesize and lsat modified time):

$ find <directory> -type f -size +1G
$ find <directory> -type f -size +1G -exec du -h --time {} \;


Sorted by file size (human readable size):

$ find <directory> -type f -size +1G -exec du --time {} \; | sort -n
$ find <directory> -type f -size +1G -exec du -h --time {} \; | sort -h


Find files that are larger than 1GB and older than 5 days (sorted by time):

$ find <directory> -type f -size +1G -mtime +5
$ find <directory> -type f -size +1G -mtime +5 -exec ls -lht {} +;


Find and delete files older than 5 days and larger than 1GB:

$ find <directory> -type f -size +1G -mtime +5 -exec rm {} \;

Friday, February 11, 2011

How to find out CentOS's version

$ cat /etc/issue
CentOS release 5.7 (Final)
Kernel \r on an \m

$ cat /etc/centos-release
CentOS release 6.3 (Final)

$ uname -a
Linux cle-dev 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

$ rpm -qa | grep ^centos
centos-release-notes-5.7-0
centos-release-5-7.el5.centos

$ yum list installed |grep ^centos
centos-indexhtml.noarch
centos-release.x86_64 6-3.el6.centos.9  @anaconda-CentOS-201207061011.x86_64/6.3

# Find out what package were installed with 'yum'
$ yum list installed

# e.g. mysql-server
$ yum list installed |grep ^mysql-server
mysql-server.x86_64   5.1.61-4.el6      @base

# e.g. php modules
$ yum list installed |grep ^php
php.x86_64            5.3.3-14.el6_3    @updates
php-cli.x86_64        5.3.3-14.el6_3    @updates
php-common.x86_64     5.3.3-14.el6_3    @updates
php-gd.x86_64         5.3.3-14.el6_3    @updates
php-intl.x86_64       5.3.3-14.el6_3    @updates
php-mbstring.x86_64   5.3.3-14.el6_3    @updates
php-mysql.x86_64      5.3.3-14.el6_3    @updates
php-pdo.x86_64        5.3.3-14.el6_3    @updates
php-soap.x86_64       5.3.3-14.el6_3    @updates
php-xml.x86_64        5.3.3-14.el6_3    @updates
php-xmlrpc.x86_64     5.3.3-14.el6_3    @updates