Find a text pattern in jar files
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.
1 #!/bin/sh 2 for f in `find . -type f -name '*\.jar'` 3 do 4 unzip -l $f | grep -i $1 && echo "was found in $f" 5 done
Screenshot in wmii
Method 1
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.
1 #!/bin/bash 2 import -window root /tmp/screenshot.png
Method 2
If you want timestamped screenshots then
1 apt-get install scrot 2 mkdir -p ~/screenshots
And create a script with the following content for making the screenshot.
1 #!/bin/bash 2 scrot '%Y-%m-%d-%H-%M-%S_$wx$h_scrot.png' -e 'mv $f ~/screenshots'
Mount a network drive with proper privileges
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.
1 sudo mount -t smbfs -o uid=1000,gid=1000,username=marko //remote_server/work /mnt/net/stage/work
Disable pc speaker beep in Linux
Not really a snippet, still a good fix for a big annoyance. Temporarily disable the speaker by removing the driver for it.
1 sudo rmmod pcspkr
To make the silence more permanent add this line into /etc/modprob.d/blacklist
1 blacklist pcspkr
Colorize grep
Put this export in .bashrc to make grep colorize the text it found.
1 export GREP_OPTIONS='--color=auto'