Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
Showing 21-40 of 44 total

Clear a log file

Run at prompt, replacing development.log with the name of the log file

echo -n > development.log

Change keyboard mapping

In order to get greater than and less than signs without using the retarded French keyboard layout for those keys, remap keys using xmodmap. For help and testing xev can show you what is being typed.

Place the following inside ~/.bashrc to have it run whenever you login.

xmodmap -e "keysym a = a A ae AE less less"
xmodmap -e "keysym z = z Z guillemotleft less greater greater"
xmodmap -e "keysym semicolon = period semicolon horizconnector multiply horizconnector multiply"
xmodmap -e "keysym ugrave = percent percent percent percent percent percent"


The order of the letters after the = sign signify the modifiers to the keypress. The first is without modifier (natural key press of 'a'. Second is with Shift. Third and fourth is after a Mode_Switch (in RedHat Linux that is pressing Shift_R + Alt_R simultaneous, in that order) but without modifier after switching modes. And the last two is with Alt_R and Alt_R + Shift_R modifiers.


To see what currently is mapped use
xmodmap -pke | less

Find IPs connected to HTTP (Port 80)

// Find IPs connected to HTTP (Port 80)

netstat -an | grep :80 | awk '{ print $5 }' | awk -F: '{ print $1 }' | sort | uniq -c | sort -n

Fix permissions on a directory

// Fix permissions on a directory

chown -R youruser:youruser /thedirectory
find /thedirectory -type f -exec chmod 0644 {} \;
find /thedirectory -type d -exec chmod 0755 {} \;

Mount MDF Image files

//How to mount MDF images in any given folder

mount imagen.mdf /path/mount_directory -o loop=/dev/loop0


Also here
Mount MDF images in Linux

Create a virtual CD/DVD using an image on Linux

On Linux, if you have an ISO file and need to create a virtual CD/DVD, just run the command below.

dd if=/dev/cdrom of=/directory/filename.iso

mount -o loop /directory/filename.iso /mountpoint/

How to count particular words using perl

When "grep -c" doesn't cut it (counts only 1 occurrence per line).

perl -lne '$c++ while /SEARCH_STRING/g; END { print $c; }'


For example, to count the number of times ABCD appears in mysqldump output:

mysqldump my_db | perl -lne '$c++ while /ABCD/g; END { print $c; }'


Modified version of snippet found in http://www.wellho.net/forum/Perl-Programming/Issue-with-Grep.html

tar and gzip on one line

Bundle my_dir
tar cvf - my_dir | gzip -c > my_dir.tar.gz


Unbundle my_dir
gunzip -c my_dir.tar.gz | tar xvf -

Remove CVS directoires and files

When check out the files, use
cvs export

instead of
cvs checkout

can avoid creating those CVS directories

If files already exist, then in bash, do
find . -name CVS -prune -exec rm -rf {} \;

How to set a static IP in Ubuntu from the shell

Edit /etc/network/interfaces and adjust it to your needs (in this example setup I will use the IP address 192.168.178.50 for eth0):

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
        script grep
        map eth0

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.178.50
        netmask 255.255.255.0
        network 192.168.178.0
        broadcast 192.168.178.255
        gateway 192.168.178.1
        #optional
        #dns-nameserver 102.168.178.1


You can also edit /etc/resolv.conf to configure a dns-server to use:

nameserver 192.168.178.1

Extract all .tar files in a dir

// Extract all tar files in a dir
for i in *.tar; do echo working on $i; tar xvzf $i ; done

Delete all the .jpg files in all directories below the current

// Delete all the .jpg files in all directories below the current
find /PATH/TO/STARTING/DIRECTORY  -type f -name "*.jpg" -delete

Check Disk Usage on Linux

// Check Disk Usage on Linux
du -sh /PATH/TO/DIRECTORY

Make SymLink In Linux

Makes a symbolic link in linux

ln -s /home/dir_to /home/dir_from

//dir_to is the existing directory you want dir_from to point to symbolically

How to extract all the files from an RPM package

rpm2cpio filename | cpio -i --make-directories

how to use shfsmount as a normal user in Debian/Ubuntu

sudo chmod u+s /usr/bin/shfsmount /usr/bin/shfsumount

Bash script to export ssh public key to a remote server

This isn't a brilliant script, but it sure can be a time saver. When I add a public key by hand I end up doing a lot more commands.

#!/bin/bash

## USAGE: add_to_server.sh remote_server

## This script will add your ssh dsa public key to remote_server's authorized_keys list, 
## assuming that everything is in it's default location

set -v                                 # verbose output
username="USERNAME"              # CHANGE ME!!!!
remote_server=$1              # assigns the first commandline argument to $remote_server


## Pipe the public key to ssh, then remotely touch the file to make sure it will be there, and concat to the end of it.
## Might work without the touch?
cat ~/.ssh/id_dsa.pub | ssh ${username}@${remote_server} "touch ~/.ssh/authorized_keys && cat - >> ~/.ssh/authorized_keys"

exit 0

Stop bell/beep in bash

setterm -blength 0


Sets the bell length to zero for all applications

How to set a static IP in Ubuntu from the shell

Edit
/etc/network/interfaces 
and adjust it to your needs (in this example setup I will use the IP address 192.168.0.100):

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
        script grep
        map eth0

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.0.100
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1

get rid of mac's ._ meta files on unix command line

When a mac accesses storage not formatted in it's own HFS format, it stores it's additional metadata about the file in another file named the same but starting with "._" It can be annoying and when you're accessing a remote volume that's source control managed with subversion, they show up your status information. This bash shell script will get remove of all ._metadata files residing below the current working directory.

#!/bin/sh
for i in `find . -regex '.*\._.*'`; do rm $i; echo "removing $i"; done


If you save that as "/home/$USER/bin/cleanup" and do a "chmod 777 /home/$USER/bin/cleanup" it will be available next time you open a terminal by just typing "cleanup".
« Newer Snippets
Older Snippets »
Showing 21-40 of 44 total