<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.linuxquestions.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jcllings</id>
	<title>LQWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.linuxquestions.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jcllings"/>
	<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/wiki/Special:Contributions/Jcllings"/>
	<updated>2026-04-15T18:20:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.0</generator>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=59959</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=59959"/>
		<updated>2013-12-05T17:28:03Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Command Line Trash Can */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with GUI Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= Managing JVMs =&lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system. At least most that I know, don't.  This next script manages a symbolic link such that you can easily switch out JVM's. Just set your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
 &lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
 &lt;br /&gt;
 ctr=0&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
 &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
 &lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
= Kerberos Startup Scripts =&lt;br /&gt;
Tested on Centos 5.5&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
I built Kerberos from source and needed to run it at boot.  Toward that end I wrote these two scripts and used webmin to enable the autostart.  &amp;lt;br&amp;gt;&lt;br /&gt;
While I understand that chkconfig can and should be used in cases such as these, since I wrote these I figured I'd publish them in case someone else found them useful.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Named /etc/init.d/kdcd&amp;lt;br&amp;gt;&lt;br /&gt;
Starts the /usr/local/sbin/krb5kdc proc&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # written by John Sullivan 12/29/2010&lt;br /&gt;
 #	/usr/local/sbin/krb5kdc&lt;br /&gt;
 # description: Start and stop Kerberos5 krb5kdc process&lt;br /&gt;
 # processname: krb5kdc&lt;br /&gt;
 &lt;br /&gt;
 # Source function library&lt;br /&gt;
 . /etc/rc.d/init.d/functions&lt;br /&gt;
 &lt;br /&gt;
 # If the executable doesn't exist, then why bother?&lt;br /&gt;
 test -f /usr/local/sbin/krb5kdc || echo &amp;quot;krb5kdc not found. Exiting script.&amp;quot; exit 0&lt;br /&gt;
 &lt;br /&gt;
 NAME=kdcd&lt;br /&gt;
 DESC=&amp;quot;Start and stop Kerberos5 krb5kdc process&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 check_kdc_status()&lt;br /&gt;
 {&lt;br /&gt;
 krb5kdc_pid=`ps -C krb5kdc -o pid=`&lt;br /&gt;
 	if [ -z &amp;quot;$krb5kdc_pid&amp;quot; ]; then&lt;br /&gt;
 			# krb5kdc is NOT running&lt;br /&gt;
 			return 2&lt;br /&gt;
 	fi&lt;br /&gt;
 	if [ -n &amp;quot;$krb5kdc_pid&amp;quot; ]; then&lt;br /&gt;
 			# krb5kdc is running&lt;br /&gt;
 			return 0&lt;br /&gt;
 	fi&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 case &amp;quot;$1&amp;quot; in&lt;br /&gt;
 	start)&lt;br /&gt;
 	echo &amp;quot;Starting krb5kdc... &amp;quot;&lt;br /&gt;
 		check_kdc_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 2 ] &amp;amp;&amp;amp; /usr/local/sbin/krb5kdc &amp;amp;&amp;amp; echo &amp;quot;  krb5kdc started&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  krb5kdc already running!&amp;quot;&lt;br /&gt;
 			;;&lt;br /&gt;
 	stop)&lt;br /&gt;
 	echo &amp;quot;Stopping krb5kdc: &amp;quot;&lt;br /&gt;
 		check_kdc_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 0 ] &amp;amp;&amp;amp; kdc=`ps -C krb5kdc -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; echo &amp;quot;  krb5kdc stopped&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  krb5kdc was not running!&amp;quot;&lt;br /&gt;
 		;;&lt;br /&gt;
 	restart|reload)&lt;br /&gt;
 		check_kdc_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	if [ $RETVAL -eq 2 ]; then &lt;br /&gt;
 		echo &amp;quot;  krb5kdc was not running!&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;  starting krb5kdc: &amp;quot; &amp;amp;&amp;amp; &lt;br /&gt;
 		/usr/local/sbin/krb5kdc &amp;amp;&amp;amp; kdcpid=`ps x | grep -i krb5kdc | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid &lt;br /&gt;
 	fi&lt;br /&gt;
 	if [ $RETVAL -eq 0 ]; then&lt;br /&gt;
 		echo &amp;quot;  stopping krb5kdc... &amp;quot; &amp;amp;&amp;amp; kdc=`ps -C krb5kdc -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; &lt;br /&gt;
 		echo &amp;quot;  starting krb5kdc... &amp;quot; &amp;amp;&amp;amp; /usr/local/sbin/krb5kdc &amp;amp;&amp;amp; &lt;br /&gt;
 		kdcpid=`ps x | grep -i krb5kdc | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid&lt;br /&gt;
 	fi&lt;br /&gt;
 	;;&lt;br /&gt;
 	status)&lt;br /&gt;
 		krb5kdc_pid=`ps -C krb5kdc -o pid=`&lt;br /&gt;
 		[ -z $krb5kdc_pid ] &amp;amp;&amp;amp; echo &amp;quot;  krb5kdc NOT running&amp;quot; || echo &amp;quot;  krb5kdc running&amp;quot;&lt;br /&gt;
 	;;&lt;br /&gt;
 	*)&lt;br /&gt;
 		echo &amp;quot;  Usage: kdcd {start|stop|restart|status}&amp;quot;&lt;br /&gt;
 		exit 1&lt;br /&gt;
 esac&lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
Named /etc/init.d/kadm&amp;lt;br&amp;gt;&lt;br /&gt;
Starts the /usr/local/sbin/kadmind proc&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # written by John Sullivan 12/29/2010&lt;br /&gt;
 #	/usr/local/sbin/kadmind&lt;br /&gt;
 # description: Start and stop Kerberos5 kadmind process&lt;br /&gt;
 # processname: kadmind&lt;br /&gt;
 &lt;br /&gt;
 # Source function library&lt;br /&gt;
 . /etc/rc.d/init.d/functions&lt;br /&gt;
 &lt;br /&gt;
 # If the executable doesn't exist, then why bother?&lt;br /&gt;
 test -f /usr/local/sbin/kadmind || echo &amp;quot;kadmind not found. Exiting script.&amp;quot; exit 0&lt;br /&gt;
 &lt;br /&gt;
 NAME=kadm&lt;br /&gt;
 DESC=&amp;quot;Start and stop Kerberos5 kadmind process&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 check_kadmin_status()&lt;br /&gt;
 {&lt;br /&gt;
 kadmind_pid=`ps -C kadmind -o pid=`&lt;br /&gt;
 	if [ -z &amp;quot;$kadmind_pid&amp;quot; ]; then&lt;br /&gt;
 			# kadmind is NOT running&lt;br /&gt;
 			return 2&lt;br /&gt;
 	fi&lt;br /&gt;
 	if [ -n &amp;quot;$kadmind_pid&amp;quot; ]; then&lt;br /&gt;
 			# kadmind is running&lt;br /&gt;
 			return 0&lt;br /&gt;
 	fi&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 case &amp;quot;$1&amp;quot; in&lt;br /&gt;
 	start)&lt;br /&gt;
 	echo &amp;quot;Starting kadmind... &amp;quot;&lt;br /&gt;
 		check_kadmin_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 2 ] &amp;amp;&amp;amp; /usr/local/sbin/kadmind &amp;amp;&amp;amp; echo &amp;quot;  kadmind started&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  kadmind already running!&amp;quot;&lt;br /&gt;
 			;;&lt;br /&gt;
 	stop)&lt;br /&gt;
 	echo &amp;quot;Stopping kadmind: &amp;quot;&lt;br /&gt;
 		check_kadmin_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 0 ] &amp;amp;&amp;amp; kdc=`ps -C kadmind -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; echo &amp;quot;  kadmind stopped&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  kadmind was not running!&amp;quot;&lt;br /&gt;
 		;;&lt;br /&gt;
 	restart|reload)&lt;br /&gt;
 		check_kadmin_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	if [ $RETVAL -eq 2 ]; then &lt;br /&gt;
 		echo &amp;quot;  kadmind was not running!&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;  starting kadmind: &amp;quot; &amp;amp;&amp;amp; &lt;br /&gt;
 		/usr/local/sbin/kadmind &amp;amp;&amp;amp; kdcpid=`ps x | grep -i kadmind | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid &lt;br /&gt;
  	fi&lt;br /&gt;
 	if [ $RETVAL -eq 0 ]; then&lt;br /&gt;
 		echo &amp;quot;  stopping kadmind...&amp;quot; &amp;amp;&amp;amp; kdc=`ps -C kadmind -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; &lt;br /&gt;
 		echo &amp;quot;  starting kadmind: &amp;quot; &amp;amp;&amp;amp; /usr/local/sbin/kadmind &amp;amp;&amp;amp; &lt;br /&gt;
 		kdcpid=`ps x | grep -i kadmind | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid&lt;br /&gt;
 	fi&lt;br /&gt;
 	;;&lt;br /&gt;
 	status)&lt;br /&gt;
 		kadmind_pid=`ps -C kadmind -o pid=`&lt;br /&gt;
 		[ -z $kadmind_pid ] &amp;amp;&amp;amp; echo &amp;quot;  kadmind NOT running&amp;quot; || echo &amp;quot;  kadmind running&amp;quot;&lt;br /&gt;
 	;;&lt;br /&gt;
 	*)&lt;br /&gt;
 		echo &amp;quot;  Usage: kadm {start|stop|restart|status}&amp;quot;&lt;br /&gt;
 		exit 1&lt;br /&gt;
 esac&lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=59958</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=59958"/>
		<updated>2013-12-05T17:26:49Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* KDE4 Command Line Trash Can */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= Managing JVMs =&lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system. At least most that I know, don't.  This next script manages a symbolic link such that you can easily switch out JVM's. Just set your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
 &lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
 &lt;br /&gt;
 ctr=0&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
 &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
 &lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
= Kerberos Startup Scripts =&lt;br /&gt;
Tested on Centos 5.5&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
I built Kerberos from source and needed to run it at boot.  Toward that end I wrote these two scripts and used webmin to enable the autostart.  &amp;lt;br&amp;gt;&lt;br /&gt;
While I understand that chkconfig can and should be used in cases such as these, since I wrote these I figured I'd publish them in case someone else found them useful.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Named /etc/init.d/kdcd&amp;lt;br&amp;gt;&lt;br /&gt;
Starts the /usr/local/sbin/krb5kdc proc&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # written by John Sullivan 12/29/2010&lt;br /&gt;
 #	/usr/local/sbin/krb5kdc&lt;br /&gt;
 # description: Start and stop Kerberos5 krb5kdc process&lt;br /&gt;
 # processname: krb5kdc&lt;br /&gt;
 &lt;br /&gt;
 # Source function library&lt;br /&gt;
 . /etc/rc.d/init.d/functions&lt;br /&gt;
 &lt;br /&gt;
 # If the executable doesn't exist, then why bother?&lt;br /&gt;
 test -f /usr/local/sbin/krb5kdc || echo &amp;quot;krb5kdc not found. Exiting script.&amp;quot; exit 0&lt;br /&gt;
 &lt;br /&gt;
 NAME=kdcd&lt;br /&gt;
 DESC=&amp;quot;Start and stop Kerberos5 krb5kdc process&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 check_kdc_status()&lt;br /&gt;
 {&lt;br /&gt;
 krb5kdc_pid=`ps -C krb5kdc -o pid=`&lt;br /&gt;
 	if [ -z &amp;quot;$krb5kdc_pid&amp;quot; ]; then&lt;br /&gt;
 			# krb5kdc is NOT running&lt;br /&gt;
 			return 2&lt;br /&gt;
 	fi&lt;br /&gt;
 	if [ -n &amp;quot;$krb5kdc_pid&amp;quot; ]; then&lt;br /&gt;
 			# krb5kdc is running&lt;br /&gt;
 			return 0&lt;br /&gt;
 	fi&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 case &amp;quot;$1&amp;quot; in&lt;br /&gt;
 	start)&lt;br /&gt;
 	echo &amp;quot;Starting krb5kdc... &amp;quot;&lt;br /&gt;
 		check_kdc_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 2 ] &amp;amp;&amp;amp; /usr/local/sbin/krb5kdc &amp;amp;&amp;amp; echo &amp;quot;  krb5kdc started&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  krb5kdc already running!&amp;quot;&lt;br /&gt;
 			;;&lt;br /&gt;
 	stop)&lt;br /&gt;
 	echo &amp;quot;Stopping krb5kdc: &amp;quot;&lt;br /&gt;
 		check_kdc_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 0 ] &amp;amp;&amp;amp; kdc=`ps -C krb5kdc -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; echo &amp;quot;  krb5kdc stopped&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  krb5kdc was not running!&amp;quot;&lt;br /&gt;
 		;;&lt;br /&gt;
 	restart|reload)&lt;br /&gt;
 		check_kdc_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	if [ $RETVAL -eq 2 ]; then &lt;br /&gt;
 		echo &amp;quot;  krb5kdc was not running!&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;  starting krb5kdc: &amp;quot; &amp;amp;&amp;amp; &lt;br /&gt;
 		/usr/local/sbin/krb5kdc &amp;amp;&amp;amp; kdcpid=`ps x | grep -i krb5kdc | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid &lt;br /&gt;
 	fi&lt;br /&gt;
 	if [ $RETVAL -eq 0 ]; then&lt;br /&gt;
 		echo &amp;quot;  stopping krb5kdc... &amp;quot; &amp;amp;&amp;amp; kdc=`ps -C krb5kdc -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; &lt;br /&gt;
 		echo &amp;quot;  starting krb5kdc... &amp;quot; &amp;amp;&amp;amp; /usr/local/sbin/krb5kdc &amp;amp;&amp;amp; &lt;br /&gt;
 		kdcpid=`ps x | grep -i krb5kdc | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid&lt;br /&gt;
 	fi&lt;br /&gt;
 	;;&lt;br /&gt;
 	status)&lt;br /&gt;
 		krb5kdc_pid=`ps -C krb5kdc -o pid=`&lt;br /&gt;
 		[ -z $krb5kdc_pid ] &amp;amp;&amp;amp; echo &amp;quot;  krb5kdc NOT running&amp;quot; || echo &amp;quot;  krb5kdc running&amp;quot;&lt;br /&gt;
 	;;&lt;br /&gt;
 	*)&lt;br /&gt;
 		echo &amp;quot;  Usage: kdcd {start|stop|restart|status}&amp;quot;&lt;br /&gt;
 		exit 1&lt;br /&gt;
 esac&lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
Named /etc/init.d/kadm&amp;lt;br&amp;gt;&lt;br /&gt;
Starts the /usr/local/sbin/kadmind proc&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # written by John Sullivan 12/29/2010&lt;br /&gt;
 #	/usr/local/sbin/kadmind&lt;br /&gt;
 # description: Start and stop Kerberos5 kadmind process&lt;br /&gt;
 # processname: kadmind&lt;br /&gt;
 &lt;br /&gt;
 # Source function library&lt;br /&gt;
 . /etc/rc.d/init.d/functions&lt;br /&gt;
 &lt;br /&gt;
 # If the executable doesn't exist, then why bother?&lt;br /&gt;
 test -f /usr/local/sbin/kadmind || echo &amp;quot;kadmind not found. Exiting script.&amp;quot; exit 0&lt;br /&gt;
 &lt;br /&gt;
 NAME=kadm&lt;br /&gt;
 DESC=&amp;quot;Start and stop Kerberos5 kadmind process&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 check_kadmin_status()&lt;br /&gt;
 {&lt;br /&gt;
 kadmind_pid=`ps -C kadmind -o pid=`&lt;br /&gt;
 	if [ -z &amp;quot;$kadmind_pid&amp;quot; ]; then&lt;br /&gt;
 			# kadmind is NOT running&lt;br /&gt;
 			return 2&lt;br /&gt;
 	fi&lt;br /&gt;
 	if [ -n &amp;quot;$kadmind_pid&amp;quot; ]; then&lt;br /&gt;
 			# kadmind is running&lt;br /&gt;
 			return 0&lt;br /&gt;
 	fi&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 case &amp;quot;$1&amp;quot; in&lt;br /&gt;
 	start)&lt;br /&gt;
 	echo &amp;quot;Starting kadmind... &amp;quot;&lt;br /&gt;
 		check_kadmin_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 2 ] &amp;amp;&amp;amp; /usr/local/sbin/kadmind &amp;amp;&amp;amp; echo &amp;quot;  kadmind started&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  kadmind already running!&amp;quot;&lt;br /&gt;
 			;;&lt;br /&gt;
 	stop)&lt;br /&gt;
 	echo &amp;quot;Stopping kadmind: &amp;quot;&lt;br /&gt;
 		check_kadmin_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	[ $RETVAL -eq 0 ] &amp;amp;&amp;amp; kdc=`ps -C kadmind -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; echo &amp;quot;  kadmind stopped&amp;quot; || &lt;br /&gt;
 		echo &amp;quot;  kadmind was not running!&amp;quot;&lt;br /&gt;
 		;;&lt;br /&gt;
 	restart|reload)&lt;br /&gt;
 		check_kadmin_status&lt;br /&gt;
 		RETVAL=$?&lt;br /&gt;
 	if [ $RETVAL -eq 2 ]; then &lt;br /&gt;
 		echo &amp;quot;  kadmind was not running!&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;  starting kadmind: &amp;quot; &amp;amp;&amp;amp; &lt;br /&gt;
 		/usr/local/sbin/kadmind &amp;amp;&amp;amp; kdcpid=`ps x | grep -i kadmind | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid &lt;br /&gt;
  	fi&lt;br /&gt;
 	if [ $RETVAL -eq 0 ]; then&lt;br /&gt;
 		echo &amp;quot;  stopping kadmind...&amp;quot; &amp;amp;&amp;amp; kdc=`ps -C kadmind -o pid=` &amp;amp;&amp;amp; `kill $kdc` &amp;amp;&amp;amp; &lt;br /&gt;
 		echo &amp;quot;  starting kadmind: &amp;quot; &amp;amp;&amp;amp; /usr/local/sbin/kadmind &amp;amp;&amp;amp; &lt;br /&gt;
 		kdcpid=`ps x | grep -i kadmind | grep -v grep` &amp;amp;&amp;amp; echo $kdcpid&lt;br /&gt;
 	fi&lt;br /&gt;
 	;;&lt;br /&gt;
 	status)&lt;br /&gt;
 		kadmind_pid=`ps -C kadmind -o pid=`&lt;br /&gt;
 		[ -z $kadmind_pid ] &amp;amp;&amp;amp; echo &amp;quot;  kadmind NOT running&amp;quot; || echo &amp;quot;  kadmind running&amp;quot;&lt;br /&gt;
 	;;&lt;br /&gt;
 	*)&lt;br /&gt;
 		echo &amp;quot;  Usage: kadm {start|stop|restart|status}&amp;quot;&lt;br /&gt;
 		exit 1&lt;br /&gt;
 esac&lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=User:Jcllings&amp;diff=59311</id>
		<title>User:Jcllings</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=User:Jcllings&amp;diff=59311"/>
		<updated>2011-12-30T20:43:29Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is my BASH scriptorium and the place where I keep notes on writing them. BASH, is the Borne Again SHell. BASH is a programming language that one writes to execute commands on a Linux or Unix system. The official BASH website is [http://www.gnu.org/software/bash here]. BASH is an interpreted language which means it runs on a virtual machine like Java does. Unfortunately, BASH isn't all that cross-platform. For the most part, it is for Unix only. Mac's do come with it, by the way. One can run BASH on Windows but you need [http://www.cygwin.com/ Cygwin] for that particular trick. Cygwin can be a little tricky to install, for Windows software but if you're careful to follow the instructions, it shouldn't be a problem. Documentation is fair for Cygwin.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
While BASH is the grand Unix standard, it isn't the best language to be writing scripts in these days, however... It is important for any Unix or Linux user to be able to read and trace through BASH.  Why? Because you may need these skills if something goes wrong on your Unix or Linux machine. Can't tell you how many times it has come in handy. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:47, January 24, 2010 (UTC)&lt;br /&gt;
==Trashy Scripting==&lt;br /&gt;
&lt;br /&gt;
Moved to: [http://wiki.linuxquestions.org/wiki/Scripts LinuxQuestions Wiki - Scripts]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Scripting Tips==&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:47, January 24, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
See the links section below for a marvellous article on colourized BASH prompts.&lt;br /&gt;
&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colourize the output of the '''ls''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:46, January 24, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
*[http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt - ArchWiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:46, January 24, 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=User:Jcllings&amp;diff=59310</id>
		<title>User:Jcllings</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=User:Jcllings&amp;diff=59310"/>
		<updated>2011-12-30T20:40:02Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is my BASH scriptorium and the place where I keep notes on writing them. BASH, is the Borne Again SHell. BASH is a programming language that one writes to execute commands on a Linux or Unix system. The official BASH website is [http://www.gnu.org/software/bash here]. BASH is an interpreted language which means it runs on a virtual machine like Java does. Unfortunately, BASH isn't all that cross-platform. For the most part, it is for Unix only. Mac's do come with it, by the way. One can run BASH on Windows but you need [http://www.cygwin.com/ Cygwin] for that particular trick. Cygwin can be a little tricky to install, for Windows software but if you're careful to follow the instructions, it shouldn't be a problem. Documentation is fair for Cygwin.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
While BASH is the grand Unix standard, it isn't the best language to be writing scripts in these days. It is important for any Unix person to be able to read and trace through BASH, however, because you may need these skills if something goes wrong on your Unix or Linux machine. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:47, January 24, 2010 (UTC)&lt;br /&gt;
==Trashy Scripting==&lt;br /&gt;
&lt;br /&gt;
Moved to: [http://wiki.linuxquestions.org/wiki/Scripts LinuxQuestions Wiki - Scripts]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Scripting Tips==&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:47, January 24, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
See the links section below for a marvellous article on colourized BASH prompts.&lt;br /&gt;
&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colourize the output of the '''ls''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:46, January 24, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
*[http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt - ArchWiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:46, January 24, 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53521</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53521"/>
		<updated>2010-07-25T19:22:12Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing JVMs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= Managing JVMs =&lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system. At least most that I know, don't.  This next script manages a symbolic link such that you can easily switch out JVM's. Just set your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
 &lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
 &lt;br /&gt;
 ctr=0&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
 &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
 &lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53519</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53519"/>
		<updated>2010-07-25T19:17:55Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing JVMs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= Managing JVMs =&lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system.  This next script manages a symbolic link such that you can easily switch out JVM's. Just set your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
 &lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
 &lt;br /&gt;
 ctr=0&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
 &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
 &lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53518</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53518"/>
		<updated>2010-07-25T19:17:26Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing JVMs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= Managing JVMs =&lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system.  This next script manages a symbolic link such that you can easily switch out JVM's. Just make your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
 &lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
 &lt;br /&gt;
 ctr=0&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
 &lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
 &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
 &lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53517</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53517"/>
		<updated>2010-07-25T19:16:47Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing JVMs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= Managing JVMs =&lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system.  This next script manages a symbolic link such that you can easily switch out JVM's. Just make your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
&lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
&lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
&lt;br /&gt;
 ctr=0&lt;br /&gt;
&lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
&lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
&lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
&lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53516</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53516"/>
		<updated>2010-07-25T19:16:11Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
== Managing JVMs == &lt;br /&gt;
So if your a Java developer, you probably don't use the etc/alternatives system.  This next script manages a symbolic link such that you can easily switch out JVM's. Just make your ''${JAVA_HOME}'' to ''~/bin/java'' and the script will create a link here.  &lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 set -e &lt;br /&gt;
&lt;br /&gt;
 JDKDIR=&amp;quot;/opt/jdks/&amp;quot; #Must end in a / &lt;br /&gt;
&lt;br /&gt;
 echo &amp;quot;Available jdks: &amp;quot;&lt;br /&gt;
 echo&lt;br /&gt;
&lt;br /&gt;
 ctr=0&lt;br /&gt;
&lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do &lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   echo ${ctr}. ${JDKDIR}${I}&lt;br /&gt;
 fi&lt;br /&gt;
 done&lt;br /&gt;
 ctr=0&lt;br /&gt;
 echo&lt;br /&gt;
 echo Choose:&lt;br /&gt;
 read response&lt;br /&gt;
&lt;br /&gt;
 for I in `ls ${JDKDIR} | grep jdk`;do&lt;br /&gt;
&lt;br /&gt;
 if [[ -d ${JDKDIR}${I} ]];then&lt;br /&gt;
   let &amp;quot;ctr +=1&amp;quot;&lt;br /&gt;
   if [[ ${ctr} == ${response} ]];then&lt;br /&gt;
&lt;br /&gt;
     rm -f &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
     ln -s &amp;quot;${JDKDIR}${I}/bin&amp;quot; &amp;quot;$HOME/bin/java&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   fi&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53512</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53512"/>
		<updated>2010-07-25T14:44:50Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Using SSH */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''SSH''' is short for '''S'''ecure '''Sh'''ell. It allows you to execute [[command]]s on a remote computer and much more. It uses encryption for the data transfer.&lt;br /&gt;
&lt;br /&gt;
The [http://man.linuxquestions.org/?query=ssh&amp;amp;section=0&amp;amp;type=2 ssh man page] gives you an overview of the capabilities of ssh, as does [[using SSH]] on this site.&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] is more secure than telnet thus it is recommended for use with [[Linux]] systems.&lt;br /&gt;
* In [[Red Hat]] &amp;amp; [[fedora]] these [[RPM]] [[packages]] must be [[install]]ed: openssh-[[client]]s, [[openssh]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
Main article: [[Using ssh]]&lt;br /&gt;
&lt;br /&gt;
1. Type: &lt;br /&gt;
 # ssh ''youruser''@''192.168.0.2''&lt;br /&gt;
In this case, ''192.168.0.2'' is your target's IP address, where you have a user ''youruser''. You can also use a [[hostname]], in our examples ''target'' instead of an IP address.&lt;br /&gt;
'''1st time you log in to a system a mesage will come up:'''&lt;br /&gt;
  The authenticity of host 'xxxxx' can't be established.&lt;br /&gt;
  DSA key fingerprint is ''94:68:3a:3a:bc:f3:9a:9b:01:5d:b3:07:38:e2:11:0c''.&lt;br /&gt;
  Are you sure you want to continue connecting (yes/no)?  &amp;lt;-- type in y for yes or n for no&lt;br /&gt;
&lt;br /&gt;
'''If you type yes then:'''&lt;br /&gt;
  Warning: Permanently added 'xxxxxxxx' (RSA) to the list of known hosts.&lt;br /&gt;
&lt;br /&gt;
2. Now type in the password&lt;br /&gt;
&lt;br /&gt;
3. If you don't want to log in but you want to execute a command, do this: &lt;br /&gt;
 # ssh ''youruser''@''target'' ''date''&lt;br /&gt;
This will execute the [[command]] ''[[date]]'' as user ''youruser'' on the computer ''target''.&lt;br /&gt;
&lt;br /&gt;
You can even run GUI programs with this. For example, if you wanted to run a GUI text editor like ''kate'' or a web browser like ''firefox'', try something like this:&lt;br /&gt;
&lt;br /&gt;
 ssh -X username@servername firefox&lt;br /&gt;
&lt;br /&gt;
This will cause ''firefox'' to load on the remote machine, '''however the interface will be forwarded to your local machine''' giving you remote control over an encrypted ssh connection. Pretty cool, huh? ;-)  If this doesn't work out-of-box then it probably means that it is turned off in the openssh server configuration. &lt;br /&gt;
&lt;br /&gt;
==== TroubleShooting ====&lt;br /&gt;
If ssh does not work, you may have switched on the [[firewall]]. Make sure your target computer has port 22 open towards your computer:&lt;br /&gt;
 telnet ''target'' 22&lt;br /&gt;
 Trying 192.168.0.2...&lt;br /&gt;
 Connected to ''target''.&lt;br /&gt;
 Escape character is '^]'.&lt;br /&gt;
 SSH-2.0-OpenSSH_4.6&lt;br /&gt;
&lt;br /&gt;
==== See also ====&lt;br /&gt;
* [[passWordLess LogIns]]&lt;br /&gt;
&lt;br /&gt;
== SSH Client Software ==&lt;br /&gt;
* [[OpenSSH]]&lt;br /&gt;
* [[lsh]]&lt;br /&gt;
* [[PuTTY]]&lt;br /&gt;
Some implementations for other OS:&lt;br /&gt;
* [http://sshdos.sourceforge.net SSHDOS] - client for [[MS-DOS]].&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] - client for console access and X-Windows forwarding on [[Windows]].&lt;br /&gt;
* [[Using_SSH#WinSCP_-_A_Windows_implementation_of_scp|WinSCP]] [http://winscp.net/] - open source SFTP and SCP client.&lt;br /&gt;
* The [[Cygwin]] UNIX environment for Windows includes OpenSSH's client and server.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting SSH Connections ==&lt;br /&gt;
&lt;br /&gt;
SSH clients and servers can generate a lot of debug information.&lt;br /&gt;
&lt;br /&gt;
On the server, kill [[sshd]], and then start the server in debug mode.&lt;br /&gt;
&lt;br /&gt;
 $ [[killall]] sshd PID&lt;br /&gt;
 $ /usr/sbin/sshd -ddde&lt;br /&gt;
&lt;br /&gt;
Leave the window open, so you can see the output it generates.&lt;br /&gt;
&lt;br /&gt;
Then on the client, run:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -vvv ''(target-host)''&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Using SSH]] -- copying files, remoting, clients&lt;br /&gt;
* [[SFTP]] - secure file transfer protocol&lt;br /&gt;
* [[Scp]] - secure copy protocol&lt;br /&gt;
* [[Sshd]] - SSH daemon&lt;br /&gt;
* [[Tunneling with SSH]] Using SSH to tunnel TCP connections.&lt;br /&gt;
* [[Autossh|autossh]] SSH Tunnels that won't drop dead.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53511</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53511"/>
		<updated>2010-07-25T14:40:05Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Using SSH */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''SSH''' is short for '''S'''ecure '''Sh'''ell. It allows you to execute [[command]]s on a remote computer and much more. It uses encryption for the data transfer.&lt;br /&gt;
&lt;br /&gt;
The [http://man.linuxquestions.org/?query=ssh&amp;amp;section=0&amp;amp;type=2 ssh man page] gives you an overview of the capabilities of ssh, as does [[using SSH]] on this site.&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] is more secure than telnet thus it is recommended for use with [[Linux]] systems.&lt;br /&gt;
* In [[Red Hat]] &amp;amp; [[fedora]] these [[RPM]] [[packages]] must be [[install]]ed: openssh-[[client]]s, [[openssh]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
Main article: [[Using ssh]]&lt;br /&gt;
&lt;br /&gt;
1. Type: &lt;br /&gt;
 # ssh ''youruser''@''192.168.0.2''&lt;br /&gt;
In this case, ''192.168.0.2'' is your target's IP address, where you have a user ''youruser''. You can also use a [[hostname]], in our examples ''target'' instead of an IP address.&lt;br /&gt;
'''1st time you log in to a system a mesage will come up:'''&lt;br /&gt;
  The authenticity of host 'xxxxx' can't be established.&lt;br /&gt;
  DSA key fingerprint is ''94:68:3a:3a:bc:f3:9a:9b:01:5d:b3:07:38:e2:11:0c''.&lt;br /&gt;
  Are you sure you want to continue connecting (yes/no)?  &amp;lt;-- type in y for yes or n for no&lt;br /&gt;
&lt;br /&gt;
'''If you type yes then:'''&lt;br /&gt;
  Warning: Permanently added 'xxxxxxxx' (RSA) to the list of known hosts.&lt;br /&gt;
&lt;br /&gt;
2. Now type in the password&lt;br /&gt;
&lt;br /&gt;
3. If you don't want to log in but you want to execute a command, do this: &lt;br /&gt;
 # ssh ''youruser''@''target'' ''date''&lt;br /&gt;
This will execute the [[command]] ''[[date]]'' as user ''youruser'' on the computer ''target''.&lt;br /&gt;
&lt;br /&gt;
You can even run GUI programs with this. For example, if you wanted to run a GUI text editor like ''kate'' or a web browser like ''firefox'', try something like this:&lt;br /&gt;
&lt;br /&gt;
 ssh -X username@servername firefox&lt;br /&gt;
&lt;br /&gt;
This will cause ''firefox'' to load on the remote machine, '''however the interface will be forwarded to your local machine''' giving you remote control over an encrypted ssh connection. Pretty cool, huh? ;-)&lt;br /&gt;
&lt;br /&gt;
==== TroubleShooting ====&lt;br /&gt;
If ssh does not work, you may have switched on the [[firewall]]. Make sure your target computer has port 22 open towards your computer:&lt;br /&gt;
 telnet ''target'' 22&lt;br /&gt;
 Trying 192.168.0.2...&lt;br /&gt;
 Connected to ''target''.&lt;br /&gt;
 Escape character is '^]'.&lt;br /&gt;
 SSH-2.0-OpenSSH_4.6&lt;br /&gt;
&lt;br /&gt;
==== See also ====&lt;br /&gt;
* [[passWordLess LogIns]]&lt;br /&gt;
&lt;br /&gt;
== SSH Client Software ==&lt;br /&gt;
* [[OpenSSH]]&lt;br /&gt;
* [[lsh]]&lt;br /&gt;
* [[PuTTY]]&lt;br /&gt;
Some implementations for other OS:&lt;br /&gt;
* [http://sshdos.sourceforge.net SSHDOS] - client for [[MS-DOS]].&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] - client for console access and X-Windows forwarding on [[Windows]].&lt;br /&gt;
* [[Using_SSH#WinSCP_-_A_Windows_implementation_of_scp|WinSCP]] [http://winscp.net/] - open source SFTP and SCP client.&lt;br /&gt;
* The [[Cygwin]] UNIX environment for Windows includes OpenSSH's client and server.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting SSH Connections ==&lt;br /&gt;
&lt;br /&gt;
SSH clients and servers can generate a lot of debug information.&lt;br /&gt;
&lt;br /&gt;
On the server, kill [[sshd]], and then start the server in debug mode.&lt;br /&gt;
&lt;br /&gt;
 $ [[killall]] sshd PID&lt;br /&gt;
 $ /usr/sbin/sshd -ddde&lt;br /&gt;
&lt;br /&gt;
Leave the window open, so you can see the output it generates.&lt;br /&gt;
&lt;br /&gt;
Then on the client, run:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -vvv ''(target-host)''&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Using SSH]] -- copying files, remoting, clients&lt;br /&gt;
* [[SFTP]] - secure file transfer protocol&lt;br /&gt;
* [[Scp]] - secure copy protocol&lt;br /&gt;
* [[Sshd]] - SSH daemon&lt;br /&gt;
* [[Tunneling with SSH]] Using SSH to tunnel TCP connections.&lt;br /&gt;
* [[Autossh|autossh]] SSH Tunnels that won't drop dead.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53510</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53510"/>
		<updated>2010-07-25T14:39:07Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Using SSH */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''SSH''' is short for '''S'''ecure '''Sh'''ell. It allows you to execute [[command]]s on a remote computer and much more. It uses encryption for the data transfer.&lt;br /&gt;
&lt;br /&gt;
The [http://man.linuxquestions.org/?query=ssh&amp;amp;section=0&amp;amp;type=2 ssh man page] gives you an overview of the capabilities of ssh, as does [[using SSH]] on this site.&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] is more secure than telnet thus it is recommended for use with [[Linux]] systems.&lt;br /&gt;
* In [[Red Hat]] &amp;amp; [[fedora]] these [[RPM]] [[packages]] must be [[install]]ed: openssh-[[client]]s, [[openssh]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
Main article: [[Using ssh]]&lt;br /&gt;
&lt;br /&gt;
1. Type: &lt;br /&gt;
 # ssh ''youruser''@''192.168.0.2''&lt;br /&gt;
In this case, ''192.168.0.2'' is your target's IP address, where you have a user ''youruser''. You can also use a [[hostname]], in our examples ''target'' instead of an IP address.&lt;br /&gt;
'''1st time you log in to a system a mesage will come up:'''&lt;br /&gt;
  The authenticity of host 'xxxxx' can't be established.&lt;br /&gt;
  DSA key fingerprint is ''94:68:3a:3a:bc:f3:9a:9b:01:5d:b3:07:38:e2:11:0c''.&lt;br /&gt;
  Are you sure you want to continue connecting (yes/no)?  &amp;lt;-- type in y for yes or n for no&lt;br /&gt;
&lt;br /&gt;
'''If you type yes then:'''&lt;br /&gt;
  Warning: Permanently added 'xxxxxxxx' (RSA) to the list of known hosts.&lt;br /&gt;
&lt;br /&gt;
2. Now type in the password&lt;br /&gt;
&lt;br /&gt;
3. If you don't want to log in but you want to execute a command, do this: &lt;br /&gt;
 # ssh ''youruser''@''target'' ''date''&lt;br /&gt;
This will execute the [[command]] ''[[date]]'' as user ''youruser'' on the computer ''target''.&lt;br /&gt;
&lt;br /&gt;
You can even run GUI programs with this. For example, if you wanted to run a GUI text editor like ''kate'' or a web browser like ''firefox'', try something like this:&lt;br /&gt;
&lt;br /&gt;
 ssh -X username@servername firefox&lt;br /&gt;
&lt;br /&gt;
This will cause ''firefox'' to load on the remote machine, '''however the interface will be forwarded to your local machine''' over an encrypted ssh connection. Pretty cool, huh? ;-)&lt;br /&gt;
&lt;br /&gt;
==== TroubleShooting ====&lt;br /&gt;
If ssh does not work, you may have switched on the [[firewall]]. Make sure your target computer has port 22 open towards your computer:&lt;br /&gt;
 telnet ''target'' 22&lt;br /&gt;
 Trying 192.168.0.2...&lt;br /&gt;
 Connected to ''target''.&lt;br /&gt;
 Escape character is '^]'.&lt;br /&gt;
 SSH-2.0-OpenSSH_4.6&lt;br /&gt;
&lt;br /&gt;
==== See also ====&lt;br /&gt;
* [[passWordLess LogIns]]&lt;br /&gt;
&lt;br /&gt;
== SSH Client Software ==&lt;br /&gt;
* [[OpenSSH]]&lt;br /&gt;
* [[lsh]]&lt;br /&gt;
* [[PuTTY]]&lt;br /&gt;
Some implementations for other OS:&lt;br /&gt;
* [http://sshdos.sourceforge.net SSHDOS] - client for [[MS-DOS]].&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] - client for console access and X-Windows forwarding on [[Windows]].&lt;br /&gt;
* [[Using_SSH#WinSCP_-_A_Windows_implementation_of_scp|WinSCP]] [http://winscp.net/] - open source SFTP and SCP client.&lt;br /&gt;
* The [[Cygwin]] UNIX environment for Windows includes OpenSSH's client and server.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting SSH Connections ==&lt;br /&gt;
&lt;br /&gt;
SSH clients and servers can generate a lot of debug information.&lt;br /&gt;
&lt;br /&gt;
On the server, kill [[sshd]], and then start the server in debug mode.&lt;br /&gt;
&lt;br /&gt;
 $ [[killall]] sshd PID&lt;br /&gt;
 $ /usr/sbin/sshd -ddde&lt;br /&gt;
&lt;br /&gt;
Leave the window open, so you can see the output it generates.&lt;br /&gt;
&lt;br /&gt;
Then on the client, run:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -vvv ''(target-host)''&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Using SSH]] -- copying files, remoting, clients&lt;br /&gt;
* [[SFTP]] - secure file transfer protocol&lt;br /&gt;
* [[Scp]] - secure copy protocol&lt;br /&gt;
* [[Sshd]] - SSH daemon&lt;br /&gt;
* [[Tunneling with SSH]] Using SSH to tunnel TCP connections.&lt;br /&gt;
* [[Autossh|autossh]] SSH Tunnels that won't drop dead.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53509</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53509"/>
		<updated>2010-07-25T14:28:36Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''SSH''' is short for '''S'''ecure '''Sh'''ell. It allows you to execute [[command]]s on a remote computer and much more. It uses encryption for the data transfer.&lt;br /&gt;
&lt;br /&gt;
The [http://man.linuxquestions.org/?query=ssh&amp;amp;section=0&amp;amp;type=2 ssh man page] gives you an overview of the capabilities of ssh, as does [[using SSH]] on this site.&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] is more secure than telnet thus it is recommended for use with [[Linux]] systems.&lt;br /&gt;
* In [[Red Hat]] &amp;amp; [[fedora]] these [[RPM]] [[packages]] must be [[install]]ed: openssh-[[client]]s, [[openssh]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
Main article: [[Using ssh]]&lt;br /&gt;
&lt;br /&gt;
1. Type: &lt;br /&gt;
 # ssh ''youruser''@''192.168.0.2''&lt;br /&gt;
In this case, ''192.168.0.2'' is your target's IP address, where you have a user ''youruser''. You can also use a [[hostname]], in our examples ''target'' instead of an IP address.&lt;br /&gt;
'''1st time you log in to a system a mesage will come up:'''&lt;br /&gt;
  The authenticity of host 'xxxxx' can't be established.&lt;br /&gt;
  DSA key fingerprint is ''94:68:3a:3a:bc:f3:9a:9b:01:5d:b3:07:38:e2:11:0c''.&lt;br /&gt;
  Are you sure you want to continue connecting (yes/no)?  &amp;lt;-- type in y for yes or n for no&lt;br /&gt;
&lt;br /&gt;
'''If you type yes then:'''&lt;br /&gt;
  Warning: Permanently added 'xxxxxxxx' (RSA) to the list of known hosts.&lt;br /&gt;
&lt;br /&gt;
2. Now type in the password&lt;br /&gt;
&lt;br /&gt;
3. If you don't want to log in but you want to execute a command, do this: &lt;br /&gt;
 # ssh ''youruser''@''target'' ''date''&lt;br /&gt;
This will execute the [[command]] ''[[date]]'' as user ''youruser'' on the computer ''target''.&lt;br /&gt;
&lt;br /&gt;
==== TroubleShooting ====&lt;br /&gt;
If ssh does not work, you may have switched on the [[firewall]]. Make sure your target computer has port 22 open towards your computer:&lt;br /&gt;
 telnet ''target'' 22&lt;br /&gt;
 Trying 192.168.0.2...&lt;br /&gt;
 Connected to ''target''.&lt;br /&gt;
 Escape character is '^]'.&lt;br /&gt;
 SSH-2.0-OpenSSH_4.6&lt;br /&gt;
&lt;br /&gt;
==== See also ====&lt;br /&gt;
* [[passWordLess LogIns]]&lt;br /&gt;
&lt;br /&gt;
== SSH Client Software ==&lt;br /&gt;
* [[OpenSSH]]&lt;br /&gt;
* [[lsh]]&lt;br /&gt;
* [[PuTTY]]&lt;br /&gt;
Some implementations for other OS:&lt;br /&gt;
* [http://sshdos.sourceforge.net SSHDOS] - client for [[MS-DOS]].&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] - client for console access and X-Windows forwarding on [[Windows]].&lt;br /&gt;
* [[Using_SSH#WinSCP_-_A_Windows_implementation_of_scp|WinSCP]] [http://winscp.net/] - open source SFTP and SCP client.&lt;br /&gt;
* The [[Cygwin]] UNIX environment for Windows includes OpenSSH's client and server.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting SSH Connections ==&lt;br /&gt;
&lt;br /&gt;
SSH clients and servers can generate a lot of debug information.&lt;br /&gt;
&lt;br /&gt;
On the server, kill [[sshd]], and then start the server in debug mode.&lt;br /&gt;
&lt;br /&gt;
 $ [[killall]] sshd PID&lt;br /&gt;
 $ /usr/sbin/sshd -ddde&lt;br /&gt;
&lt;br /&gt;
Leave the window open, so you can see the output it generates.&lt;br /&gt;
&lt;br /&gt;
Then on the client, run:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -vvv ''(target-host)''&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Using SSH]] -- copying files, remoting, clients&lt;br /&gt;
* [[SFTP]] - secure file transfer protocol&lt;br /&gt;
* [[Scp]] - secure copy protocol&lt;br /&gt;
* [[Sshd]] - SSH daemon&lt;br /&gt;
* [[Tunneling with SSH]] Using SSH to tunnel TCP connections.&lt;br /&gt;
* [[Autossh|autossh]] SSH Tunnels that won't drop dead.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53508</id>
		<title>Autossh</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53508"/>
		<updated>2010-07-25T14:22:07Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* autossh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==autossh==&lt;br /&gt;
&lt;br /&gt;
So maybe your having trouble keeping an ssh tunnel open for a program you want to secure. Lets say it's synergy, which uses port 24800. I recommend using autossh for this: &lt;br /&gt;
&lt;br /&gt;
 autossh -f -v -M 24800 -N -R 24800:localhost:22 remotehostname&lt;br /&gt;
&lt;br /&gt;
Reason being that autossh will automatically restart the tunnel if something pesky wacks it.&lt;br /&gt;
&lt;br /&gt;
There's some really awesome info on autossh here: [http://www.gentoo-wiki.info/Autossh autossh on Gentoo Wiki]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53507</id>
		<title>Autossh</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53507"/>
		<updated>2010-07-25T14:12:07Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==autossh==&lt;br /&gt;
&lt;br /&gt;
So maybe your having trouble keeping an ssh tunnel open for a program you want to secure. Lets say it's synergy, which uses port 24800. I recommend using autossh for this: &lt;br /&gt;
&lt;br /&gt;
 autossh -f -v -M 24800 -N -R 24800:localhost:22 remotehostname&lt;br /&gt;
&lt;br /&gt;
Reason being that autossh will automatically restart the tunnel if something pesky wacks it.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53506</id>
		<title>Autossh</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53506"/>
		<updated>2010-07-25T14:11:37Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;So maybe your having trouble keeping an ssh tunnel open for a program you want to secure. Lets say it's synergy, which uses port 24800. I recommend using autossh for this: &lt;br /&gt;
&lt;br /&gt;
 autossh -f -v -M 24800 -N -R 24800:localhost:22 remotehostname&lt;br /&gt;
&lt;br /&gt;
Reason being that autossh will automatically restart the tunnel if something pesky wacks it.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53505</id>
		<title>Autossh</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Autossh&amp;diff=53505"/>
		<updated>2010-07-25T14:11:10Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: Created page with 'So maybe your having trouble keeping an ssh tunnel open for a program you want to secure. Lets say it's synergy, which uses port 24800. I recommend using autossh for this:   auto…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;So maybe your having trouble keeping an ssh tunnel open for a program you want to secure. Lets say it's synergy, which uses port 24800. I recommend using autossh for this: &lt;br /&gt;
&lt;br /&gt;
autossh -f -v -M 24800 -N -R 24800:localhost:22 remotehostname&lt;br /&gt;
&lt;br /&gt;
Reason being that autossh will automatically restart the tunnel if something pesky wacks it.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Tips_and_tricks&amp;diff=53504</id>
		<title>Tips and tricks</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Tips_and_tricks&amp;diff=53504"/>
		<updated>2010-07-25T14:09:52Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Single tips */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Tip collections =&lt;br /&gt;
* [[distribution specific tips and tricks]]&lt;br /&gt;
* [[KDE specific tips and tricks]]&lt;br /&gt;
* this [[wiki]]'s [[:Category:Tips|Category Tips]]&lt;br /&gt;
&lt;br /&gt;
= Single tips =&lt;br /&gt;
* [[Mount remote folders using sshfs]]&lt;br /&gt;
* How to [[Work on a Firewall Remotely]].&lt;br /&gt;
* How to [[Swap Caps Lock and Ctrl]].&lt;br /&gt;
* Use [[screen]] to keep a program running on a server, even if you don't upkeep the connection.&lt;br /&gt;
* you can create your own [[pdf]]s without additional [[software]] - just choose it in your printer dialog to print to a pdf [[file]]&lt;br /&gt;
* you can play your old Dos [[games]] from inside [[Linux]] using [[DosBox]]&lt;br /&gt;
* you can record a video from what you are doing on your [[desktop]] using [[xvidcap]]&lt;br /&gt;
* Ctrl+Alt+ESC will change the cursor to a skull. Clicking any window with the skull will immediately [[kill]] the program. Very useful if a program refuses to close. You can cancel this by pressing ESC. Be careful not to kill your desktop or menu bar if you're running KDE or Gnome.&lt;br /&gt;
* Ctrl+Alt+Backspace will kill the X server, if it refuses to quit gracefully. It's referred to as zapping.&lt;br /&gt;
* Ctrl+Alt+Numpad_+ changes to next resolution defined in the X configuration.&lt;br /&gt;
* Ctrl+Alt+Numpad_- changes to the previous resolution.&lt;br /&gt;
* Highlighted text is automatically copied, clicking the middle mouse button will paste it. Ctrl+C, Ctrl+V also works for most environments.&lt;br /&gt;
* Hexadecimal ID3 tag editing [[hex3| script]]&lt;br /&gt;
* SSH tunnels that won't drop dead using [[autossh|autossh]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Tips]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53503</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53503"/>
		<updated>2010-07-25T14:07:05Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Specifics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''SSH''' is short for '''S'''ecure '''Sh'''ell. It allows you to execute [[command]]s on a remote computer and much more. It uses encryption for the data transfer.&lt;br /&gt;
&lt;br /&gt;
The [http://man.linuxquestions.org/?query=ssh&amp;amp;section=0&amp;amp;type=2 ssh man page] gives you an overview of the capabilities of ssh, as does [[using SSH]] on this site.&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] is more secure than telnet thus it is recommended for use with [[Linux]] systems.&lt;br /&gt;
* In [[Red Hat]] &amp;amp; [[fedora]] these [[RPM]] [[packages]] must be [[install]]ed: openssh-[[client]]s, [[openssh]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
Main article: [[Using ssh]]&lt;br /&gt;
&lt;br /&gt;
1. Type: &lt;br /&gt;
 # ssh ''youruser''@''192.168.0.2''&lt;br /&gt;
In this case, ''192.168.0.2'' is your target's IP address, where you have a user ''youruser''. You can also use a [[hostname]], in our examples ''target'' instead of an IP address.&lt;br /&gt;
'''1st time you log in to a system a mesage will come up:'''&lt;br /&gt;
  The authenticity of host 'xxxxx' can't be established.&lt;br /&gt;
  DSA key fingerprint is ''94:68:3a:3a:bc:f3:9a:9b:01:5d:b3:07:38:e2:11:0c''.&lt;br /&gt;
  Are you sure you want to continue connecting (yes/no)?  &amp;lt;-- type in y for yes or n for no&lt;br /&gt;
&lt;br /&gt;
'''If you type yes then:'''&lt;br /&gt;
  Warning: Permanently added 'xxxxxxxx' (RSA) to the list of known hosts.&lt;br /&gt;
&lt;br /&gt;
2. Now type in the password&lt;br /&gt;
&lt;br /&gt;
3. If you don't want to log in but you want to execute a command, do this: &lt;br /&gt;
 # ssh ''youruser''@''target'' ''date''&lt;br /&gt;
This will execute the [[command]] ''[[date]]'' as user ''youruser'' on the computer ''target''.&lt;br /&gt;
&lt;br /&gt;
==== TroubleShooting ====&lt;br /&gt;
If ssh does not work, you may have switched on the [[firewall]]. Make sure your target computer has port 22 open towards your computer:&lt;br /&gt;
 telnet ''target'' 22&lt;br /&gt;
 Trying 192.168.0.2...&lt;br /&gt;
 Connected to ''target''.&lt;br /&gt;
 Escape character is '^]'.&lt;br /&gt;
 SSH-2.0-OpenSSH_4.6&lt;br /&gt;
&lt;br /&gt;
==== See also ====&lt;br /&gt;
* [[passWordLess LogIns]]&lt;br /&gt;
&lt;br /&gt;
== SSH Client Software ==&lt;br /&gt;
* [[OpenSSH]]&lt;br /&gt;
* [[lsh]]&lt;br /&gt;
* [[PuTTY]]&lt;br /&gt;
Some implementations for other OS:&lt;br /&gt;
* [http://sshdos.sourceforge.net SSHDOS] - client for [[MS-DOS]].&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] - client for console access and X-Windows forwarding on [[Windows]].&lt;br /&gt;
* [[Using_SSH#WinSCP_-_A_Windows_implementation_of_scp|WinSCP]] [http://winscp.net/] - open source SFTP and SCP client.&lt;br /&gt;
* The [[Cygwin]] UNIX environment for Windows includes OpenSSH's client and server.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting SSH Connections ==&lt;br /&gt;
&lt;br /&gt;
SSH clients and servers can generate a lot of debug information.&lt;br /&gt;
&lt;br /&gt;
On the server, kill [[sshd]], and then start the server in debug mode.&lt;br /&gt;
&lt;br /&gt;
 $ [[killall]] sshd PID&lt;br /&gt;
 $ /usr/sbin/sshd -ddde&lt;br /&gt;
&lt;br /&gt;
Leave the window open, so you can see the output it generates.&lt;br /&gt;
&lt;br /&gt;
Then on the client, run:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -vvv ''(target-host)''&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Using SSH]] -- copying files, remoting, clients&lt;br /&gt;
* [[SFTP]] - secure file transfer protocol&lt;br /&gt;
* [[Scp]] - secure copy protocol&lt;br /&gt;
* [[Sshd]] - SSH daemon&lt;br /&gt;
* [[Tunneling with SSH]] Using SSH to tunnel TCP connections.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53502</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=SSH&amp;diff=53502"/>
		<updated>2010-07-25T14:05:50Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''SSH''' is short for '''S'''ecure '''Sh'''ell. It allows you to execute [[command]]s on a remote computer and much more. It uses encryption for the data transfer.&lt;br /&gt;
&lt;br /&gt;
The [http://man.linuxquestions.org/?query=ssh&amp;amp;section=0&amp;amp;type=2 ssh man page] gives you an overview of the capabilities of ssh, as does [[using SSH]] on this site.&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] is more secure than telnet thus it is recommended for use with [[Linux]] systems.&lt;br /&gt;
* In [[Red Hat]] &amp;amp; [[fedora]] these [[RPM]] [[packages]] must be [[install]]ed: openssh-[[client]]s, [[openssh]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
Main article: [[Using ssh]]&lt;br /&gt;
&lt;br /&gt;
1. Type: &lt;br /&gt;
 # ssh ''youruser''@''192.168.0.2''&lt;br /&gt;
In this case, ''192.168.0.2'' is your target's IP address, where you have a user ''youruser''. You can also use a [[hostname]], in our examples ''target'' instead of an IP address.&lt;br /&gt;
'''1st time you log in to a system a mesage will come up:'''&lt;br /&gt;
  The authenticity of host 'xxxxx' can't be established.&lt;br /&gt;
  DSA key fingerprint is ''94:68:3a:3a:bc:f3:9a:9b:01:5d:b3:07:38:e2:11:0c''.&lt;br /&gt;
  Are you sure you want to continue connecting (yes/no)?  &amp;lt;-- type in y for yes or n for no&lt;br /&gt;
&lt;br /&gt;
'''If you type yes then:'''&lt;br /&gt;
  Warning: Permanently added 'xxxxxxxx' (RSA) to the list of known hosts.&lt;br /&gt;
&lt;br /&gt;
2. Now type in the password&lt;br /&gt;
&lt;br /&gt;
3. If you don't want to log in but you want to execute a command, do this: &lt;br /&gt;
 # ssh ''youruser''@''target'' ''date''&lt;br /&gt;
This will execute the [[command]] ''[[date]]'' as user ''youruser'' on the computer ''target''.&lt;br /&gt;
&lt;br /&gt;
==== TroubleShooting ====&lt;br /&gt;
If ssh does not work, you may have switched on the [[firewall]]. Make sure your target computer has port 22 open towards your computer:&lt;br /&gt;
 telnet ''target'' 22&lt;br /&gt;
 Trying 192.168.0.2...&lt;br /&gt;
 Connected to ''target''.&lt;br /&gt;
 Escape character is '^]'.&lt;br /&gt;
 SSH-2.0-OpenSSH_4.6&lt;br /&gt;
&lt;br /&gt;
==== See also ====&lt;br /&gt;
* [[passWordLess LogIns]]&lt;br /&gt;
&lt;br /&gt;
== SSH Client Software ==&lt;br /&gt;
* [[OpenSSH]]&lt;br /&gt;
* [[lsh]]&lt;br /&gt;
* [[PuTTY]]&lt;br /&gt;
Some implementations for other OS:&lt;br /&gt;
* [http://sshdos.sourceforge.net SSHDOS] - client for [[MS-DOS]].&lt;br /&gt;
* [http://www.chiark.greenend.org.uk/~sgtatham/putty/ PuTTY] - client for console access and X-Windows forwarding on [[Windows]].&lt;br /&gt;
* [[Using_SSH#WinSCP_-_A_Windows_implementation_of_scp|WinSCP]] [http://winscp.net/] - open source SFTP and SCP client.&lt;br /&gt;
* The [[Cygwin]] UNIX environment for Windows includes OpenSSH's client and server.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting SSH Connections ==&lt;br /&gt;
&lt;br /&gt;
SSH clients and servers can generate a lot of debug information.&lt;br /&gt;
&lt;br /&gt;
On the server, kill [[sshd]], and then start the server in debug mode.&lt;br /&gt;
&lt;br /&gt;
 $ [[killall]] sshd PID&lt;br /&gt;
 $ /usr/sbin/sshd -ddde&lt;br /&gt;
&lt;br /&gt;
Leave the window open, so you can see the output it generates.&lt;br /&gt;
&lt;br /&gt;
Then on the client, run:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -vvv ''(target-host)''&lt;br /&gt;
&lt;br /&gt;
== Specifics ==&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Using SSH]] -- copying files, remoting, clients&lt;br /&gt;
* [[SFTP]] - secure file transfer protocol&lt;br /&gt;
* [[Scp]] - secure copy protocol&lt;br /&gt;
* [[Sshd]] - SSH daemon&lt;br /&gt;
* [[Tunneling with SSH]] Using SSH to tunnel TCP connections.&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=User_talk:Jcllings&amp;diff=53501</id>
		<title>User talk:Jcllings</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=User_talk:Jcllings&amp;diff=53501"/>
		<updated>2010-07-25T13:51:09Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I was moving it here from another Wiki. It got late. I got tired. ;-) Further advice welcomed. &lt;br /&gt;
----&lt;br /&gt;
Hey, thanks for your additions to [[scripts]]. If you link to [[tar]] and explain all [[options]] there, your article gets much more readable. Tell me what you think --[[User:ThorstenStaerk|ThorstenStaerk]] 07:24, July 25, 2010 (UTC)&lt;br /&gt;
----&lt;br /&gt;
Hey, that is a great bash page - would you like to integrate your findings into [[bash tIPs]]? --[[User:ThorstenStaerk|ThorstenStaerk]] 21:37, May 25, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
{{welcome}}&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53500</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53500"/>
		<updated>2010-07-25T13:47:11Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:[[#Tar|tar]] - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53499</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53499"/>
		<updated>2010-07-25T13:45:40Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53498</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53498"/>
		<updated>2010-07-25T13:45:21Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:[http://dar.linux.free.fr/ dar] - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53497</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53497"/>
		<updated>2010-07-25T13:40:52Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with 'largarchive.' but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53496</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53496"/>
		<updated>2010-07-25T13:39:51Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the individual files created. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53495</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53495"/>
		<updated>2010-07-25T13:38:39Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip2 compression. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53494</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53494"/>
		<updated>2010-07-25T13:37:06Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:[[#Zip|zip]] - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53493</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53493"/>
		<updated>2010-07-25T13:34:36Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;[[#Cat|cat]] :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53492</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53492"/>
		<updated>2010-07-25T13:32:46Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;[[#Tar|tar]] :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;[[http://unixhelp.ed.ac.uk/CGI/man-cgi?split split]] :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53491</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53491"/>
		<updated>2010-07-25T13:29:29Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :[[#Tar|Tape ARchive]], sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53472</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53472"/>
		<updated>2010-07-25T05:57:41Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53471</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53471"/>
		<updated>2010-07-25T05:56:17Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls *FilesDir&lt;br /&gt;
 arcFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 extractedFilesDir: &lt;br /&gt;
 &lt;br /&gt;
 srcFilesDir:&lt;br /&gt;
 First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
 total 2687628&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
 -rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
 -rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
 srcFilesDir/&lt;br /&gt;
 srcFilesDir/Third.iso&lt;br /&gt;
 srcFilesDir/Second.iso&lt;br /&gt;
 srcFilesDir/Fourth.iso&lt;br /&gt;
 srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 [root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
 extractedFilesDir/srcFilesDir:&lt;br /&gt;
 total 2849208&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
 -rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
 [root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
:zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
:tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
:dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53470</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53470"/>
		<updated>2010-07-25T05:54:22Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 $ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
:x - Extract files from an archive. &lt;br /&gt;
:v - Print lots of information about how things are going. &lt;br /&gt;
:j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
:f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53469</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53469"/>
		<updated>2010-07-25T05:52:56Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
$ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
:c - Create an archive. &lt;br /&gt;
:v - Produce lots of output so that we can see any errors. &lt;br /&gt;
:j - Compress using bzip. &lt;br /&gt;
:p - Preserve permissions and ownerships. &lt;br /&gt;
:S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
:f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
:b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
    x - Extract files from an archive. &lt;br /&gt;
    v - Print lots of information about how things are going. &lt;br /&gt;
    j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
    f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53468</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53468"/>
		<updated>2010-07-25T05:52:03Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
$ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
    c - Create an archive. &lt;br /&gt;
    v - Produce lots of output so that we can see any errors. &lt;br /&gt;
    j - Compress using bzip. &lt;br /&gt;
    p - Preserve permissions and ownerships. &lt;br /&gt;
    S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
    f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
    b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
    x - Extract files from an archive. &lt;br /&gt;
    v - Print lots of information about how things are going. &lt;br /&gt;
    j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
    f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53467</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53467"/>
		<updated>2010-07-25T05:51:46Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
;split :Will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
;cat :Does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
$ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
    c - Create an archive. &lt;br /&gt;
    v - Produce lots of output so that we can see any errors. &lt;br /&gt;
    j - Compress using bzip. &lt;br /&gt;
    p - Preserve permissions and ownerships. &lt;br /&gt;
    S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
    f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
    b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
    x - Extract files from an archive. &lt;br /&gt;
    v - Print lots of information about how things are going. &lt;br /&gt;
    j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
    f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53466</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53466"/>
		<updated>2010-07-25T05:51:16Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
;tar :Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
split&lt;br /&gt;
        will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
cat&lt;br /&gt;
        does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
$ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
    c - Create an archive. &lt;br /&gt;
    v - Produce lots of output so that we can see any errors. &lt;br /&gt;
    j - Compress using bzip. &lt;br /&gt;
    p - Preserve permissions and ownerships. &lt;br /&gt;
    S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
    f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
    b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
    x - Extract files from an archive. &lt;br /&gt;
    v - Print lots of information about how things are going. &lt;br /&gt;
    j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
    f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53465</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53465"/>
		<updated>2010-07-25T05:46:41Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
tar&lt;br /&gt;
        Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
split&lt;br /&gt;
        will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
cat&lt;br /&gt;
        does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
$ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
    c - Create an archive. &lt;br /&gt;
    v - Produce lots of output so that we can see any errors. &lt;br /&gt;
    j - Compress using bzip. &lt;br /&gt;
    p - Preserve permissions and ownerships. &lt;br /&gt;
    S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
    f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
    b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
    x - Extract files from an archive. &lt;br /&gt;
    v - Print lots of information about how things are going. &lt;br /&gt;
    j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
    f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53464</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53464"/>
		<updated>2010-07-25T05:46:10Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Managing Large Compressed Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.&lt;br /&gt;
&lt;br /&gt;
    tar&lt;br /&gt;
&lt;br /&gt;
        Tape ARchive, sticks files together end to end and will also compress them. &lt;br /&gt;
&lt;br /&gt;
    split&lt;br /&gt;
&lt;br /&gt;
        will divide an input or file into chunks of an exact size. &lt;br /&gt;
&lt;br /&gt;
    cat&lt;br /&gt;
&lt;br /&gt;
        does the opposite of split so it can be used to reassemble split files. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
$ tar cvjpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The options used here are as follows:&lt;br /&gt;
&lt;br /&gt;
For tar&lt;br /&gt;
&lt;br /&gt;
    c - Create an archive. &lt;br /&gt;
    v - Produce lots of output so that we can see any errors. &lt;br /&gt;
    j - Compress using bzip. &lt;br /&gt;
    p - Preserve permissions and ownerships. &lt;br /&gt;
    S - Handle &amp;quot;sparse&amp;quot; files effectively. &lt;br /&gt;
    f - Specifies a file or output. In this case we use &amp;quot;-&amp;quot; so that we can also use a pipe (i.e. &amp;quot;|&amp;quot; ) to route the output through to the split command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For split&lt;br /&gt;
&lt;br /&gt;
    b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the &amp;quot;.&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ cat arcFilesDir/* | tar xvjf - -C extractedFilesDir&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.&lt;br /&gt;
&lt;br /&gt;
Options for tar in this case are:&lt;br /&gt;
&lt;br /&gt;
    x - Extract files from an archive. &lt;br /&gt;
    v - Print lots of information about how things are going. &lt;br /&gt;
    j - Used with x above, this means uncompress using bzip. &lt;br /&gt;
    f - Used with x above, this specifies where we are getting our data from. In this case standard input. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip / unzip, have very poor Large File support. Part of what spurred this HOWTO into being.&lt;br /&gt;
&lt;br /&gt;
Here is how it all might go together:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls *FilesDir&lt;br /&gt;
arcFilesDir:&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir:&lt;br /&gt;
&lt;br /&gt;
srcFilesDir:&lt;br /&gt;
First.iso  Fourth.iso  Second.iso  Third.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So far, so good. Now lets see if the files are as they should be.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l arcFilesDir/&lt;br /&gt;
total 2687628&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:49 largarchive.aa&lt;br /&gt;
-rw-r--r--  1 root root 1073741824 Jan 21 01:53 largarchive.ab&lt;br /&gt;
-rw-r--r--  1 root root  601946112 Jan 21 01:55 largarchive.ac&lt;br /&gt;
&lt;br /&gt;
Great! Now lets try our extraction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir&lt;br /&gt;
srcFilesDir/&lt;br /&gt;
srcFilesDir/Third.iso&lt;br /&gt;
srcFilesDir/Second.iso&lt;br /&gt;
srcFilesDir/Fourth.iso&lt;br /&gt;
srcFilesDir/First.iso&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/*&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 18:53 srcFilesDir/First.iso&lt;br /&gt;
-rw-r--r--  1 root root  728795136 Jan 20 19:07 srcFilesDir/Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 18:57 srcFilesDir/Second.iso&lt;br /&gt;
-rw-r--r--  1 root root  728563712 Jan 20 19:08 srcFilesDir/Third.iso&lt;br /&gt;
&lt;br /&gt;
extractedFilesDir/srcFilesDir:&lt;br /&gt;
total 2849208&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 18:53 First.iso&lt;br /&gt;
-rw-r--r--  1 root root 728795136 Jan 20 19:07 Fourth.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 18:57 Second.iso&lt;br /&gt;
-rw-r--r--  1 root root 728563712 Jan 20 19:08 Third.iso&lt;br /&gt;
[root@kaliklak root]#&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.&lt;br /&gt;
&lt;br /&gt;
Everything's cool so we are good to go. :-)&lt;br /&gt;
edit Comments on other compression protocols&lt;br /&gt;
&lt;br /&gt;
    zip - Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting. &lt;br /&gt;
    tar - Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools. &lt;br /&gt;
    dar - A &amp;quot;fixed&amp;quot; version of tar. Self splitting is added. Not yet mainstream, though. I'm really itching to try it. :-) Currently however, the -P option seems broken. :-|&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53463</id>
		<title>Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Scripts&amp;diff=53463"/>
		<updated>2010-07-25T05:42:21Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* KDE4 Command Line Trash Can */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Scripts''' are small [[programs]] that are not [[compiled]], but [[interpreter|interpreted]]. They are often written in languages such as [[Perl]], [[PHP]], [[JavaScript]]. See [[programming#interpreted languages|here]] for a list of interpreted languages.&lt;br /&gt;
&lt;br /&gt;
If not specified otherwise, a script is usually written in [[bash]].&lt;br /&gt;
&lt;br /&gt;
= Bash scripting =&lt;br /&gt;
Main article: [[bash tips]]&lt;br /&gt;
&lt;br /&gt;
== Hello world ==&lt;br /&gt;
The minimal bash script that only outputs &amp;quot;hello world&amp;quot; looks like this:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Find out your distribution ==&lt;br /&gt;
Main article: [[find out your distribution]]&lt;br /&gt;
&lt;br /&gt;
The following script tells you what [[distribution]] you have installed on your computer.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 found=0;&lt;br /&gt;
 if [ -e /etc/SuSE-release ]; then echo &amp;quot;You have a SUSE distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/redhat-release ]; then echo &amp;quot;You have a Red Hat distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/fedora-release ]; then echo &amp;quot;You have a Fedora distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/debian-version ]; then echo &amp;quot;You have a Debian, Ubuntu, Kubuntu, Edubuntu or Flubuntu distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if [ -e /etc/slackware-version ]; then echo &amp;quot;You have a SlackWare distro&amp;quot;; export found=1; fi&lt;br /&gt;
 if ! [ $found = 1 ]; then echo &amp;quot;I could not find out your distro&amp;quot;; fi&lt;br /&gt;
It looks if the respective files exist (&amp;lt;tt&amp;gt;if [ -e /etc/SuSE-release ];&amp;lt;/tt&amp;gt;) and prints the distribution they flag (using the [[command]] &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Tonka Script ==&lt;br /&gt;
Changes your console to some other colours.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function tonka {&lt;br /&gt;
&lt;br /&gt;
#   Named &amp;quot;Tonka&amp;quot; because of the colour scheme&lt;br /&gt;
&lt;br /&gt;
local WHITE=&amp;quot;\[\033[1;37m\]&amp;quot;&lt;br /&gt;
local LIGHT_BLUE=&amp;quot;\[\033[1;34m\]&amp;quot;&lt;br /&gt;
local YELLOW=&amp;quot;\[\033[1;33m\]&amp;quot;&lt;br /&gt;
local NO_COLOUR=&amp;quot;\[\033[0m\]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
case $TERM in&lt;br /&gt;
    xterm*|rxvt*)&lt;br /&gt;
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'&lt;br /&gt;
        ;;&lt;br /&gt;
    *)&lt;br /&gt;
        TITLEBAR=&amp;quot;&amp;quot;&lt;br /&gt;
        ;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
PS1=&amp;quot;$TITLEBAR\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\u$LIGHT_BLUE@$YELLOW\h\&lt;br /&gt;
$LIGHT_BLUE)-(\&lt;br /&gt;
$YELLOW\$PWD\&lt;br /&gt;
$LIGHT_BLUE)-$YELLOW-\&lt;br /&gt;
\n\&lt;br /&gt;
$YELLOW-$LIGHT_BLUE-(\&lt;br /&gt;
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \&amp;quot;+%a,%d %b %y\&amp;quot;)\&lt;br /&gt;
$LIGHT_BLUE:$WHITE\\$ $LIGHT_BLUE)-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
PS2=&amp;quot;$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR &amp;quot;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Get your ip ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# get ip&lt;br /&gt;
/sbin/ifconfig $1 | grep inet | awk '{print $2}' | sed 's/^addr://g'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your Internet address if you are behind a [[NAT]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## The -n option retrieves the Internet IP address&lt;br /&gt;
## if you are behind a NAT&lt;br /&gt;
if [ &amp;quot;$1&amp;quot; = &amp;quot;-n&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
  ip=$(lynx -dump http://cfaj.freeshell.org/ipaddr.cgi)&lt;br /&gt;
else&lt;br /&gt;
  if=$1   ## specify which interface, e.g. eth0, fxp0&lt;br /&gt;
  system=$(uname)&lt;br /&gt;
  case $system in&lt;br /&gt;
      FreeBSD) sep=&amp;quot;inet &amp;quot; ;;&lt;br /&gt;
      Linux) sep=&amp;quot;addr:&amp;quot; ;;&lt;br /&gt;
  esac&lt;br /&gt;
  temp=$(ifconfig $if)&lt;br /&gt;
  temp=${temp#*&amp;quot;$sep&amp;quot;}&lt;br /&gt;
  ip=${temp%% *}&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
printf &amp;quot;%s\n&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
### CFAJ ###&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connect to a wireless access point (WPA compatible) ==&lt;br /&gt;
Tested in Ubuntu 8.10&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#removing possible previous temp file&lt;br /&gt;
rm list.temp 2&amp;gt;/dev/null&lt;br /&gt;
&lt;br /&gt;
#scans for wifi connections &amp;amp; isolates wifi AP name&lt;br /&gt;
# thanks to jonjgc for the array solution&lt;br /&gt;
# thanks to ghostdog74 for the AWK suggestion&lt;br /&gt;
&lt;br /&gt;
eval list=( $(sudo iwlist scan 2&amp;gt;/dev/null | awk -F&amp;quot;:&amp;quot; '/ESSID/{print $2}') )&lt;br /&gt;
&lt;br /&gt;
#sets prompt&lt;br /&gt;
PS3=&amp;quot;Choose wifi connection: &amp;quot;&lt;br /&gt;
&lt;br /&gt;
#tests for number of wifi connections, exits if none&lt;br /&gt;
if [ -z &amp;quot;${list[0]}&amp;quot; ]; then&lt;br /&gt;
	clear&lt;br /&gt;
	echo &amp;quot;No available wifi connection&amp;quot;&lt;br /&gt;
	exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#menu of wifi connections&lt;br /&gt;
select item in &amp;quot;${list[@]}&amp;quot;; do&lt;br /&gt;
&lt;br /&gt;
#sets essid as value for WIFI variable and displays information about the AP&lt;br /&gt;
	wifi=$(echo $item)&lt;br /&gt;
&lt;br /&gt;
	sudo iwlist scan 2&amp;gt;/dev/null | sed -n &amp;quot;/$wifi/, +9p&amp;quot; &amp;gt; list.temp&lt;br /&gt;
	echo &amp;quot;$(cat list.temp | sed 's/^[ \t]*//')&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#sets channel as value for CHANNEL variable&lt;br /&gt;
	channel=$(grep Channel: list.temp | sed 's/.*Channel://g')&lt;br /&gt;
&lt;br /&gt;
#test for mode, if mode = master, sets MODE variable to managed&lt;br /&gt;
	mode=$(grep Mode list.temp | sed 's/.*Mode://g')&lt;br /&gt;
	if [ &amp;quot;$mode&amp;quot; == &amp;quot;Master&amp;quot; ]; then&lt;br /&gt;
		mode=&amp;quot;managed&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		clear&lt;br /&gt;
		echo &amp;quot;Cannot connect&amp;quot;&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#tests for encryption key&lt;br /&gt;
	key=$(grep key: list.temp | sed 's/.*key://g')&lt;br /&gt;
	if [ $key == &amp;quot;on&amp;quot; ]; then&lt;br /&gt;
		echo -n &amp;quot;Enter encryption key: &amp;quot;&lt;br /&gt;
		read key&lt;br /&gt;
	fi&lt;br /&gt;
&lt;br /&gt;
#checks encryption algorithm&lt;br /&gt;
	IE=$(grep IE list.temp | sed 's/^ .*IE: \(...\).*/\1/')&lt;br /&gt;
&lt;br /&gt;
#writes to /etc/network/interfaces file for WPA encryption: essid, key, protocols, etc.&lt;br /&gt;
	if [ &amp;quot;$IE&amp;quot; == &amp;quot;WPA&amp;quot; ]; then&lt;br /&gt;
		sudo cp /etc/network/interfaces /etc/network/interfaces.bakup&lt;br /&gt;
		sudo sed -i 's/iface wlan0 inet manual/iface wlan0 inet dhcp/' /etc/network/interfaces&lt;br /&gt;
		sudo sed -i -e &amp;quot;/dhcp/a\wpa-passphrase $key&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-driver wext&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-key-mgmt WPA-PSK&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-proto WPA&amp;quot; \&lt;br /&gt;
	-e &amp;quot;/dhcp/a\wpa-ssid \&amp;quot;$wifi\&amp;quot;&amp;quot; /etc/network/interfaces&lt;br /&gt;
	sudo /etc/init.d/networking restart&lt;br /&gt;
	sudo cp /etc/network/interfaces.bakup /etc/network/interfaces&lt;br /&gt;
	sudo rm /etc/network/interfaces.bakup&lt;br /&gt;
	exit&lt;br /&gt;
&lt;br /&gt;
	else&lt;br /&gt;
&lt;br /&gt;
#sets the wireless configuration for non WPA: essid, channel, mode, key, etc&lt;br /&gt;
		sudo iwconfig wlan0 essid \&amp;quot;&amp;quot;$wifi&amp;quot;\&amp;quot; channel $channel mode $mode key $key&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
		echo &amp;quot;Connecting to: $wifi at channel: $channel, mode: $mode&amp;quot;&lt;br /&gt;
		echo &amp;quot;------------------------------------------------&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#connects to wifi connection&lt;br /&gt;
		sudo dhclient&lt;br /&gt;
		exit&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= KDE4 Command Line Trash Can =&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Script by Jim Collings&lt;br /&gt;
 # Written Sat Jan 30 14:01:38 EST 2010&lt;br /&gt;
 # A simple trash script that handles spaces and integrates properly with KDE4 Trash system.&lt;br /&gt;
 # Handles spaces properly according to every test I've devised so far. &lt;br /&gt;
  &lt;br /&gt;
 set -e&lt;br /&gt;
 &lt;br /&gt;
 TRASHLOC=&amp;quot;$HOME/.local/share/Trash&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 function move_it {&lt;br /&gt;
  COUNTER=0&lt;br /&gt;
  TARGET_BASE_NAME=`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  TARGET_FILE_NAME=&amp;quot;${TRASHLOC}/files/${TARGET_BASE_NAME}&amp;quot;  &lt;br /&gt;
  TARGET_INFO_NAME=&amp;quot;${TRASHLOC}/info/${TARGET_BASE_NAME}&amp;quot;&lt;br /&gt;
  XTENSION=&amp;quot;&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  while [ -e &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot; ]&lt;br /&gt;
  do    &lt;br /&gt;
    let COUNTER+=1&lt;br /&gt;
    XTENSION=&amp;quot;_${COUNTER}&amp;quot;&lt;br /&gt;
  done&lt;br /&gt;
 &lt;br /&gt;
 OLDDIR=`pwd` &lt;br /&gt;
 &lt;br /&gt;
 cd &amp;quot;`dirname &amp;quot;$*&amp;quot;`&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  FULLPATH=`pwd`&lt;br /&gt;
  FULLPATH=&amp;quot;${FULLPATH}/&amp;quot;`/usr/bin/basename &amp;quot;$*&amp;quot;`&lt;br /&gt;
  FULLPATH=`echo &amp;quot;${FULLPATH}&amp;quot; | sed 's/ /%20/g'`&lt;br /&gt;
 &lt;br /&gt;
  cd &amp;quot;${OLDDIR}&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  mv -n &amp;quot;$*&amp;quot; &amp;quot;${TARGET_FILE_NAME}${XTENSION}&amp;quot;&lt;br /&gt;
  echo &amp;quot;[Trash Info]&amp;quot; &amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo &amp;quot;Path=&amp;quot;${FULLPATH} &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot;&lt;br /&gt;
  echo DeletionDate=`date +%Y-%m-%dT%H:%M:%S` &amp;gt;&amp;gt; &amp;quot;${TARGET_INFO_NAME}${XTENSION}.trashinfo&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 until [ -z &amp;quot;$1&amp;quot; ]  # Until all parameters used up...&lt;br /&gt;
 do&lt;br /&gt;
 &lt;br /&gt;
       if [ -d &amp;quot;$1&amp;quot; ]; then #its a directory &lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
       elif [ -f &amp;quot;$1&amp;quot; ];then #its a file&lt;br /&gt;
 	  move_it &amp;quot;$1&amp;quot;&lt;br /&gt;
 	elif [ -h &amp;quot;$1&amp;quot; ];then #its just a link&lt;br /&gt;
 	  rm -f &amp;quot;$1&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
               echo &amp;quot;Error condition: '&amp;quot;&amp;quot;$1&amp;quot;&amp;quot;' not found.&amp;quot; &lt;br /&gt;
               echo &amp;quot;Usage: $0 [Pathnames]&amp;quot;&lt;br /&gt;
               echo &amp;quot;Where [Pathname] is a list of space delimited existing files or directories the current user has permissions for.&amp;quot; &lt;br /&gt;
               echo &amp;quot;So like this: $0 file1 '&amp;quot;&amp;quot;file two with spaces&amp;quot;&amp;quot;' directoryOne '&amp;quot;&amp;quot;directory two with spaces in the name&amp;quot;&amp;quot;' ...&amp;quot; &lt;br /&gt;
               exit 1&lt;br /&gt;
       fi&lt;br /&gt;
 &lt;br /&gt;
       shift&lt;br /&gt;
 &lt;br /&gt;
 done&lt;br /&gt;
                                          &lt;br /&gt;
 exit 0&lt;br /&gt;
&lt;br /&gt;
= Managing Large Compressed Archives =&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[Bash Tips]]&lt;br /&gt;
* [[:Category:Script|Category:Script]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52720</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52720"/>
		<updated>2010-05-26T00:11:36Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Customized Prompts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
==Customized Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of great interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
&lt;br /&gt;
Using the information at the link below, you can colorize your prompt and have it show convenient things like the time of day, date and if you log in to a number of different machines, it might be good to have the name of the machine displayed so you can remember which one you are on. ;-)&lt;br /&gt;
For more on customized prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that your script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52719</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52719"/>
		<updated>2010-05-26T00:11:19Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Customized Prompts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
==Customized Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
&lt;br /&gt;
Using the information at the link below, you can colorize your prompt and have it show convenient things like the time of day, date and if you log in to a number of different machines, it might be good to have the name of the machine displayed so you can remember which one you are on. ;-)&lt;br /&gt;
For more on customized prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that your script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52718</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52718"/>
		<updated>2010-05-26T00:10:43Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Color Prompts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
==Customized Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
&lt;br /&gt;
Using the information at the link below, you can colorize your prompt and have it show convenient things like the time of day, date and if you log in to a number of different machines, it might be good to have the name of the machine displayed so you can remember which one you are on. ;-)&lt;br /&gt;
For more on color prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that your script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52717</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52717"/>
		<updated>2010-05-26T00:05:41Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Return values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
For more on color prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that your script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52716</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52716"/>
		<updated>2010-05-26T00:04:48Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Return values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
For more on color prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that you script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52715</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52715"/>
		<updated>2010-05-26T00:04:21Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Handy To Know */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
For more on color prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52714</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52714"/>
		<updated>2010-05-25T23:56:59Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
== Handy To Know ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that you script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
For more on color prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52713</id>
		<title>Bash tips</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=Bash_tips&amp;diff=52713"/>
		<updated>2010-05-25T23:56:25Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: /* Technologies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
If you type in a rather long and complex [[command]] at the [[command line]], you might want to save that command in a [http://en.wikipedia.org/wiki/Text_file text file], so you can execute it later without having to type the whole long thing in again. If you add a line to the beginning of that file, like &amp;quot;&amp;lt;tt&amp;gt;#!/bin/bash&amp;lt;/tt&amp;gt;&amp;quot; (a so-called &amp;quot;[[shebang]]&amp;quot; line), and then make the file executable with the &amp;lt;tt&amp;gt;[[chmod]]&amp;lt;/tt&amp;gt; command, you've just created a shell script.&lt;br /&gt;
&lt;br /&gt;
Here's an example shell script:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # Any line that starts with a hash, besides the shebang line, is a comment.&lt;br /&gt;
 echo &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You run the [[shell script]] just like any other [[executable]]. Some folks create a &amp;lt;tt&amp;gt;bin&amp;lt;/tt&amp;gt; directory in their home directory within which to place their scripts. Others drop them in &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some key points to keep in mind about shell scripts:&lt;br /&gt;
* They execute their commands, line by line, just as if you'd typed them in yourself at the command line.&lt;br /&gt;
* The commands in the script run in a subshell of the shell from which you executed the script.&lt;br /&gt;
* If you want the script to affect your [[pwd|present working directory]] or [[environment variables]], source it with &amp;lt;tt&amp;gt;.&amp;amp;nbsp;scriptname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Don't put spaces around equal signs.&lt;br /&gt;
&lt;br /&gt;
You can check out the [[bash]] page and you'll also find lots of info in the [http://www.tldp.org/LDP/abs/html Advanced Bash-Scripting Guide].&lt;br /&gt;
&lt;br /&gt;
= Technologies =&lt;br /&gt;
&lt;br /&gt;
== Handy Things To Know ==&lt;br /&gt;
&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long. Basically, when ever a return value that isn't 0 comes back from a command, it stops the script. Be careful though, this is not necessarily an error condition. The '''grep''' command, for example, returns 1 when it doesn't find anything... but then maybe that is what you are counting on! The consequence will be that you script will stop and you may not immediately understand why.&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colorize the output of the '''ls''' command.&lt;br /&gt;
For more on color prompts, check out [http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt at ArchWiki].&lt;br /&gt;
&lt;br /&gt;
== Using quotes ==&lt;br /&gt;
Quotation marks, either double quotes (&amp;quot;) or single quotes ('), are often needed in shell scripts to pass arguments that have spaces or other special characters.  The two quotes have slightly different meanings.  Single quotes protect the exact text they enclose.&lt;br /&gt;
&lt;br /&gt;
Inside double quotes, the dollar sign ($) is still special, so shell variables and other $ expressions are interpreted, as is the backquote (`) used for command substitution.  Lastly, the backslash (\) is special in double quotes, so be cautious.  Some examples and the shell output of each:&lt;br /&gt;
&lt;br /&gt;
 $ echo 'The location of the shell is stored in $BASH'&lt;br /&gt;
 The location of the shell is stored in $BASH&lt;br /&gt;
 $ echo &amp;quot;The location of the shell is $BASH&amp;quot;&lt;br /&gt;
 The location of the shell is /bin/bash&lt;br /&gt;
 $ echo '\\'&lt;br /&gt;
 \\&lt;br /&gt;
 $ echo &amp;quot;\\&amp;quot;&lt;br /&gt;
 \&lt;br /&gt;
&lt;br /&gt;
== Return values ==&lt;br /&gt;
The return value, also known as error code, delivers the exiting state of the most recently executed program. It is defined to be 0 in case no error happened. It is stored in the variable $?:&lt;br /&gt;
 scorpio:~ # echo &amp;quot;hello world&amp;quot;&lt;br /&gt;
 hello world&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # ls /doesNotExist&lt;br /&gt;
 /bin/ls: /doesNotExist: No such file or directory&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 2&lt;br /&gt;
&lt;br /&gt;
The [ ] operators deliver 0 if they contain a true expression, 1 if they contain a false expression:&lt;br /&gt;
 scorpio:~ # [ 5 = 5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5 = 6 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ #&lt;br /&gt;
Here, [ is a [[command]]. A command requires a blank behind it - thus the following error is very common:&lt;br /&gt;
 scorpio:~ # [5 = 6]&lt;br /&gt;
 bash: [5: command not found&lt;br /&gt;
Also the ] requires a blank in front of it:&lt;br /&gt;
 scorpio:~ # [ 5 = 6]&lt;br /&gt;
 bash: [: missing `]'&lt;br /&gt;
The &amp;quot;=&amp;quot; sign requires a blank in front of it and after it. Otherwise, the bash only sees &amp;quot;something&amp;quot; within the brackets, and that is true (0), while &amp;quot;nothing&amp;quot; is false (1):&lt;br /&gt;
 scorpio:~ # [ aoei ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ 5=5 ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # [ ]&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
 scorpio:~ # true&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 0&lt;br /&gt;
 scorpio:~ # false&lt;br /&gt;
 scorpio:~ # echo $?&lt;br /&gt;
 1&lt;br /&gt;
You can hand over your own error codes with the command exit. This command will exit from the current process. As the ( ) signs spawn out an own process, you can do the following:&lt;br /&gt;
 scorpio:~ # (exit 5); echo $?&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
== Conditions ==&lt;br /&gt;
Conditions are handled with the [[if]] command, using the form &lt;br /&gt;
if &amp;lt;expression&amp;gt;&lt;br /&gt;
then command1&lt;br /&gt;
else command2&lt;br /&gt;
fi&lt;br /&gt;
&amp;quot;fi&amp;quot; as the reverse of &amp;quot;if&amp;quot;, closes the loop.&lt;br /&gt;
bash allows you to substitute newlines with &amp;quot;;&amp;quot;, so the following form is also legal:&lt;br /&gt;
if &amp;lt;expression&amp;gt;; then command1; else command2; fi&lt;br /&gt;
Example:&lt;br /&gt;
 scorpio:~ # if true; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 yes&lt;br /&gt;
 scorpio:~ # if false; then echo &amp;quot;yes&amp;quot;; else echo &amp;quot;no&amp;quot;; fi&lt;br /&gt;
 no&lt;br /&gt;
You can omit the else-branch:&lt;br /&gt;
 scorpio:~ # if [ 5 = 5 ]; then echo &amp;quot;five is five&amp;quot;; fi&lt;br /&gt;
 five is five&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
In this case, bash replaces $name with its content. That means, we get an error if $name is empty:&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ $name = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
 scorpio:~ # if [  = Thorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 bash: [: =: unary operator expected&lt;br /&gt;
To overcome this problem, one can add an &amp;quot;x&amp;quot; to the left and to the right:&lt;br /&gt;
 scorpio:~ # export name=Thorsten&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 it's you&lt;br /&gt;
 scorpio:~ # export name=&lt;br /&gt;
 scorpio:~ # if [ x$name = xThorsten ]; then echo &amp;quot;it's you&amp;quot;; fi&lt;br /&gt;
 scorpio:~ # &lt;br /&gt;
&lt;br /&gt;
== Negations ==&lt;br /&gt;
You can invert true/false values with the ! operator:&lt;br /&gt;
 $ ! true&lt;br /&gt;
 $ echo $?&lt;br /&gt;
 1&lt;br /&gt;
That helps you if you want to do &amp;quot;not&amp;quot;-statements:&lt;br /&gt;
 if ! [[grep]] &amp;quot;network error&amp;quot; /var/log/messages&lt;br /&gt;
 then [[echo]] &amp;quot;There is no network error mentioned in the syslog&amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
The ! is just like a [[command]] with arguments, that's why it is important to have a space behind it:&lt;br /&gt;
 $ !true&lt;br /&gt;
 bash: !true: event not found&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
You can [[loop]] on a condition:&lt;br /&gt;
 while [ 5 = 5 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
 until [ 5 = 6 ]; do echo &amp;quot;This never stops&amp;quot;; done&lt;br /&gt;
&lt;br /&gt;
== $-variables ==&lt;br /&gt;
:$! : PID of last [[process]] that has been started in the [[background]] (e.g. firefox &amp;amp;)&lt;br /&gt;
:$? : return value of last [[command]]&lt;br /&gt;
&lt;br /&gt;
== Counting ==&lt;br /&gt;
 x=0; ((x++))&lt;br /&gt;
 x=0; x=$((x+1))&lt;br /&gt;
 x=0; let x=$x+1&lt;br /&gt;
 for (( x=0; x&amp;lt;10; x++ )) ; do echo $x ; done&lt;br /&gt;
&lt;br /&gt;
 for x in $(seq 0 9); do echo $x; done &lt;br /&gt;
 x=0; x=$(expr $x + 1) &lt;br /&gt;
 x=0; x=$(echo $x + 1|bc)&lt;br /&gt;
 x=4; x=$(echo scale=5\; $x / 3.14|bc)&lt;br /&gt;
&lt;br /&gt;
The first four demonstrate Bash' internal counting mechanisms, these will not use external programs and are thus safe (and fast).&lt;br /&gt;
The last four use external programs. [[bc]], as used in the last two examples, is the only one that supports numbers with decimals. For adding, subtracting and multiplying, you don't have to do anything special, but for division you need to specify the number of digits to keep (default is none) using the 'scale=n' line. &lt;br /&gt;
&lt;br /&gt;
== Combining multiple conditions of if statements ==&lt;br /&gt;
AND:&lt;br /&gt;
 if((a==1 &amp;amp;&amp;amp; b==2))&lt;br /&gt;
OR:&lt;br /&gt;
 if(( a!=1 || b&amp;gt;10 ))&lt;br /&gt;
&lt;br /&gt;
== Conditional execution == &lt;br /&gt;
As stated above, you can do something like&lt;br /&gt;
 scorpio:~ # if (( 5 == 5 &amp;amp;&amp;amp; 6 == 6 )); then echo &amp;quot;five is five and six is six&amp;quot;; fi&lt;br /&gt;
 five is five and six is six&lt;br /&gt;
We call 5 == 5 the left term and 6 == 6 the right term. [[Bash]] first evaluates the left term and if it is true, it evaluates the right term. If both are true, the result is true, otherwise, the result is false (boolean logic). It is an interesting effect that, if the left term is false, the right term is not even evaluated - the result will be false in any case. That means, if we replace the terms by commands, the right command will only be executed if the left command succeeded. One can use this effect:&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /tmp/dir &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 the command succeeded&lt;br /&gt;
 scorpio:~ # ls &amp;gt; /proc/cmdline &amp;amp;&amp;amp; echo &amp;quot;the command succeeded&amp;quot;&lt;br /&gt;
 /bin/ls: write error: Input/output error&lt;br /&gt;
 scorpio:~ #           &lt;br /&gt;
In the above example, bash tells you if the command succeded. The right command is &amp;lt;i&amp;gt;conditionally executed&amp;lt;/i&amp;gt;.&lt;br /&gt;
Considering a famous saying, you can even program a bird using this technology:&lt;br /&gt;
 eat || die&lt;br /&gt;
This line says &amp;quot;eat or die&amp;quot; which is very useful if you want a program to exit in case it cannot perform a certain operation:&lt;br /&gt;
 touch /root/test || exit&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
You can define functions for [[structured]] [[programming]]. It is also possible to hand over parameters to a function.&lt;br /&gt;
Example:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 # This program calculates the square of a given number &lt;br /&gt;
 &lt;br /&gt;
 function square \&lt;br /&gt;
 {&lt;br /&gt;
   echo &amp;quot;The square of your number is &amp;quot;&lt;br /&gt;
   echo $((a*a))&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 echo &amp;quot;Input a number&amp;quot;&lt;br /&gt;
 read a&lt;br /&gt;
 square $a&lt;br /&gt;
&lt;br /&gt;
= UseCases =&lt;br /&gt;
&lt;br /&gt;
== Renaming a set of files ==&lt;br /&gt;
The following example will rename all files ending in .jpeg to end in .jpg&lt;br /&gt;
 $ for file in *.jpeg; do mv $file ${file%.jpeg}.jpg; done&lt;br /&gt;
&lt;br /&gt;
[[mmv]] is a really nifty tool for doing this sort of thing more flexibly too.  The [[rename]] command also provides similar functionality, depending on your linux [[distribution]].&lt;br /&gt;
&lt;br /&gt;
If you have a load of files in all capital letters (common if you unzip old [[DOS]] programs for instance), you can use&lt;br /&gt;
 $ for file in *; do mv $file $(echo $file | tr upper: lower:); done&lt;br /&gt;
to make all the files in the current directory lowercase.&lt;br /&gt;
&lt;br /&gt;
== Get your IP address ==&lt;br /&gt;
A [[bash]] example to get your IP address using http://www.whatismyip.com:&amp;lt;br /&amp;gt;&lt;br /&gt;
 lynx -dump http://www.whatismyip.com | grep -i &amp;quot;Your IP is&amp;quot; | awk '{ print $4; }'&lt;br /&gt;
&lt;br /&gt;
Or use this:&lt;br /&gt;
 $ ifconfig ppp0 | awk '/inet addr/{print $2}' | cut -d: -f2&lt;br /&gt;
&lt;br /&gt;
Or this:&lt;br /&gt;
 $ ifconfig ppp0 | sed -rn 's/^.*inet addr:([^ ]+).*$/\1/p'&lt;br /&gt;
Note that ppp0 stands for the first point-to-point-protocol device which is usually a modem. If you are using an ethernet adapter instead, replace ppp0 with eth0. You can also leave it out all together to list all the addresses associated with your computer.&lt;br /&gt;
&lt;br /&gt;
== Converting several wav files to mp3 ==&lt;br /&gt;
This statement will convert all .wav files in a directory to mp3  (assuming you already have the [http://lame.sourceforge.net/ lame] mp3 encoding [[package]] [[install]]ed):&lt;br /&gt;
 for i in *.wav; do lame -h $i [[&amp;amp;&amp;amp;]] rm $i; done&lt;br /&gt;
The double ampersand prevents rm from deleting files that weren't successfully converted.&lt;br /&gt;
&lt;br /&gt;
== Full file name ==&lt;br /&gt;
Prints the full filename removing ./ and ../ and adding `pwd` if necessary.&lt;br /&gt;
&lt;br /&gt;
'''fqn.sh'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# return the full filename, removing ./ ../ adding `pwd` if necessary&lt;br /&gt;
&lt;br /&gt;
FILE=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# file		dot relative&lt;br /&gt;
# ./file	dot relative&lt;br /&gt;
# ../file	parent relative&lt;br /&gt;
# /file		absolute&lt;br /&gt;
while true; do&lt;br /&gt;
	case &amp;quot;$FILE&amp;quot; in&lt;br /&gt;
		( /* ) 		&lt;br /&gt;
		# Remove /./ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |fgrep &amp;quot;/./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		# Remove /../ inside filename:&lt;br /&gt;
		while echo &amp;quot;$FILE&amp;quot; |grep &amp;quot;/[^/][^/]*/\\.\\./&amp;quot; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; do&lt;br /&gt;
			FILE=`echo &amp;quot;$FILE&amp;quot; | sed &amp;quot;s/\\/[^/][^/]*\\/\\.\\.\\//\\//&amp;quot;`&lt;br /&gt;
		done&lt;br /&gt;
		echo &amp;quot;$FILE&amp;quot;&lt;br /&gt;
		exit 0&lt;br /&gt;
		;;&lt;br /&gt;
		&lt;br /&gt;
		(*)&lt;br /&gt;
		FILE=`pwd`/&amp;quot;$FILE&amp;quot;&lt;br /&gt;
		;;&lt;br /&gt;
	esac&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resolving a link ==&lt;br /&gt;
This little script follows symbolic links wherever they may lead and prints the ultimate filename (if it exists!) (note - it uses the previous script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# prints the real file pointed to by a link&lt;br /&gt;
# usage: $0 link&lt;br /&gt;
&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
LINK=`fqn &amp;quot;$1&amp;quot;`&lt;br /&gt;
while [ -h &amp;quot;$LINK&amp;quot; ]; do&lt;br /&gt;
	DIR=`dirname &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	# next link is everything from &amp;quot;-&amp;gt; &amp;quot;&lt;br /&gt;
	LINK=`ls -l &amp;quot;$LINK&amp;quot; |sed &amp;quot;s/^.*-&amp;gt; //&amp;quot;`&lt;br /&gt;
&lt;br /&gt;
	LINK=`cd &amp;quot;$DIR&amp;quot;; fqn &amp;quot;$LINK&amp;quot;`&lt;br /&gt;
	if [ ! -e &amp;quot;$LINK&amp;quot; ]; then&lt;br /&gt;
		echo &amp;quot;\&amp;quot;$ORIG_LINK\&amp;quot; is a broken link: \&amp;quot;$LINK\&amp;quot; does not exist&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
		exit 1&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$LINK&amp;quot;&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a lot simpler, and just as useful (but doesn't do dead link checking)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ORIG_LINK=&amp;quot;$1&amp;quot;&lt;br /&gt;
TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
while test -n &amp;quot;$TMP&amp;quot;; do&lt;br /&gt;
    ORIG_LINK=&amp;quot;$TMP&amp;quot;&lt;br /&gt;
    TMP=&amp;quot;$(readlink &amp;quot;$ORIG_LINK&amp;quot;)&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;$ORIG_LINK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Viewing a file according to its type ==&lt;br /&gt;
I save this as a script called &amp;lt;tt&amp;gt;v&amp;lt;/tt&amp;gt; and it is my universal viewing script - it can be extended to any kind of file and to use your favourite tools for each type of file. It uses the &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; utility to determine what sort of file it is and then invokes the correct tool. It automatically adapts to being used on the system console or under X.&lt;br /&gt;
&lt;br /&gt;
(note - this uses a prior script &amp;lt;tt&amp;gt;fqn.sh&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/sh&lt;br /&gt;
# View files based on the type of the first one:&lt;br /&gt;
# Relies partly on 'less' to invoke an appropriate viewer.&lt;br /&gt;
# Make sure than you have this set:&lt;br /&gt;
# LESSOPEN=&amp;quot;|lesspipe.sh %s&amp;quot;&lt;br /&gt;
&lt;br /&gt;
FIRST=&amp;quot;$1&amp;quot;&lt;br /&gt;
FULL=`fqn $FIRST`&lt;br /&gt;
&lt;br /&gt;
# if we are being piped to, just run less&lt;br /&gt;
[ -z &amp;quot;$FIRST&amp;quot; -o ! -r &amp;quot;$FIRST&amp;quot; ] &amp;amp;&amp;amp; exec less &amp;quot;$@&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# some file types beyond what /usr/bin/lesspipe.sh handles:&lt;br /&gt;
case &amp;quot;$FIRST&amp;quot; in&lt;br /&gt;
  *.cpio.bz2) bunzip2 -c $1 | cpio -ctv 2&amp;gt;/dev/null |less; exit ;;&lt;br /&gt;
  *.cpio) cpio -ctv $1 2&amp;gt;/dev/null |less; exit;;&lt;br /&gt;
esac&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TYPE=`file -L -i &amp;quot;$FIRST&amp;quot;  2&amp;gt;/dev/null | \&lt;br /&gt;
  awk '{len=length(&amp;quot;'&amp;quot;$FIRST&amp;quot;'&amp;quot;)+ 2; $0=substr($0, len); print $1;}'`&lt;br /&gt;
echo &amp;quot;Type=\&amp;quot;$TYPE\&amp;quot;&amp;quot;&lt;br /&gt;
case &amp;quot;$TYPE&amp;quot; in&lt;br /&gt;
    image/jpeg | image/tiff | image/gif | image/x-xpm | image/*)&lt;br /&gt;
        xzgv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/pdf) &lt;br /&gt;
	XPDFGEOM=`xdpyinfo |awk '/dimensions/ {print $2}'| \&lt;br /&gt;
          awk -Fx '{printf(&amp;quot;%dx%d+0+0&amp;quot;, 0.60*$1, $2-35)}'`&lt;br /&gt;
	xpdf -geometry $XPDFGEOM -z width &amp;quot;$@&amp;quot; &lt;br /&gt;
	;;&lt;br /&gt;
    application/postscript)&lt;br /&gt;
        gv &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
    application/msword)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then antiword &amp;quot;$@&amp;quot; | \&lt;br /&gt;
          less; else soffice &amp;quot;$@&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    text/html)&lt;br /&gt;
        if [ -z &amp;quot;$DISPLAY&amp;quot; ] ; then lynx &amp;quot;$@&amp;quot;; else dillo &amp;quot;$FULL&amp;quot; &amp;amp; fi ;;&lt;br /&gt;
    audio/mpeg)&lt;br /&gt;
        mpg123 &amp;quot;$FIRST&amp;quot; ;;&lt;br /&gt;
    *)&lt;br /&gt;
        less &amp;quot;$@&amp;quot; ;;&lt;br /&gt;
esac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Finding the 50 largest directories ==&lt;br /&gt;
 du -S / | sort -nr | head -n50&lt;br /&gt;
&lt;br /&gt;
== Auto-generating a shebang line ==&lt;br /&gt;
 (echo -n '#!'; which perl; tail -n+2 foo) &amp;gt; bar&lt;br /&gt;
This will print &amp;quot;#!&amp;quot; and the path to &amp;lt;tt&amp;gt;perl&amp;lt;/tt&amp;gt;, then everything except the first line (the original shebang) of the file &amp;lt;tt&amp;gt;foo&amp;lt;/tt&amp;gt;; and redirect all that to go into a file &amp;lt;tt&amp;gt;bar&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This is really meant for use in install scripts; obviously you know where perl is on your system, but not necessarily on anybody else's system  (though &amp;lt;tt&amp;gt;/usr/bin/perl&amp;lt;/tt&amp;gt; is a safe guess). But you know bash is always at &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt;. So, instead of just saying in the documentation &amp;quot;change the first line .....&amp;quot;, you can write a little shell script that puts the correct shebang line in the file and copies it to &amp;lt;tt&amp;gt;/usr/local/bin&amp;lt;/tt&amp;gt;. Then, put this script in a .tar.gz file with your perl script and any documentation.&lt;br /&gt;
&lt;br /&gt;
== Creating an audio CD from .mp3 files ==&lt;br /&gt;
This little script requires the mpg123 and [http://cdrdao.sourceforge.net/ cdrdao] packages.  It uses mpg123 to create a .wav file from each mp3 in the current directory, and builds up a &amp;quot;TOC&amp;quot; file (Table Of Contents) as it goes along, using the &amp;amp;amp;&amp;amp;amp; notation to be sure only to include successfully-converted files.  Finally, it starts writing the CD.&lt;br /&gt;
&lt;br /&gt;
The TOC file is given a name based on the PID, and is placed in the current directory.  Neither it nor the .wav files will be deleted at the end of the script, so you can always burn another copy of the CD if you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
tocfile=&amp;quot;cd_$$.toc&amp;quot;&lt;br /&gt;
echo &amp;quot;CD_DA&amp;quot; &amp;gt; $tocfile&lt;br /&gt;
for i in *mp3&lt;br /&gt;
 do wav=&amp;quot;`basename $i .mp3`.wav&amp;quot;&lt;br /&gt;
    mpg123 -w$wav $i\&lt;br /&gt;
    &amp;amp;&amp;amp; echo -en &amp;gt;&amp;gt;$tocfile &amp;quot;TRACK AUDIO\nFILE \&amp;quot;$wav\&amp;quot; 0\n&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo -e &amp;quot;TOC file still available at $tocfile&amp;quot;&lt;br /&gt;
cdrdao write $tocfile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: in the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt; statement, you might think at first sight that&lt;br /&gt;
it should be &amp;lt;tt&amp;gt;for i in *.mp3&amp;lt;/tt&amp;gt;; but Linux doesn't care about&lt;br /&gt;
filename extensions at all.  * will match a . character; therefore, *mp3&lt;br /&gt;
will match everything ending in mp3 or .mp3.  Those characters are unlikely&lt;br /&gt;
to be found on the end of anything but an mp3 file.&lt;br /&gt;
&lt;br /&gt;
== Portable Indirection ==&lt;br /&gt;
Sometimes you need to use the value of a variable whose name is held in another variable. This is indirection. For example:&lt;br /&gt;
  for V in PATH LD_LIBRARY_PATH; do echo ${!V}; done&lt;br /&gt;
but that isn't portable to older shells, eg. the old Bourne shell. A portable way is to use the following instead of &amp;lt;tt&amp;gt;${!V}&amp;lt;/tt&amp;gt;:&lt;br /&gt;
  `eval echo \\$&amp;quot;$V&amp;quot;`&lt;br /&gt;
It's not pretty but at least it works on nearly all Unixes. &lt;br /&gt;
&lt;br /&gt;
[ someone said - &amp;quot;It does require that the variable be exported.&amp;quot; Actually no. It works without exporting V on bash and on Solaris sh ]&lt;br /&gt;
&lt;br /&gt;
== Matching Curly Brackets ==&lt;br /&gt;
&lt;br /&gt;
If you indent your C, Perl or PHP code in what is commonly called &amp;quot;K&amp;amp;R style&amp;quot;, which is to say something like this&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# nested loop example&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
        print &amp;quot;$i : $j &amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
i.e.  where the opening curly bracket appears on the same line as the flow-control keyword  (if, while &amp;amp;c.)  and everything up to, but not including, the closing curly bracket is indented, then you may find this useful.  I came up with it out of necessity, and thought it was just too important not to share.  All it does is display the lines with a { but no following }  (in Perl, these denote associative array indexes)  or a } with no preceding {.  In other words, just the opening and closing lines of loops, not the content.  This can help you to spot those annoying missing-bracket errors.&lt;br /&gt;
&lt;br /&gt;
 [[awk]] '/({[^}]*$)|(^[^{]*})/{print}' ''foo''&lt;br /&gt;
&lt;br /&gt;
Replace ''foo'' with the filename to be examined.  Or, of course, you can omit the filename and use the command in a [[pipe]]line.&lt;br /&gt;
&lt;br /&gt;
The above example would appear as&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt;= 6; ++$i) {&lt;br /&gt;
    for ($j = 0; $j &amp;lt;= $i; ++$j) {&lt;br /&gt;
    };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== rpminfo ==&lt;br /&gt;
This is a small script that prints useful info about an [[rpm]] package.  It was inspired by the ability of [[less]] to give almost useful info about an rpm file through &amp;lt;tt&amp;gt;lesspipe.sh&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 echo INFORMATION: ; rpm -qi $* ; echo&lt;br /&gt;
 echo REQUIRES: ; rpm -qR $* ; echo&lt;br /&gt;
 echo PROVIDES: ; rpm -q --provides $* ; echo&lt;br /&gt;
 echo FILELIST: ; rpm -qlv $*&lt;br /&gt;
&lt;br /&gt;
Save it to a file called &amp;lt;tt&amp;gt;rpminfo&amp;lt;/tt&amp;gt; in your [[path]] and [[chmod]] it so it's executable.  It is often useful to [[pipe]] the output to [[less]], as in the examples below.&lt;br /&gt;
&lt;br /&gt;
To get info on an installed package, you can just give the package name like:&lt;br /&gt;
 rpminfo XFree86 |less&lt;br /&gt;
For a package file that you have just downloaded, give the &amp;lt;tt&amp;gt;-p&amp;lt;/tt&amp;gt; [[command options|command option]], just like &amp;lt;tt&amp;gt;rpm&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 rpminfo -p XFree86-4.1.0-25.i386.rpm |[[less]]&lt;br /&gt;
&lt;br /&gt;
== Finding All Files That Start With a '.' (period) ==&lt;br /&gt;
To list all the [[file]]s in your current [[directory]] whose file names start with a '.')&lt;br /&gt;
 [[ls]] -A | [[grep]] -E &amp;quot;^\.\.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following command will copy, overwriting existing files, the hidden contents of the present directory (files and directories that start with a period) into the folder, '/tmp/testing' (assuming that you've already made the target directory):&lt;br /&gt;
&lt;br /&gt;
(Useful for backing up hidden files and directories in your home folder; be sure to change the target directory to something more sensible, though.)&lt;br /&gt;
&lt;br /&gt;
 [[cp]] -vfr `ls -A | grep -E &amp;quot;^\.\.*&amp;quot;` -t /tmp/testing/&lt;br /&gt;
&lt;br /&gt;
== Connecting to a wireless access point through Bash (no encryption key)==&lt;br /&gt;
To connect to a [[wireless]] access point through the shell, first determine the designation of your wireless adapter:&lt;br /&gt;
&lt;br /&gt;
 [[cat]] /proc/net/wireless&lt;br /&gt;
&lt;br /&gt;
This should give you a similar output:&lt;br /&gt;
&lt;br /&gt;
 Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE&lt;br /&gt;
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22&lt;br /&gt;
 wlan0: 0000   57.  -53.  -87.       0      0      0      0      0        0&lt;br /&gt;
&lt;br /&gt;
In this case the designation of the wireless adapter is '''wlan0'''.  Now you can proceed to the next step, scanning the available wireless points:&lt;br /&gt;
&lt;br /&gt;
 [[sudo]] iwlist wlan0 scan&lt;br /&gt;
&lt;br /&gt;
An example of the output you should get:&lt;br /&gt;
&lt;br /&gt;
 wlan0     Scan completed :&lt;br /&gt;
          Cell 01 - Address: 00:1D:8B:52:2C:9C&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=57/70  Signal level=-53 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;costa reina&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=000000208e5ce217&lt;br /&gt;
                    Extra: Last beacon: 110ms ago&lt;br /&gt;
                    IE: Unknown: 000B636F737461207265696E61&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 02 - Address: 00:1C:A2:B0:DC:54&lt;br /&gt;
                    Channel:1&lt;br /&gt;
                    Frequency:2.412 GHz (Channel 1)&lt;br /&gt;
                    Quality=36/70  Signal level=-74 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2B0DC54&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000ddf7c3e4&lt;br /&gt;
                    Extra: Last beacon: 3240ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132423044433534&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030101&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
          Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:on&lt;br /&gt;
                    ESSID:&amp;quot;FASTWEB-1-001CA2C3DFCC&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
                    IE: Unknown: 0016464153545745422D312D303031434132433344464343&lt;br /&gt;
                    IE: Unknown: 010882848B960C121824&lt;br /&gt;
                    IE: Unknown: 030106&lt;br /&gt;
                    IE: Unknown: 2A0104&lt;br /&gt;
                    IE: Unknown: 32043048606C&lt;br /&gt;
                    IE: WPA Version 1&lt;br /&gt;
                        Group Cipher : TKIP&lt;br /&gt;
                        Pairwise Ciphers (1) : TKIP&lt;br /&gt;
                        Authentication Suites (1) : PSK&lt;br /&gt;
                    IE: Unknown: 0706495420010E10&lt;br /&gt;
&lt;br /&gt;
The important bits of information are: '''ESSID''', '''Channel''', '''Encryption key''', and '''Mode'''.  ESSID is the name given to the wireless point.  Now you select which one you want to connect to.  Let's say you want to connect to an access point that has the following information:&lt;br /&gt;
&lt;br /&gt;
 Cell 03 - Address: 00:1C:A2:C3:DF:CC&lt;br /&gt;
                    Channel:6&lt;br /&gt;
                    Frequency:2.437 GHz (Channel 6)&lt;br /&gt;
                    Quality=32/70  Signal level=-78 dBm  &lt;br /&gt;
                    Encryption key:off&lt;br /&gt;
                    ESSID:&amp;quot;connect here&amp;quot;&lt;br /&gt;
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s&lt;br /&gt;
                              9 Mb/s; 12 Mb/s; 18 Mb/s&lt;br /&gt;
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s&lt;br /&gt;
                    Mode:Master&lt;br /&gt;
                    Extra:tsf=00000000087f0232&lt;br /&gt;
                    Extra: Last beacon: 2850ms ago&lt;br /&gt;
&lt;br /&gt;
The command to connect would be:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] iwconfig wlan0 essid &amp;quot;connect here&amp;quot; mode managed channel 6 key off&lt;br /&gt;
&lt;br /&gt;
Followed by:&lt;br /&gt;
&lt;br /&gt;
  [[sudo]] dhclient&lt;br /&gt;
&lt;br /&gt;
*Please note that if there is an encryption key encrypted with WPA, things become slightly more complicated.  You can refer to a [http://ubuntuforums.org/showthread.php?t=1342833 script] I wrote for WPA encrypted connections.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
* [[ShellScripts]]&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
	<entry>
		<id>https://wiki.linuxquestions.org/index.php?title=User:Jcllings&amp;diff=52700</id>
		<title>User:Jcllings</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxquestions.org/index.php?title=User:Jcllings&amp;diff=52700"/>
		<updated>2010-05-24T03:58:31Z</updated>

		<summary type="html">&lt;p&gt;Jcllings: Created page with 'This is my BASH scriptorium and the place where I keep notes on writing them. BASH, is the Borne Again SHell. BASH is a programming language that one writes to execute commands o…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is my BASH scriptorium and the place where I keep notes on writing them. BASH, is the Borne Again SHell. BASH is a programming language that one writes to execute commands on a Linux or Unix system. The official BASH website is [http://www.gnu.org/software/bash here]. BASH is an interpreted language which means it runs on a virtual machine like Java does. Unfortunately, BASH isn't all that cross-platform. For the most part, it is for Unix only. Mac's do come with it, by the way. One can run BASH on Windows but you need [http://www.cygwin.com/ Cygwin] for that particular trick. Cygwin can be a little tricky to install, for Windows software but if you're careful to follow the instructions, it shouldn't be a problem. Documentation is fair for Cygwin.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
While BASH is the grand Unix standard, it isn't the best language to be writing scripts in these days. It is important for any Unix person to be able to read and trace through BASH, however, because you may need these skills if something goes wrong on your machine. To my knowledge, Ruby is the scripting language currently in favor amongst my peers. I should probably learn it someday.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:47, January 24, 2010 (UTC)&lt;br /&gt;
==Trashy Scripting==&lt;br /&gt;
&lt;br /&gt;
Moved to: [http://wiki.linuxquestions.org/wiki/Scripts LinuxQuestions Wiki - Scripts]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Scripting Tips==&lt;br /&gt;
Using '''set -e''' in your script will cause it to drop dead on the first error. This is a good thing when manipulating an operating system, file system or if the script otherwise runs very long.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:47, January 24, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Color Prompts==&lt;br /&gt;
See the links section below for a marvellous article on colourized BASH prompts.&lt;br /&gt;
&lt;br /&gt;
Tip: '''dircolors''' is a bash command of interest for folks who want to colourize the output of the '''ls''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:46, January 24, 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
*[http://wiki.archlinux.org/index.php/Color_Bash_Prompt Color Bash Prompt - ArchWiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Jcllings|Jcllings]] 06:46, January 24, 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Jcllings</name></author>
	</entry>
</feed>