Check These Out
Remove everything except that file with shell tricks inside a subshell to avoid changes in the environment.
$ help shopt
The biggest advantage of this over the functions is that it is portable.
Sometimes in a script you want to make sure that a directory is in the path, and add it in if it's not already there. In this example, $dir contains the new directory you want to add to the path if it's not already present.
There are multiple ways to do this, but this one is a nice clean shell-internal approach. I based it on http://stackoverflow.com/a/1397020.
You can also do it using tr to separate the path into lines and grep -x to look for exact matches, like this:
$ if ! $(echo "$PATH" | tr ":" "\n" | grep -qx "$dir") ; then PATH=$PATH:$dir ; fi
which I got from http://stackoverflow.com/a/5048977.
Or replace the "echo | tr" part with a shell parameter expansion, like
$ if ! $(echo "${PATH//:/$'\n'}" | grep -qx "$dir") ; then PATH=$PATH:$dir ; fi
which I got from http://www.commandlinefu.com/commands/view/3209/.
There are also other more regex-y ways to do it, but I find the ones listed here easiest to follow.
Note some of this is specific to the bash shell.
can be used within a script to configure iptables for example:
iface=$2
inet_ip=`ifconfig "$iface" | grep inet | cut -d: -f2 | cut -d ' ' -f1`
ipt="sudo /sbin/iptables"
.........................
----------------------------------------------------------------------------------------------------------------
$ipt -A INPUT -i $iface ! -f -p tcp -s $UL -d $inet_ip --sport 1023: --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
----------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
$ipt -A OUTPUT -o $iface -p tcp -s $inet_ip -d $UL --sport 3306 --dport 1023: -m state --state ESTABLISHED,RELATED -j ACCEPT
-----------------------------------------------------------------------------------------------------------------
It's sometimes useful to strip the embedded fonts from a pdf, for importing into something like Inkscape. Be warned, this will increase the size of a pdf substantially.
I tried this with only gs writing with -sDEVICE=pdfwrite but it doesn't seem to work, so I just pipe postscript output to ps2pdf for the same effect.
Return IP information about your external ip address with JSON format
diff is designed to compare two files. You can also compare directories. In this form, bash uses 'process substitution' in place of a file as an input to diff. Each input to diff can be filtered as you choose. I use find and egrep to select the files to compare.
This also works with Safari if you just change the application name. Replace
$ window 1
with
$ windows
to list the URLs of tabs in all windows instead of only the frontmost window. This also includes titles:
$ osascript -e{'set o to""','tell app"google chrome"','repeat with t in tabs of window 1','set o to o&url of t&"\n"&" "&title of t&"\n"',end,end}|sed \$d
.
The old dos2unix from sysutils has been deprecated on Debian systems to this tool.