my own bash tricks

two array print alternatively a and b

  a=(1 2 3) ; b=(a b c ) ;  for ((i = 0; i <=${#a[@]} ; i++ )) ; do printf "%s %s " "${a[i]}" "${b[i]}" ; done

Create menu with kdialog using 2 array
this is not good for kdialog expecially if you have special characters with menus

NOTE
kdialog –menu “title” MENU-OPTION-1 MENU-TAG-1 MENU-OPTION-2 MENU-TAG-2

– means end of options and this is essential to avoid error due for example from

-ab 128k

example file to read $HOME/FFmpeg_profiles.lst

mpeg  -vcodec mpeg2 stuff -ab 1000k
avi  -vcodec avi stuff -ab 1000k
mp3 -acodec mp3 stuff -ab 128k

script i did

function_load_profiles(){
k=0
while read line; do

nameprofile[$k]="$(echo "$line" | awk '{print $1}')"
ffmpegoptionprofile[$k]="$(echo "$line" | awk '{ for(b=2; b&lt;=NF; b++) {printf("%s ", $b)} } ' )"

k=$(( $k+1 ))
done &lt; "$HOME/FFmpeg_profiles.lst"

}

function_load_profiles

ARGS="--menu \"choose your profile\" --"
for ((i=0; i&lt;${#nameprofile[@]}; i++)); do
ARGS="$ARGS \"${ffmpegoptionprofile[$i]}\" \"${nameprofile[$i]}\""
done

SELECTED_OPTIONS=$(echo $ARGS | xargs kdialog)
echo $SELECTED_OPTIONS

replace a word without sed

 a="hi bastards"  ; echo ${a/hi/fuck}

compress folders wihtout .svn stuff

  for folder in */ ; do zip -r ${folder%/}.zip "$folder" -x "*.git*" -x "*.svn*" -x "*~"  ; done

list some files kind with find xD

  ind  /etc/apt/sources.list.d/ -path *.save

list files ignoring a *.svn folder

list files less some kind

  find . -path '*/.svn' -prune -o -type f -print 

Find *.txt file but ignore hidden .txt file

  find . -type f \( -iname "*.txt" ! -iname ".*" \) 

check which folder is the biggest

 du -m --max-depth=1 --exclude=home --exclude=archivio --exclude=proc 2>/dev/null | sort -n 

run desktop console and execute NOT TESTED

xdotool search –name “Desktop Shell Scripting Console – Plasma Desktop Shell” windowactivate key ctrl+e key ctrl+w

find what is changed last minute

find . -mmin -1 

see picture , video and pdf wihtout X server , YOU MUST BE On video groups , sudo adduser $USER video , and you must be on terminal login , i mean in a session without X server , ctrl alt f1 , to go back crtl alt f7

fbi /home/stuff/picture.jpeg 

fbgs /home/stuff/document.pdf 

cvlc /home/stuff/movie.avi 

bash name renaming folder  extension etc 

#get only the name with extension   
line=/usr/bin/stuff.ugly ;name="${line##*/}"  ; echo $name 

#get the path only
line=/usr/bin/stuff.ugly ;name="${line%/*}"  ; echo $name

#get the path with the name without extension
line=/usr/bin/stuff.ugly ;name=${line%%.*}  ; echo $name 

#get only the name without container forlder and without extension 
 line=/usr/bin/stuff.ugly ;name="${line##*/}" ; name=${name%%.*}  ; echo $name

#simulate the typing of alt f2

xdotool key alt+F2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.