Finding the biggest files

A common problem with computers is when you have a number of large files (such as audio/video clips) that you may want to get rid of. You can find the biggest files in the current directory with:

ls -lSrh

The «r» causes the large files to be listed at the end and the «h» gives human readable output (MB and such). You could also search for the biggest MP3/MPEGs:

ls -lSrh *.mp*

You can also look for the largest directories with:

du -kx | egrep -v "./.+/" | sort -n

Replacing same text in multiple files

If you have text you want to replace in multiple locations, there are several ways to do this. To replace the text Windows with Linux in all files in current directory called test[something] you can run this:

perl -i -pe 's/Windows/Linux/;' test*

To replace the text Windows with Linux in all text files in current directory and down you can run this:

find . -name '*.txt' -print | xargs perl -pi -e's/Windows/Linux/ig' *.txt

Or if you prefer this will also work, but only on regular files:

find -type f -name '*.txt' -print0 | xargs --null perl -pi -e 's/Windows/Linux/'

Recover root password

Step 1: For Redhat based distros:

Boot from your first install CD and as the very first screen comes up hit F2 and type:

rescue ( For RedHat «linux rescue» ) and the computer will boot in rescue mode.

It will show a few alternatives, select : ¨mount the existing partitions¨ and go to the shell/console prompt.

( Booting Mandrake in «failsafe» from the Lilo menu does the same )

Step 1: For SUSE:

Boot from your first install CD and press F1 at the first screen, then choose «Rescue System» from the menu and at the prompt type «root» ( you do not need a password )

Step 1: For other distro’s

Boot from the first install CD ( or any Live CD like Knoppix ) and at the bootprompt type:

linux single

(For Knoppix: knoppix single )

Alternative for step 1

Sure with most Live and Rescue CDs you can also just boot in the live version, mount the partition and, as root, make changes to the needed files

Step 2

# cd /etc

( if you boot from knoppix first cd to the partition your lost-password-distro is on )

We need to change two files; ¨passwd¨ and ¨shadow¨:

# vi passwd

< i > ( puts vi in insertmode )

This is the first line:

root:x:0:0:root:/root:/bin/bash

Make it:

root::0:0:root:/root:/bin/bash

So just get rid of the ¨x¨ and leave the ¨:¨ ( colons )

Save the file:

Press Esc,

write –> :x,

Press enter

Second file to be changed:

# vi shadow

< i > ( insert mode )

The first line is a long scrambled line of characters, just make it:

root:::: ( four : )

Press Esc

Write –> 😡

Press enter

Now you can reboot your computer. Log in as normal user, open a console and type:

$ su

# passwd

Now set the new root password !

Log out as root:

Ctrl+d

How to mount ext2fs from FreeBSD

To mount ext2fs filesystems under FreeBSD, you first have to build a new kernel with ext2fs support. Put the line

options “EXT2FS”

in your kernel configuration file for the new kernel and compile.
Read the FreeBSD handbook to learn how to do that.

or

Do the following steps to enable ext2fs support in the kernel:

# cd /usr/src/sys/modules/ext2fs
# make
# make install

You can use ‘kldload‘ to load the ext2fs module in to the kernel.

# kldload ext2fs
Then you will be able to mount your linux partitions by giving a command like:

# mount -t ext2fs /dev/ad1s1 /mnt

to unload module use

# kldunload ext2fs

To load the module automatically on system startup

add the following line in to /boot/loader.conf

ext2fs_load=”YES”

Access Your MySQL Server Remotely Over SSH

So you’ve got MySQL on your web server, but it’s only opened to local ports by default for security reasons. If you want to access your database from a client tool like the MySQL Query Browser, normally you’d have to open up access from your local IP address… but that’s not nearly as secure.

So instead, we’ll just use port-forwarding through an SSH tunnel, so your MySQL client thinks it’s connecting to your localhost machine, but it’s really connecting to the other server through the tunnel.

If you are using the command line ssh, the command would look like this. (You can do the same thing graphically in Putty or SecureCRT options if you need to)

ssh -L 3306:localhost:3306 geek@webserver.com

The syntax is ssh -L <localport>hostname<remoteport> <username>@<servername>. We’re using localhost as the hostname because we are directly accessing the remote mysql server through ssh. You could also use this technique to port-forward through one ssh server to another server.

If you already have mysql running on your local machine then you can use a different local port for the port-forwarding, and just set your client tools to access MySQL on a different port.

Once you’ve got the ssh tunnel going, you can open up MySQL Query Browser and enter in the details for your remote server, using localhost as the server host, and adjust the port to whatever you used.