Linux Tip of the Day - converting caps in vi
To convert:
THE CAT SAT ON THE MAT
to
The Cat Sat On The Mat
in vim, add the following to .vimrc:
map #1 :s/\([A-Z]\)\([A-Z][A-Z]*\)/\1\L\2/g
It maps a suitable regular-expression based search and replace to the F1 function key.
Linux Tip of the Day - links that point to nothing
find / -type l -print |perl -nle ‘-e || print’;
This will look for all links that are dead and print it out. It can be piped to a file and unlink it later. It is wise to list the links first and save the output to a file. This is in case if the links are needed by users which remove those files temporary for testing or housekeeping.
Linux Tip of the Day - secure backups over net
Securely backup a partition across a network using dd, gzip and SSH:
1. The partition to be backed up must be unmounted.
2. The following does the trick:
dd if=/dev/partition_to_be_backed_up | gzip | ssh user_name@backup.server dd of=name_of_backup_file.gz
As an example, the following backs up an image of a floppy disk:
dd if=/dev/fd0 | gzip | ssh user_name@backup.server dd of=floppy.img.gz
3. To restore a backed-up partition across a network:
(From the backup server)
dd if=name_of_backup_file.gz | gzip -d | ssh user_name@target.server dd of=/dev/target_partition
Linux Tip of the Day - when did that shell get disconnected
Have you ever come back to work the next day and had your session(s) disconnected, but aren’t sure when it occurred?
I’ve found that logging into a machine with
ssh machinename;date
is pretty useful, as if the machine dies (or the network loses connection overnight), you will immediately know when it happened.
Linux Tip of the Day - a simple native converter
Lot of people use special softs to convert hex numbers to decimal ones. You can easily do it (C style) via printf:
# from hex to dec
$ printf “%d\n” 0×100
256
# from dec to oct
$printf “%o\n” 8
10
Linux Tip of the Day - Solaris changing seasons
During a session, sometimes we have a need to change the system time for our session only. We have used it to simulate time based testing.
export TZ=ESThhEDT
The EST set your time to Eastern Standard Time and EDT is Eastern Daylight Time.
hh is the number of hours you wish to change.
Example: Currently the system date is Tue Jun 19 13:38:03 EDT 2001
and you wish to set it to yesterday at the same time. You would substitute a positive 29 for hh.
Linux Tip of the Day - filenames upper to lower
This script can be used to renames all the file in current directory with UPPERCASE letters to lowercase.
I uses it because some time when I try to upload some files from a Windows system to a unix based web server, the files somehow gets converted to UPPERCASES, which is undesirable.
###########################
for uppercase in `ls`
do
for lowercase in `ls $uppercase|tr [A-Z] [a-z]`
do
mv $lowercase $uppercase 2>/dev/null
done
done
############################
Linux Tip of the Day - full of filesystem inodes
We recently had a problem where a file system had 100% inode usage. Unfortunately there isn’t an easy way to search for directories with a lot of files in them (1 file = 1 inode). And if the files are small, you can’t rely on du to help you out.
Here is a find command that will print all the directories in the current filesystem, with the number of files (inodes) in that directory.
find . -xdev -type d -exec /bin/echo -n {} \; -exec sh -c “ls {} | wc -l” \;
Linux Tip of the Day - listing files by size
If you want to have a listing of the files sorted by size, you can use the following command(s), it will list the files in decrease order. if you need to do the same thing recursively, you could use the second one.
ls -l | grep ^- | sort -nr -k 5 | more
ls -lR | grep ^- | sort -nr -k 5 | more
Linux Tip of the Day - rename a large number of files
This a an oldie but a goodie. There always comes a time when a large number of files need to be renamed.
Here is one quick way to do it:
=================== cut here ===========================
#!/bin/sh
for i in *
do
echo $i
mv $i `basename $i`.bak
done
