Welcome to the most active Linux Forum on the web.
Go Back > Blogs
User Name



bash read file

Posted 05-24-2013 at 10:20 AM by NullTerminator
Updated 05-24-2013 at 12:26 PM by NullTerminator

Sample of while loop to process input
# Purpose: Cleanup any confirmation reports (*.pdf) older than xx days
# Called By:  batch daily cleanup process,  /Applications/xyz/
# Author: jeb
# Date: 4/20/07
# Comments: The while loop is preferred over the find -exec rm {} syntax because it
#           does not spawn a process for each file to be deleted.
#           The script expects
LQ Newbie
Posted in Uncategorized
Views 736 Comments 0 NullTerminator is offline

A good $PS1 for displaying long paths in the bash prompt

Posted 03-14-2013 at 12:29 AM by the dsc (linux-related notes)
Updated 03-14-2013 at 12:30 AM by the dsc
Tags bash, prompt, ps1

PS1='${debian_chroot:+($debian_chroot)}\t \u $(if [ ${#PWD} -gt 30 ] ; then myPWD="${PWD:0:12}…/\W" ; myPWD="${myPWD:0:25}…" ; else myPWD=$PWD; fi ; echo $myPWD) $ '
It will display full paths smaller than 30 characters entirely, but for longer paths it will get only the first characters of the whole path, and the fist characters of the last folder in the full path.

The end result is something like:

HH:MM:SS tuxguy /home/tuxguy/mystuf.../xmas...
Posted in Uncategorized
Views 888 Comments 0 the dsc is offline

File conversion script

Posted 12-29-2012 at 11:04 AM by Snark1994
Updated 12-29-2012 at 11:10 AM by Snark1994

A handy script I put together to automatically convert between file formats based on file extension, in an easily extensible manner:

#!/usr/bin/env bash

#Conversion rules:
# commands["extension_from extension_to"]="convert_command"
# INFILE and OUTFILE in the conversion command are replaced
# with the appropriate filenames

declare -A commands
commands["wav mp3"]="ffmpeg -i INFILE OUTFILE"
Senior Member
Posted in Uncategorized
Views 601 Comments 0 Snark1994 is offline

Bash quickie: loop N times, without doing math

Posted 10-22-2012 at 10:07 PM by the dsc (linux-related notes)
Updated 03-10-2013 at 01:25 AM by the dsc (improving, varible version)
Tags bash, loop

I thought that the only way to do such type of loop in Bash would require something like "n=$(($n+1))" within the loop, with the loop being conditioned to "n" adding up to whatever you want, such as "until ((n==30)) ; do". But you can actually do "for i in {1..20} ; do <whatever> ; done". That's somewhat similar to Basic's "for i=1 to 20 ; whatever ; next i".

But it won't work with variables for the starting and ending numbers....
Posted in Uncategorized
Views 850 Comments 0 the dsc is offline

Example script to run and manage a service (tcpdump) with managed logging.

Posted 10-11-2012 at 08:59 PM by konsolebox
Updated 06-13-2015 at 01:27 AM by konsolebox

I made this script as a reply to a question on a thread before. The accidentally simplified complexity of it amazes me so I thought that it would be nice to post this on a blog as well. Original thread:

The script runs and manages a service (tcpdump). It could also automatically delete files older than C days, and reduce the size of a logfile if it's already larger than N bytes....
Senior Member
Posted in Howtos
Views 2821 Comments 0 konsolebox is offline


All times are GMT -5. The time now is 08:45 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration