Register now and start sharing your code snippets.
-->

Find a text pattern in jar files

Shell Script (Bash) posted about 1 year ago by marko

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

Tagged jar, find, search, recursive, linux, unzip

Screenshot in wmii

Shell Script (Bash) posted about 1 year ago by marko

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'

Tagged wmii, screenshot, linux, imagemagick

Mount a network drive with proper privileges

Shell Script (Bash) posted about 1 year ago by marko

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

Tagged smbfs, samba, mount, smbmount, permissions, filesystem, network drive, linux

Disable pc speaker beep in Linux

Shell Script (Bash) posted about 1 year ago by marko

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

Tagged pc speaker, linux, quiet, disable, audio, beep

Colorize grep

Shell Script (Bash) posted about 1 year ago by marko

Put this export in .bashrc to make grep colorize the text it found.

   1  export GREP_OPTIONS='--color=auto'

Tagged grep, bash, color, linux