April 12

Linux: SCP tricks

Quite a handy thing about scp is that it supports asterisks. You can copy all files in a remote directory in a way like this:

scp yourusername@yourserver:/home/yourusername/* .

And you can also just copy a whole directory by specifying the -r (recursive) option:

scp -r yourusername@yourserver:/home/yourusername/ .

Both of these also work when copying to a (remote) server or copying between a (remote) server and another (remote) server.

You can also limit the bandwidth scp may use when copying. This is very useful if you’re wanting to copy a huge amount of data without suffering from slow internet for a long time. Limiting bandwidth is done this way:

scp -l bandwidthlimit yourusername@yourserver:/home/yourusername/* .

The bandwidth is specified in Kbit/sec. What does this mean? Eight bits is one byte. If you want to copy no faster than 10 Kbyte/sec, set the limit to 80. If you want to copy no faster than 80 Kbyte/sec, set the limit to 640. Get it? You should set the limit to eight times the maximum Kbyte/sec you want it to be. I’d recommend to set the -l option with all scp’ing you do on a connection that other people need to use, too. A big amount of copying can virtually block a whole 10 Mbit network if you’re using hubs.

By: rechosen

Category: Linux | Comments Off on Linux: SCP tricks
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