Forum Settings
Forums
New
Sep 29, 2015 10:34 AM
#1

Offline
Oct 2014
3645
You can share your useful shell scripts here
CnonSep 22, 2019 3:32 AM
Reply Disabled for Non-Club Members
Oct 24, 2015 8:24 AM
#2

Offline
Feb 2011
6
I used this script to convert m4a into mp3
http://pastebin.com/7J4LiuFe
Oct 24, 2015 8:27 AM
#3

Offline
Feb 2011
6
This one I used to resize a lot of pictures in a directory
http://pastebin.com/31VVp6nD
Nov 8, 2015 3:16 AM
#4

Offline
Oct 2014
3645
here's a one liner for bulk renaming it replaces foo with bar
ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv

doesn't work filenames with spaces etc. though.
Since I'm using mate there's no bulk renaming utility.
Sep 5, 2017 9:28 AM
#5

Offline
Sep 2009
928
My one-liner for downloading->watching->removing a single episode/show through torrent, assuming you have the link to magnet/.torrent on your clipboard. Works great if you don't have space on you HDD or just don't want to keep the file(s).

file=$(aria2c `xclip -o` --seed-time 0 -d /tmp | python -c "import re,sys; print(re.findall(r'complete: (/.*)\n',''.join(l for l in sys.stdin))[-1])"); mpv $file && rm -r $file
IDexSep 5, 2017 12:25 PM
Dec 23, 2017 3:01 PM
#6

Offline
Oct 2014
3645
IDex said:
My one-liner for downloading->watching->removing a single episode/show through torrent, assuming you have the link to magnet/.torrent on your clipboard. Works great if you don't have space on you HDD or just don't want to keep the file(s).

file=$(aria2c `xclip -o` --seed-time 0 -d /tmp | python -c "import re,sys; print(re.findall(r'complete: (/.*)\n',''.join(l for l in sys.stdin))[-1])"); mpv $file && rm -r $file

this is really useful, thanks.
Dec 10, 2018 9:31 AM
#7
Offline
Sep 2018
7
My script for downloading anime.
ahmubashshir/d04343a5fc8448074da806e38330bc1e
It lists and downloads anime from dubbedanime.net
Aug 20, 2019 4:37 PM
#8

Offline
Oct 2014
3645
clock skew problems on gentoo are annoying. you can't build anything.
just leaving this here:
$ cd /
$ touch currtime
$ find . -cnewer /currtime -exec touch {} \;
source: http://www.cydeweys.com/blog/2007/08/27/fixing-clock-skew-problems-in-gnulinux/
Aug 23, 2019 4:06 PM
#9

Offline
Sep 2008
96
Finding a way to attach your VM without networking can be annoying. So I compose this short script in order to attach/detach .qcow2 disk images:

// looking for the defined block device name... or "ARE YOU STILL THERE? (Portal reference)
status=$(mount | grep "nbd4p2")

// checking the status by counting the number of characters stored in the variable
if [ ${#status} = 0 ] 
then

// setting up the maximum number of block device...
sudo modprobe nbd max_part=8

// attaching the image as a block device
sudo qemu-nbd --connect=/dev/nbd4 /media/sdc/virt-machine/libelec.qcow2

// in order to prevent too fast command executions... it can be a problem, I've been there ^^"
sleep 0.5

// make a dir for the mount command
mkdir /media/libelec 

// take a half second break... again your shell script will appreciate it
sleep 0.5 

// attach me, please :)
sudo mount /dev/nbd4p2 /media/libelec

// reversing everything, unload stuff
else
sudo umount /media/libelec
rmdir /media/libelec
sudo qemu-nbd --disconnect /dev/nbd4
sudo rmmod nbd
fi


It's been a while since I wrote this and I'm dead tired. There may issues with the comments.
Oct 5, 2019 1:33 PM

Offline
Sep 2008
96
Turn on and off your display outputs via shell script. If I want to watch things on the TV then I will press a CRLT+F12 and the following will run...

// if exists it will store the string for further analysis
dpon=$(xrandr --listactivemonitors | grep "DP1-1")
hdon=$(xrandr --listactivemonitors | grep "HDMI1")

// because I used [b]#[/b] it will count the number of characters
// if it doesn't zero then...
if [ ${#dpon} != 0 ] || [ ${#hdon} != 0 ]
then
// turn off HDMI1 and DP1-1 and switch on DP1-2 in 1920x1080
xrandr --output HDMI1 --off
xrandr --output DP1-1 --off
xrandr --output DP1-2 --mode 1920x1080

else
// otherwise turn on DP1-1 as a primary monitor in the those specified coordinates in pixels
// and put HDMI1 in the left in those coordinates
xrandr --output DP1-1 --auto --pos 0x175 --output HDMI1 --auto --primary --pos 1680x0
xrandr --output DP1-2 --off
fi
Jan 12, 2020 2:54 AM

Offline
Sep 2008
96
Locking the screen and turning off the display(s) by DPMS.

// locking the screen
cinnamon-screensaver-command -l
// turning off screen until mouse or keyboard input 
xset dpms force off
Jan 20, 2020 4:46 AM
Offline
Nov 2014
3
Batch conversion with ffmpeg
for i in *.wav; do ffmpeg -i "$i" "${i%.*}.mp3"; done


Afterwards I used to have bunch of file names ending with "-cr", which I wanted to rename, which I did with this:

rename -n 's/\-cr.mp3/\.mp3/' *.mp3
Dec 7, 2020 9:00 PM

Offline
Sep 2013
36
Cnon said:
here's a one liner for bulk renaming it replaces foo with bar
ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv

doesn't work filenames with spaces etc. though.
Since I'm using mate there's no bulk renaming utility.

ranger has a really nice
:bulkrename
command. Select whatever files you want, run that command, then it dumps you into your editor (neovim for me) where you can make changes very easily, then you just save the file, it shows you what commands it's going to run, and you just save again. (so a quick ZZ twice)
I can't remember what it's depending on for this. Depending on the distro it may or may not pull in the needed thing on its own.
Dec 8, 2020 5:32 AM

Offline
Oct 2014
3645
soundtoxin said:
Cnon said:
here's a one liner for bulk renaming it replaces foo with bar
ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv

doesn't work filenames with spaces etc. though.
Since I'm using mate there's no bulk renaming utility.

ranger has a really nice
:bulkrename
command. Select whatever files you want, run that command, then it dumps you into your editor (neovim for me) where you can make changes very easily, then you just save the file, it shows you what commands it's going to run, and you just save again. (so a quick ZZ twice)
I can't remember what it's depending on for this. Depending on the distro it may or may not pull in the needed thing on its own.

Thanks good to know there are alternative solutions for this.
Reply Disabled for Non-Club Members

More topics from this board

Poll: » Poll: How often do you update your system?

Cnon - Dec 19, 2023

5 by Klefki_of_Awsome »»
Dec 20, 2023 5:12 PM

» What distro are you using? ( 1 2 )

Cnon - Sep 1, 2015

58 by Sasbyek »»
Dec 15, 2023 10:47 AM

Poll: » Your favorite File Manager

Cnon - Mar 28, 2017

7 by Cnon »»
Oct 22, 2023 1:15 PM

» What do you think about trinity desktop

Cnon - Aug 12, 2023

3 by konfou »»
Sep 28, 2023 3:09 AM

Poll: » Text editor of your choice

Cnon - Jun 16, 2020

23 by Sasbyek »»
Sep 26, 2023 5:28 PM
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login