April 12

Linux: Find files by size

Linux List All Large Files

To finds all files over 50,000KB (50MB+) in size and display their names, along with size, use following syntax:
Syntax for RedHat / CentOS / Fedora Linux

find {/path/to/directory/} -type f -size +{size-in-kb}k -exec ls -lh {} ; | awk ‘{ print $9 “: ” $5 }’
Search or find big files Linux (50MB) in current directory, enter:
$ find . -type f -size +50000k -exec ls -lh {} ; | awk ‘{ print $9 “: ” $5 }’
Search in my /var/log directory:
# find /var/log -type f -size +100000k -exec ls -lh {} ; | awk ‘{ print $9 “: ” $5 }’
Syntax for Debian / Ubuntu Linux

find {/path/to/directory} -type f -size +{file-size-in-kb}k -exec ls -lh {} ; | awk ‘{ print $8 “: ” $5 }’
Search in current directory:
$ find . -type f -size +10000k -exec ls -lh {} ; | awk ‘{ print $8 “: ” $5 }’
Sample output:

./.kde/share/apps/akregator/Archive/http___blogs.msdn.com_MainFeed.aspx?Type=AllBlogs.mk4: 91M
./out/out.tar.gz: 828M
./.cache/tracker/file-meta.db: 101M
./ubuntu-8.04-desktop-i386.iso: 700M
./vivek/out/mp3/Eric: 230M

Above commands will lists files that are are greater than 10,000 kilobytes in size. To list all files in your home directory tree less than 500 bytes in size, type:
$ find $HOME -size -500b
OR
$ find ~ -size -500b

To list all files on the system whose size is exactly 20 512-byte blocks, type:
# find / -size 20
Perl hack: To display large files

Jonathan has contributed following perl code print out stars and the length of the stars show the usage of each folder / file from smallest to largest on the box:

du -k | sort -n | perl -ne ‘if ( /^(d+)s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf (“%6.1ft%st%25s %sn”,($1/(2**(10*$m))),((“K”,”M”,”G”,”T”,”P”)[$m]),”*”x (1.5*$l),$2);}’

ls command: finding the largest files in a directory

You can also use ls command:
$ ls -lS
$ ls -lS | less
$ ls -lS | head +10
ls command: finding the smallest files in a directory

Use ls command as follows:
$ ls -lSr
$ ls -lSr | less
$ ls -lSr | tail -10

By: Vivek Gite

Category: Linux | Comments Off on Linux: Find files by size
April 12

Linux: How to Tar/Un Tar a Folder

To Tar:
tar –cvzf tarfilename foldername

Untar:
tar –xvzf tarfilename

Example:
tar –cvzf abc.tar.gz abc
– This will zip [tar] the abc folder with the name abc.tar.gz

tar –xvzf filename.tar.gz
– This will unzip [untar] the file as abc folder.

By: Shane G.

Category: Linux | Comments Off on Linux: How to Tar/Un Tar a Folder
April 11

Linux: Convert Red Hat to Centos – In place upgrade

The following information should allow you to do an in place upgrade of Redhat to Centos
It is safest to upgrade with in the same major version number. (eg RH 5.1 to Centos 5.8 not Centos)
**Do this at your own risk. I am not responsible if you try this and it does not work – nighthawk**

You can choose any repository that you prefer.
If you are doing this to an outdated version then you may need to goto (vault.centos.org)

Log in as root and start a terminal session.

yum clean all

mkdir ~/centos

cd ~/centos/

wget http://mirror.rit.edu/pub/CentOS/5.8/os/i386/RPM-GPG-KEY-CentOS-5

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/centos-release-5-8.el5.centos.i386.rpm

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/centos-release-notes-5.8-0.i386.rpm

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/yum-3.2.22-39.el5.centos.noarch.rpm

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/yum-updatesd-0.9-2.el5.noarch.rpm

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm

wget http://mirror.rit.edu/centos/5.8/os/i386/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm

rpm –import RPM-GPG-KEY-CentOS-5

rpm -e –nodeps redhat-release

rpm -e yum-rhn-plugin

rpm -Uvh –force *.rpm

If you receive dependency failures then wget the additional dependencies that are needed

yum upgrade -y

Category: Linux | Comments Off on Linux: Convert Red Hat to Centos – In place upgrade
April 2

Linux: Methods to Identify Your Linux File System Type

Question: How do I identify my file system type? I like to upgrade my current file system to the latest ext4. Before that I would like to know what my current file system type is for various mount points I have on my UNIX system.

Answer: Use any one of the five methods mentioned below to identify your file system type.

Method 1: Use df -T Command

The -T option in the df command displays the file system type.

# df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
/dev/sda1 ext2 /
/dev/sdb1 ext3 /home
/dev/sdc1 ext3 /u01

Method 2: Use Mount Command

Use the mount command as shown below.

# mount | grep "^/dev"
/dev/sda1 on / type ext2 (rw)
/dev/sdb1 on /home type ext3 (rw)
/dev/sdc1 on /u01 type ext3 (rw)

As shown in the above example:

  • /dev/sda1 is ext2 file system type. (mounted as /)
  • /dev/sdb1 is ext3 file system type. (mounted as /home)
  • /dev/sdc1 is ext3 file system type. (mounted as /u01)

Method 3: Use file Command

As root, use the file command as shown below. You need to pass the individual device name to the file command.

# file -sL /dev/sda1
/dev/sda1: Linux rev 1.0 ext2 filesystem data (mounted or unclean) (large files)

# file -sL /dev/sdb1
/dev/sda1: Linux rev 1.0 ext3 filesystem data (needs journal recovery)(large files)

# file -sL /dev/sdc1
/dev/sda1: Linux rev 1.0 ext3 filesystem data (needs journal recovery)(large files)

Note: You should execute the file command as root user. If you execute as non-root user, you’ll still get some output. But, that will not display the file system type as shown below.

$ file -sL /dev/sda1
/dev/sda1: writable, no read permission

Method 4: View the /etc/fstab file

If a particular mount point is configured to be mounted automatically during system startup, you can identify its file system type by looking at the /etc/fstab file.

As shown in the example below, / is ext2, /home is ext3, and /u01 is ext3.

# cat /etc/fstab
LABEL=/r       /        ext2    defaults    1 1
LABEL=/home    /home    ext3    defaults    0 0
LABEL=/u01     /u01     ext3    defaults    0 0

Method 5: Use fsck Command

Execute the fsck command as shown below. This will display the file system type of a given device.

# fsck -N /dev/sda1
fsck 1.39 (29-May-2006)
[/sbin/fsck.ext2 (1) -- /] fsck.ext2 /dev/sda1

# fsck -N /dev/sdb1
fsck 1.39 (29-May-2006)
[/sbin/fsck.ext3 (1) -- /home] fsck.ext3 /dev/sdb1

# fsck -N /dev/sdc1
fsck 1.39 (29-May-2006)
[/sbin/fsck.ext3 (1) -- /u01] fsck.ext3 /dev/sdc1

If you don’t have the root access, but would like to identify your file system type, use /sbin/fsck -N as shown above.

By: Ramesh Natarajan

Category: Linux | Comments Off on Linux: Methods to Identify Your Linux File System Type
April 2

Linux: Resize a linux image file

To resize your Debian IMG file – instructions are for people with linux computers or laptops:

Copy the ‘debian.img’ image file from your Phone’s SD card (in sdcard/debian) to your linux desktop.

Open a terminal on your linux computer and ‘su’ so you are root.

change directory to the desktop in unbuntu’s case it’s here, we do this so we can see whats going on easily:

cd /home/user/Desktop

create an empty image file: (the 3500999999 refers to the size – this one is 3.5 GB, basically take the first 4 digits and thats how many megabytes the image will be)

dd if=/dev/zero of=debian2.img seek=3500999999 bs=1 count=1

Your new image file is called debian2.img

Now do (you are still on your desktop linux machine here):

mkfs.ext2 -F debian2.img

Mount the 2 images (the old one and new empty one)

mkdir debian
mkdir debian2
mount -o loop debian.img debian
mount -o loop debian2.img debian2

Copy the contents of the old image into the new:

cd /home/user/Desktop/debian/

cp -r -f –preserve * /home/user/Desktop/debian2

Unmount files

umount debian
umount debian2

(sometimes this doesn’t work – so simply reboot)

e2fsck -F debian2

Once that’s done

Back to your linux computer desktop:

As root (su):

Delete the 2 folders debian and debian2

rm -r -f debian
rm -r -f debian2

delete your old image:

rm debian.img

rename the new image:

mv debian2.img debian.img

change permissions:

chmod a+x debian.img
chmod 777 debian.img

Then copy the newly created image into your phones /sdcard/debian folder (overwrite the original).

Finally on your phone boot debian shell as normal and at the localhost$ prompt do:

cd /var/lib/dpkg/updates

rm -r -f *

then

dpkg –configure -a (may take a few minutes, ignore the errors)

This gives you a 3.5GB image instead of the 720mb original image.

Category: Linux | Comments Off on Linux: Resize a linux image file