Saturday 5 June 2010

Miscellaneous useful bash

For my benefit more than anything - things I use over and over again, but do not have the mental capacity to remember

# number of files in current directory
 ls -1R | grep .*.<file extension> | wc -l  


# check if you have a program installed
 aptitude show <name of program> | grep State  


# only list the (sub-)directories in your current directory
 ls -l | grep ^d  


# remove backup files
 find ./ -name '*~' | xargs rm  


# use zenity get the directory where the file you want is
 zenity --info --title="My Program" --text="Select  
which directory contains the file(s) you want"
export target_dir=`zenity --file-selection --directory`


# list all txt files in this directory
 x=$( ls $target_dir | grep .*.txt |sort|zenity --list --title="Select" --column="coordinate file" )  


# get this directory
 export raw_dir=`zenity --file-selection --directory`  


# removes .txt (for example, for later use as start of filename)
 str="$x"  
Var1=`echo $str | awk -F\. '{print $1}'`


# gets the rest of the file name
 str="$Var1"  
Var2=`echo $str | awk -F\- '{print $2}'`


# turn string into (indexable) array
 e=$(echo $mystring | sed 's/\(.\)/\1 /g')  
b=($e)


# get max and min dimensions of an image
 min=`convert image1.tiff -format "%[fx: min(w,h)]" info:`  
max=`convert image1.tiff -format "%[fx: max(w,h)]" info:`


# take away 1 from both
 min=$((min-1))   
max=$((max-1))

No comments: