You are not logged in.

#1151 2010-07-07 02:51:38

evil
Member
From: Indianapolis, IN
Registered: 2010-03-06
Posts: 41
Website

Re: Post your handy self made command line utilities

This is more of an alias, but one I consider very useful especially when requiring help from the IRC channels. Check it.

alias xp='curlpaste -f $1 | xclip -selection c'

so xp [FILENAME] will paste a file to a paste bin then copy the url of it to your clipboard

Last edited by evil (2010-07-07 02:51:53)


Site | Blog | Freenode Nick: i686

Offline

#1152 2010-07-07 03:45:02

egan
Member
From: Mountain View, CA
Registered: 2009-08-17
Posts: 273

Re: Post your handy self made command line utilities

evil wrote:

This is more of an alias, but one I consider very useful especially when requiring help from the IRC channels. Check it.

alias xp='curlpaste -f $1 | xclip -selection c'

so xp [FILENAME] will paste a file to a paste bin then copy the url of it to your clipboard

I have a similar alias. Do you know of a way to pipe into xclip concurrently with outputting to stdout (the terminal)?

Offline

#1153 2010-07-07 07:56:24

TaylanUB
Member
Registered: 2009-09-16
Posts: 150

Re: Post your handy self made command line utilities

xp ()
{
    uri=$(curlpaste -f "$1")
    echo "$uri"
    echo "$uri" | xsel -bi # Or xclip -sel c
}

``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein

Offline

#1154 2010-07-07 13:39:04

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

egan wrote:
evil wrote:

This is more of an alias, but one I consider very useful especially when requiring help from the IRC channels. Check it.

alias xp='curlpaste -f $1 | xclip -selection c'

so xp [FILENAME] will paste a file to a paste bin then copy the url of it to your clipboard

I have a similar alias. Do you know of a way to pipe into xclip concurrently with outputting to stdout (the terminal)?

you could also do this with pee from moreutils

echo foo | pee 'xclip -whatever' cat

pacman -S moreutils; man pee for more

Offline

#1155 2010-07-07 13:45:00

archman-cro
Member
From: Croatia
Registered: 2010-04-04
Posts: 943
Website

Re: Post your handy self made command line utilities

I'm testing 'pacman -Sy && pacman -Qu' atm, as I'll use it in conky to view all the available updates. Still no updates for now, so I'm waiting. big_smile

Offline

#1156 2010-07-07 17:01:47

egan
Member
From: Mountain View, CA
Registered: 2009-08-17
Posts: 273

Re: Post your handy self made command line utilities

brisbin33 wrote:
egan wrote:
evil wrote:

This is more of an alias, but one I consider very useful especially when requiring help from the IRC channels. Check it.

alias xp='curlpaste -f $1 | xclip -selection c'

so xp [FILENAME] will paste a file to a paste bin then copy the url of it to your clipboard

I have a similar alias. Do you know of a way to pipe into xclip concurrently with outputting to stdout (the terminal)?

you could also do this with pee from moreutils

echo foo | pee 'xclip -whatever' cat

pacman -S moreutils; man pee for more

Moreutils is a great suite; I use sponge a lot. I have never used pee before, and now that I try it isn't working as expected. It coughs on arguments to commands within the pipe, as for some reason sh is trying to interpret them.

e.g.

 | pee 'xclip -selection c' cat

Produces the error: "sh: Invalid argument -s". I am using bash.

Trying to do a more bashy syntax also has the the same problems:

 | tee >(xclip -selection c)

Produces the error: "tee: invalid option 's'". This is really annoying me.

If I avoid any complex commands in the pipes or the file substitution, it works fine, except for the fact that the entry in xclip has a trailing newline of which I cannot rid it.

Offline

#1157 2010-07-07 17:29:50

hwkiller
Member
Registered: 2009-07-21
Posts: 56

Re: Post your handy self made command line utilities

To see if I could make a "Pacman Updating for dummies" script, I did the following:

#!/bin/sh

update () {
clear
echo "Select which update you want to start."
PS3="Update Option: "
select opt in "Standard" "With AUR (Requires yaourt)" "ABS (Requires ABS)" "Exit"; do
    if [ "$opt" = "Standard" ]; then
        echo "Standard update starting..."
        sudo pacman -Syu
        break
    elif [ "$opt" = "With AUR (Requires yaourt)" ]; then
        echo "AUR + Standard update starting..."
        yaourt -Syu --aur
        break
    elif [ "$opt" = "ABS (Requires ABS)" ]; then
        echo "Syncing ABS"
        sleep 5
        sudo abs
        break
    elif [ "$opt" = "Exit" ]; then
        echo "Exiting..."
        exit
    fi
done
exit
}
clear
PS3="What would you like to do? [1-6]
"
select opt1 in "Install" "Remove" "Update" "Search" "Search & Install (Requires Yaourt)" "Exit"; do
    if [ "$opt1" = "Install" ]; then
        echo "What would you like to install?"
        read INSTALL
        sudo pacman -S "$INSTALL"
        exit
    elif [ "$opt1" = "Remove" ]; then
        echo "What would you like to remove?"
        read REMOVE
        sudo pacman -Rns "$REMOVE"
        exit
    elif [ "$opt1" = "Update" ]; then
        update
        exit
    elif [ "$opt1" = "Search" ]; then
        echo "What would you like to search for?"
        read SEARCH
        sudo pacman -Ss "$SEARCH"
        exit
    elif [ "$opt1" = "Search & Install (Requires Yaourt)" ]; then
        echo "What would you like to install?"
        read INSTALL2
        yaourt "$INSTALL2"
        exit
    elif [ "$opt1" = "Exit" ]; then
        echo "Exiting..."
        exit
    fi
done

Pretty handy, if (for instance), I were to put arch linux on the stereotypical "parents'" computer.

Edit: As I said before, I'm an amateur.  I have a question for those more experienced.  Is there a way to make it so that executing the script through gui or .desktop will pop up the terminal and begin the script?  So lets say I have a .desktop file named "System Utilities".  Is there a way to make it so that, when I click "System Utilities", the terminal will pop up with the above script already loaded?

Last edited by hwkiller (2010-07-07 19:26:55)

Offline

#1158 2010-07-08 18:46:34

AuC
Member
From: Utrecht, The Netherlands
Registered: 2010-07-04
Posts: 3

Re: Post your handy self made command line utilities

I've created two simple bash scripts I thought would be handy. The first one is a simple script I made because I'm lazy. It'll fetch a mirrorlist with the 10 latest mirrors using reflector and then uses pacman to search for updates. It's mainly written to practice scripting a bit.

#!/bin/bash
PACMAN=/usr/bin/pacman-color

if [ "$(id -u)" != "0" ]; then
    echo -e "\e[31;1m>>\e[0m This script must be executed as root."
    exit 1
fi

echo -e "\e[34;1m>>\e[0m Updating Pacman Mirrorlist"
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
reflector -l 10 > /etc/pacman.d/mirrorlist

echo -e "\e[34;1m>>\e[0m Searching For Updates"
${PACMAN} -Syyu

echo -e "\e[32;1mDone...\e[0m"

exit 0

My second one may be a bit more usefull. It creates a backup of the users home directory and allows for excluding of files and directories. There is probably a better way to do this and the code is very messy!

#!/bin/bash
#
# Very simple backup script 
#
EXCLUDE=(backups Downloads .*)    # Directories and files that should not be backed up
BACKUP_FILENAME=backups/Backup  # Name of the backup file. Wil result in [NAME]-[DATE].tar.gz

#
# Some colors used in the script
#
LOGI="\e[1;34m>>\e[0m"
LOGE="\e[1;31m!!\e[0m"
LOGE2="\e[1;31m::\e[0m"

echo -e "${LOGI} Creating backup of ${HOME}"
echo -e "${LOGI} Excluding:"

# Show the user what files are excluded and add them to 'exclude.txt'
# which is used by tar to exclude the files.
EXCLUDECOUNT=${#EXCLUDE[@]}
for((i=0;i<$EXCLUDECOUNT;i++)); 
do
        # Exclude some included excludes!
    if [ "${EXCLUDE[${i}]}" != "." -a "${EXCLUDE[${i}]}" != ".." ]; then
        echo -en "${EXCLUDE[${i}]} "
        echo ${EXCLUDE[${i}]} >> exclude.txt
    fi
done
echo "exclude.txt" >> exclude.txt    # also exclude the exclude file! ;-)

# Check if the file exists already, if it does add a number
# to the end
DATE_NOW=$(date +%Y%m%d)
FILENAME="${BACKUP_FILENAME}-${DATE_NOW}.tar.gz"
FILENO=1

while [ -f $FILENAME ];
do
    FILENAME="${BACKUP_FILENAME}-${DATE_NOW}-${FILENO}.tar.gz"
    FILENO=$[FILENO + 1]
done 

echo -e "\n${LOGI} Creating Archive"
tar -czf ${HOME}/${FILENAME} ~/ --exclude-from=exclude.txt > /dev/null 2>&1
TAR_RETURN=$?

rm exclude.txt # We don't need the exclude file anymore.

MD5SUM=$(md5sum ${FILENAME})
if [ "${TAR_RETURN}" -ne "0" -a "${TAR_RETURN}" -ne "1" ]; then
    echo -e "${LOGE} Oops! Something went wrong. ${LOGE}"
    echo -e "${LOGE2} Error: ${TAR_RETURN}"
    exit 1;
fi


echo -e "${LOGI} All Done! Files stored in ${FILENAME} (${MD5SUM:0:32})"

exit 0

I'm quiet proud of the last one. tongue

Offline

#1159 2010-07-08 21:19:03

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Post your handy self made command line utilities

egan wrote:
brisbin33 wrote:
egan wrote:

I have a similar alias. Do you know of a way to pipe into xclip concurrently with outputting to stdout (the terminal)?

you could also do this with pee from moreutils

echo foo | pee 'xclip -whatever' cat

pacman -S moreutils; man pee for more

Moreutils is a great suite; I use sponge a lot. I have never used pee before, and now that I try it isn't working as expected. It coughs on arguments to commands within the pipe, as for some reason sh is trying to interpret them.

e.g.

 | pee 'xclip -selection c' cat

Produces the error: "sh: Invalid argument -s". I am using bash.

Trying to do a more bashy syntax also has the the same problems:

 | tee >(xclip -selection c)

Produces the error: "tee: invalid option 's'". This is really annoying me.

If I avoid any complex commands in the pipes or the file substitution, it works fine, except for the fact that the entry in xclip has a trailing newline of which I cannot rid it.

Looks like a useful suite, I've just installed it, thanks.
However inititally I have an issue with ifdata.

$ifdata -pN wlan0
192.168.1.0

From ifconfig:

wlan0     Link encap:Ethernet  HWaddr 00:22:43:15:80:C9  
          inet addr:192.168.1.78  Bcast:192.168.1.255  Mask:255.255.255.0

Anyone else who has it installed able to try it?


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#1160 2010-07-09 09:23:59

TaylanUB
Member
Registered: 2009-09-16
Posts: 150

Re: Post your handy self made command line utilities

egan wrote:

Moreutils is a great suite; I use sponge a lot. I have never used pee before, and now that I try it isn't working as expected. It coughs on arguments to commands within the pipe, as for some reason sh is trying to interpret them.

e.g.

 | pee 'xclip -selection c' cat

Produces the error: "sh: Invalid argument -s". I am using bash.

Trying to do a more bashy syntax also has the the same problems:

 | tee >(xclip -selection c)

Produces the error: "tee: invalid option 's'". This is really annoying me.

`echo foo | pee 'xclip -sel c' cat` works fine in both bash and dash for me.
`echo foo | tee >(xclip -sel c)` works fine in bash for me.

Could there be a sneaky syntax error in your code, outside the snippets you gave?

If I avoid any complex commands in the pipes or the file substitution, it works fine, except for the fact that the entry in xclip has a trailing newline of which I cannot rid it.

You can use `tr -d \\n`, `sed s/\\n//`, or `head -c -1` during the pipeline.

Also the trailing newline is always stripped when using $(). Let me re-recommend:

xp () { local uri="$(curlpaste -f "$1")"; echo "$uri"; echo -n "$uri" | xsel -bi; } # or printf for echo -n

(Hadn't used 'local' the last time. Also, that's dash syntax, meaning the double quotes around $() are necessary. (Will of course work with bash too.))


``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein

Offline

#1161 2010-07-09 21:31:14

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Post your handy self made command line utilities

i just threw this together.

it uses esniper to view my ebay auctions,

esniper -i -n ~/myebay > .esniper.tmp


for i in $(seq  `cat ~/myebay | wc -l`) ; do 

echo "--------------------------------------"

grep -i 'Auction' .esniper.tmp | head -n $i | tail -n 1 
grep -i 'Currently' .esniper.tmp | head -n $i | tail -n 1 
grep -i 'High' .esniper.tmp | head -n $i | tail -n 1 
grep -i "Time remaining"  .esniper.tmp | head -n $i | tail -n 1 
done
echo "--------------------------------------"

make a file called "myebay" in your home folder, and fill it up like this:


itemnumber 0 
itemnumber
itemnumber

and it gives you output like this:

--------------------------------------
Auction ITEMNUMBER1: Title
Currently: CURRENTPRICE  (your maximum bid: 0)
High bidder: CURRENT HIGHEST BIDDER
Time remaining: 7 days 20 hours 40 mins (679200 seconds)
--------------------------------------
Auction ITEMNUMBER2 : Title
Currently: CURRENTPRICE  (your maximum bid: 0)
High bidder: CURRENT HIGHEST BIDDER
Time remaining: 7 days 20 hours 40 mins (679200 seconds)
--------------------------------------

i have only tried it with 7 items in a list, but it seems to work well.


edit: you will also need to have you .esniper file set so that i can access your ebay account.

eg:

username = user
password = password
seconds = 5
quantity = 1
logdir = /home/user/esniperlogs
batch = false
bid = yes
debug = enabled
reduce = y

Last edited by markp1989 (2010-07-09 21:42:27)


Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD

Offline

#1162 2010-07-09 21:32:08

evil
Member
From: Indianapolis, IN
Registered: 2010-03-06
Posts: 41
Website

Re: Post your handy self made command line utilities

Here is a new bashrc function I literally just wrote because I extracted a pdf file (that when downloaded, HAD spaces in the damn filename). So, therefore I had 20 jpgs with spaces and 3-4 html files with spaces in the names.

unspacer() #remove spaces from files in current dir
{          #replaces spaces with underscores
 for i in *
  do
   [ ! "$i" == "$(echo $i | tr '\ ' '_')" && mv ./"$i" ./$(echo $i | tr '\ ' '_')
  done
}

EDIT: Added check to make sure it only renames if spaces are replaced

Last edited by evil (2010-07-09 21:38:36)


Site | Blog | Freenode Nick: i686

Offline

#1163 2010-07-09 21:35:47

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

evil wrote:

Here is a new bashrc function I literally just wrote because I extracted a pdf file (that when downloaded, HAD spaces in the damn filename). So, therefore I had 20 jpgs with spaces and 3-4 html files with spaces in the names.

unspacer() #remove spaces from files in current dir
{          #replaces spaces with underscores
 for i in *
  do
   mv ./"$i" ./$(echo $i | tr '\ ' '_')
  done
}
#!/bin/bash
#
# pbrisbin 2009
#
# http://pbrisbin.com:8080/bin/renamer
#
# take a retardedly named file or directory and rename it
# sanely
#
# adjust translate() as needed
#
###

message() { echo 'usage: renamer (--fake) <target> ...'; exit 1; }

# could always use more shit here...
translate() {
  tr -d '\n' | tr -d '\t' | tr -d \' | tr -d \" |\
    sed -r -e 's/.*/\L&/g' \
           -e 's/[ -]/_/g' \
           -e 's/_+/_/g'   \
           -e 's/^_|_$//g'
}

rfile() {
  local dir old new

  dir="$(dirname "$1")"
  old="$(basename "$1")"
  new="$(echo $old | translate)"

  if [[ "$old" != "$new" ]]; then
    if $fake; then
      echo "$dir/$old --> $dir/$new"
    else
      mv -iv "$dir/$old" "$dir/$new"
    fi
  fi
}

rdir() {
  local dir

  while IFS='' read -d '' -r dir; do
    rfile "$dir"
  done < <(find "$1" -depth -print0)
}

[[ -z "$*" ]] && message

# allow a pretend run
if [[ "$1" = '--fake' ]]; then
  fake=true
  shift
else
  fake=false
fi

# do it to it
for arg in "$@"; do
  if [[ -d "$arg" ]]; then
    rdir "$arg"
  elif [[ -e "$arg" ]]; then
    rfile "$arg"
  else
    message
  fi
done

works recursively, files/dirs, removes anything odd via translate() which can be tweaked fairly easily, also has a --fake flag.

Offline

#1164 2010-07-09 21:40:57

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

Or for something more generalized, use perl-rename from the AUR.

Offline

#1165 2010-07-10 14:32:44

TaylanUB
Member
Registered: 2009-09-16
Posts: 150

Re: Post your handy self made command line utilities

vidir from moreutils FTW.
It makes those mass-moving/renaming utilities (mmv, zmv) look funny.

Though i just realized you can't copy with it (while with mmv you apparently can). I'll recommend that...


``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein

Offline

#1166 2010-07-13 18:50:25

Rumcajs
Member
Registered: 2009-09-25
Posts: 37

Re: Post your handy self made command line utilities

This is my little one : dirsize

#!/bin/sh

deep=0
sizeoutput=h
dir=.

while [ $# -gt 0 ]; do
  case "$1" in
    --help)
      echo "Usage : dirsize [OPTION] [DIRECTORY]"
      echo "Print size sorted list of directories (the current directory by default)"
      echo
      echo "Mandatory arguments to long options are mandatory for short options too."
      echo
      echo "-d, --deep             include subdirectories"
      echo "-b, --byte             print size in byte"
      echo "-k, --kilobyte         print size in kilobyte"
      echo "-m, --megabyte         print size in megabyte"
      echo "-h, --human-readable   print size in human readable format (e.g., 1K 234M 2G)"
      echo
      echo "Examples :"
      echo
      echo "  dirsize ~"
      echo "    show size sorted directory list of you home directory"
      echo
      echo "  dirsize --deep ~"
      echo "    same as above but including subdirectories"
      echo
      exit
    ;;
    -d|--deep)
      deep=1
    ;;
    -k|--kilobyte)
      sizeoutput=k
    ;;
    -m|--megabyte)
      sizeoutput=m
    ;;
    -h|--human-readable)
      sizeoutput=h
    ;;
   -db|-dk|-dm)
      deep=1
      sizeoutput=${1:2:1}
    ;;
    * )
      dir=$1
    ;;
  esac
  shift
done

if [ "$deep" == "1" ]; then
  find "$dir" -maxdepth 1 -type d -print0 | xargs -0 du -$sizeoutput | sort -h
else
  find "$dir" -maxdepth 1 -type d -print0 | xargs -0 du -d 1 -$sizeoutput | sort -h
fi

if you don't have read access on some dirs then run it as root (sudo dirsize)

Enjoy and hf

Last edited by Rumcajs (2010-12-01 23:33:30)

Offline

#1167 2010-07-13 18:52:05

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Why not just `du`?

Offline

#1168 2010-07-13 19:02:32

Rumcajs
Member
Registered: 2009-09-25
Posts: 37

Re: Post your handy self made command line utilities

Daenyth wrote:

Why not just `du`?

try du and try dirsize in your home directory thats why.

Offline

#1169 2010-07-13 19:03:39

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

I think if you google "dirsize" there's much more robust solutions. I just prefer ncdu anyway

Offline

#1170 2010-07-13 19:04:40

Rumcajs
Member
Registered: 2009-09-25
Posts: 37

Re: Post your handy self made command line utilities

Daenyth wrote:

I think if you google "dirsize" there's much more robust solutions. I just prefer ncdu anyway

whatever

Offline

#1171 2010-07-13 20:55:55

evil
Member
From: Indianapolis, IN
Registered: 2010-03-06
Posts: 41
Website

Re: Post your handy self made command line utilities

Here is a oneliner bash rc function I put together pretty quick

feh-chooser()
 {
        zenity --file-selection | xargs feh --bg-scale
 }

I had to make this so I could place an option in the awesome right-click menu via rc.lua to change the wallpaper.


Site | Blog | Freenode Nick: i686

Offline

#1172 2010-07-14 07:19:59

0mark
Member
From: earth
Registered: 2010-06-09
Posts: 162
Website

Re: Post your handy self made command line utilities

I sort my Music like this:
musik/Genre/Artist[/Album]

But often i have a List of new Music that is just:
new/Artist[/Album]

This script looks for every Artist directory in new if it is allready sorted in one Genre directory in music, and if so moves everything inside to that Genre. If not, the unknown Artist moved somewhere else.

Well, the script actually dont move anything, it just prints out a list of shell commands, so the result could be checked and piped to sh when correct. Hey, its just for home use wink

#!/usr/bin/perl

use strict;

my $from=shift();
my $to=shift();
my $nojustajokethisistherealto=shift();

sub dir {
  my $path=shift();
  my @dir=shift();
  opendir(DIR, $path) || die "error: path $path";
  my @dir = readdir(DIR);
  closedir(DIR);
  splice(@dir,0,2);
  return @dir;
}

my %genres;
foreach(dir($to)) {
  $genres{$_}=[dir("$to/$_")];
}
my @unknownartists=dir($from);

foreach my $genre(keys(%genres)) {
  foreach my $artist(@{$genres{$genre}}) {
    foreach my $unknownartist(@unknownartists) {
      if (lc($unknownartist) eq lc($artist)) {
        if ($nojustajokethisistherealto ne "") {
          if (not -d "$nojustajokethisistherealto/$genre") {
            mkdir("$nojustajokethisistherealto/$genre");
          }
          print "mv \"$from/$unknownartist\" \"$nojustajokethisistherealto/$genre/$artist\""."\n";

        } else {
          print "mv \"$from/$unknownartist\" \"$to/$genre/$artist\""."\n";
        }
      }
    }
  }
}

Ceterum autem censeo Systemdinem esse delendam

Offline

#1173 2010-07-14 12:58:17

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Variable names sad

Offline

#1174 2010-07-18 19:16:12

TaylanUB
Member
Registered: 2009-09-16
Posts: 150

Re: Post your handy self made command line utilities

#!/bin/bash
#
# Soft Reboot
# Works with Arch Linux default initscripts.
# Needs its own runlevel.
#

/sbin/reboot ()
{
    /etc/rc.sysinit
    init 3
}

. /etc/rc.shutdown

EDIT: Must be put in inittab, for example into runlevel 7. Then `init 7` will do it.

Last edited by TaylanUB (2010-07-22 12:10:19)


``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein

Offline

#1175 2010-07-18 21:22:45

TaylanUB
Member
Registered: 2009-09-16
Posts: 150

Re: Post your handy self made command line utilities

# POSIX shell function to print length of media files, using MPlayer.
# Depends on GNU coreutils's `date` (or one with similar functionality).
# Wraps after 23:59:59; don't use on files that might run for longer than a day!
length ()
{
    local file
    for file
    do
        mplayer -frames 0 -identify "$file" \
        | sed -n 's/^ID_LENGTH=\([0-9]*\).*/\1/p' \
        | date -u -d "@$(cat)" '+%H:%M:%S' \
        | echo "$file: $(cat)"
    done
}

``Common sense is nothing more than a deposit of prejudices laid down by the mind before you reach eighteen.''
~ Albert Einstein

Offline

Board footer

Powered by FluxBB