Welcome to Cpucraft!

Cpucraft is a personal site of Ruslan Gerasimov.
Ruslan's project about Yoga: www.yogin.vip


On this site Ruslan Gerasimov posts Linux commands, scripts and customizing approaches as well as lists some C/C++ source codes.

How to disable auto mounting of any external drive?

echo "blacklist usb-storage" | sudo tee -a /etc/modprobe.d/blacklist.conf

Enabling it later should just be:

sudo modprobe usb-storage


How to list applications running by user?

wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'


How to filter certain columns, e.g. Name and Age?

Linda:F:Las Vegas, USA:18:telnet
Steve:M:Leipzig, Germany:33:ftp
Henry:M:Milan, Italy:19:sftp
Alice:F:Izmir, Turkey:32:pop3s
Robert:M:Verona, Italy:21:scp
Olga:F:Gorontalo, Indonesia:19:pop3s
Kimberly:F:Lille, France:25:ping
Henry:M:Oslo, Norway:26:ftp
Carol:F:New Delhi, India:23:pop3s
Thomas:M:New Delhi, India:32:http


cut -d: -f1,4 file


awk -F':' '{print $1,$4}' file


sed 's/([^:]*:)[^:].*:([^:]*):.*/12/' < file


while IFS=: read a b b b c; do echo $a $b; done < file


Topcon's driverless agriculture

How to resize bunches of photos from command line, keep old and rename new ones?

for pic in *.jpg
echo "Converting $pic."
convert "$pic" -resize 1152x768 "${pic/.jpg/-1152x768.jpg}"


How to ssh sudo pipe command?

Note: The password, for security reason, should be read in from the standard input only.
Here sudo, being run after ssh,  would never get password input for sudo on the remote server until we use -S option and pipe a password for it as follows:
Note: The password, for security reason, should be read in from the standard input only.

ssh -t www.server.com 'echo your_password | sudo -S ls -l'| grep 'sometext'

On the one hand this is good for the automation with no getting sudo password promts and, to have completely automated code/script you would add sshpass -p password ssh.... However on the server where others can easily read your sudo password provided as open text during the ssh session it's not recommended from the security perspectives. So, to have a sudo with ssh and be safe use ssh -t Nevertheless, with -t it's impossible to pipe ssh "sudo command"| command` for example`ssh -t server "cd path/to/directory && sudo"|grep "text" but it IS possible with ussage of -S and echoing password, e.g. ssh server 'echo password | sudo -S ls -l'| grep 'a'


Customizable and synced keyboard shortcuts in Firefox.

This mozilla support site says

 Note: Keyboard shortcuts can be customized using the Customizable Shortcuts extension.

However, the keyboard shortcuts are not synced to other computers. This seems to be on the TODO list of the extension, but has not been implemented yet.

There could be a workaround with syncing it over the net until better solution is provided.

In Linux the file is stored at:


under your profile folder:


You can sync it every time you run and exit from Firefox. Here is my example script which copies the file from Dropbox folder on the Firefox start and stores the file in Dropbox folder when it exits.

It works just fine by running this script from your Desktop. Double click the script to run Firefox and your Shortcuts Add On is always synchronized

Here is the script, but change you 'profile.default' folder name:

#!/bin/bash exec cp /home/ruslan/Dropbox/store.json /home/ruslan/.mozilla/firefox/apcbgfp7.default/jetpack/customizable-shortcuts@timtaubert.de/simple-storage &

/usr/bin/firefox &

while [ 'pidof firefox' ]



'pidof firefox'


exec cp /home/ruslan/.mozilla/firefox/apcbgfp7.default/jetpack/customizable-shortcuts@timtaubert.de/simple-storage/store.json /home/ruslan/Dropbox


Run Linux from an ISO file on a hard drive, a boot menu option.

  • Place your ISO file to /live :

sudo mkdir /live

sudo cp somelinux.iso /live

 Add new menu entry to the grub.cfg

sudo gedit /etc/grub.d/40_custom

menuentry 'ISO Ubuntu 14.04 2014 Live' --class os --class gnu-linux --class gnu --class os --group group_main {
set isofile="/live/ubuntu-14.04-desktop-amd64.iso"
insmod ext2
insmod loopback
insmod iso9660
loopback loop (hd0,msdos5)$isofile
linux (loop)/casper/vmlinuz.efi file=(loop)/cdrom/preseed/ubuntu.seed noprompt boot=casper persistent iso-scan/filename=/$isofile quiet splash --
initrd (loop)/casper/initrd.lz


1. change in the menu entry above the code name for your partition, holding /live/somelinux.iso, in my case it's hd0,msdos5 because it is on /dev/sda5/

2. change the file name from somelinux.iso to yours, in my case I have: ubuntu-14.04-desktop-amd64.iso

  • update GRUB

 sudo update-grub

  • reboot


Keep on automatical rerunning SSH session when a server kills it.

This will rise ssh connection again and again on the local machine:

sshpass -p "YourPassword" ssh -o StrictHostKeyChecking=no user@server &
while true
wait 'pidof ssh'
sshpass -p "YourPassword" ssh -o StrictHostKeyChecking=no user@server

whenever a server runs :

sudo pkill sshd

the connection will be raised up again.

If you don't have sshpass then install it:

sudo apt-get install sshpass


How to play mp3 file on another computer over ssh?
Note: The password, for security reason, should be read in from the standard input only.

sshpass -p password scp audio.mp3 user@server:~/Downloads && sshpass -p password ssh user@server 'echo y| echo password | sudo -S apt-get install mpg123 && cd Downloads && mpg123 audio.mp3'


Ways of calculating required disk space prior to package download?

echo n | sudo apt-get install $LIST | grep "disk space" | awk '{ print $4, $5 }'

But what if you need it always in kBytes?

LIST="openarena chromium-bsu"
echo n | sudo apt-get install $LIST | grep "disk space" | while IFS=, read a b; do echo $b ; done  | 
sed 's/,//g' |
while IFS=  read a b c; do 
if [ "$b" == "kB" ]; then echo $a $b;
 if [ "$b" == "MB" ]; then echo -n $(($a*1024)); echo " kB" 


How to calculate number of days between two dates?


read line < input;
echo -n $line; echo "No_Of_Days";
sed '1d' input| 
while IFS=,
read a b c d e f;
 let DIFF=(`date +%s -d $d`-`date +%s -d $e`)/86400;
 echo -n $a,$b,$c,$d,$e,$f,
 echo $(($DIFF *-1));

or alternatively

awk -F, -v q='"' '{ c="date -d"q$4q" +%s";c|getline d1;close(c); c="date -d"q$5q" +%s";c|getline d2;close(c); printf "%s,%dn", $0,(d2-d1)/3600/24}' file

How to select all files with log extension and to not contain "error" word in their name?

for f in *.log 
if [ -n "$(echo $f  | grep -v error)" ] ; then file $f ;


In the script above command file is given for example, you can change it to any command you need. The script fits also for files which have spaces in their names.

Website Built with Kopage
← Get yours now