Bulk renaming of files
Rename the files in a directory by replacing a space with an underscore. The rename program comes with most modern Linux distros.
rename 's/\ /_/g' *.*
Rename the files in a directory by replacing a space with an underscore. The rename program comes with most modern Linux distros.
rename 's/\ /_/g' *.*
Put this export in .bashrc to make grep colorize the text it found.
export GREP_OPTIONS='--color=auto'
Not really a snippet, still a good fix for a big annoyance. Temporarily disable the speaker by removing the driver for it.
sudo rmmod pcspkr
To make the silence more permanent add this line into /etc/modprob.d/blacklist
blacklist pcspkr
This is not a snippet either, but I always forget how the local permissions for a Samba mount are given, which is the reason I put it here. Uid is the id of the user you want to mount the drive as, and gid is respectively the group id. Username is the username you want to connect with.
sudo mount -t smbfs -o uid=1000,gid=1000,username=marko //remote_server/work /mnt/net/stage/work
A simple script to create a screenshot in wmii. It probably works in other window managers too. I call it 'scrot'. Put it in the path and run it as you'd run any program in wmii. The "import" program comes with imagemagick.
#!/bin/bash
import -window root /tmp/screenshot.png
If you want timestamped screenshots then
apt-get install scrot
mkdir -p ~/screenshots
And create a script with the following content for making the screenshot.
#!/bin/bash
scrot '%Y-%m-%d-%H-%M-%S_$wx$h_scrot.png' -e 'mv $f ~/screenshots'
Helpful when you need to find a class or package in some jar file recursively below the current directory. Still needs a test to see if the file found was a file or directory. Works case insensitively. Uses the unzip command because of it's performance superiority in comparison to jar.
#!/bin/sh
for f in find . -type f -name '*\.jar'
do
unzip -l $f | grep -i $1 && echo "was found in $f"
done
Reset all rules of iptables. Handy to put in the root's crontab while configuring a remote firewall.
#!/bin/sh
#
# rc.flush-iptables - Resets iptables to default values.
#
# Copyright (C) 2001 Oskar Andreasson <bluefluxATkoffeinDOTnet>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program or from the site that you downloaded it
# from; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Configurations
#
IPTABLES="/sbin/iptables"
#
# reset the default policies in the filter table.
#
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
#
# reset the default policies in the nat table.
#
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
#
# reset the default policies in the mangle table.
#
$IPTABLES -t mangle -P PREROUTING ACCEPT
$IPTABLES -t mangle -P POSTROUTING ACCEPT
$IPTABLES -t mangle -P INPUT ACCEPT
$IPTABLES -t mangle -P OUTPUT ACCEPT
$IPTABLES -t mangle -P FORWARD ACCEPT
#
# flush all the rules in the filter and nat tables.
#
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
#
# erase all chains that's not default in filter and nat table.
#
$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X
The cut program can be really versatile. Give it the character used to separate columns using the -d switch, and the column(s) you want to print using the -f switch. Here we give ' ' as a parameter to the -d switch because spaces indicate the columns here. A single column is given using -fn and multiple columns using -fn,n,n,n,n syntax.
ps axu |grep FitNesse | grep java |grep -v grep | cut -d' ' -f3
# mkdir /mnt/iso
# mount -o loop -t iso9660 file.iso /mnt/iso
In order to forward X11 applications from a remote server into your local X session the server must support tunneling of X11 apps with this property in sshd_config
X11Forwarding yes
Then simply issue the -X parameter for the SSH client.
ssh -X remotehost
Now run an X11 application from the SSH terminal and it's UI will be tunneled to your local X session.
gvim my_script.rb