Difference between revisions of "Linux Commandline Stuff"

From Robert-Depot
Jump to: navigation, search
Line 1: Line 1:
 
[[Home | <<< back to Wiki Home]]
 
[[Home | <<< back to Wiki Home]]
  
== Linux Commandline Stuff ==
+
Linux Commandline Stuff =
=== remove page numbers in place with perl ===
+
= remove page numbers in place with perl =
  
 
<code> perl -pi -e "s/p+\s+\d+(-\d*)*\.|p+\d+(-\d*)*\.//g" reading.txt </code>
 
<code> perl -pi -e "s/p+\s+\d+(-\d*)*\.|p+\d+(-\d*)*\.//g" reading.txt </code>
  
=== rsync to transfer files to server ===
+
= Rsync =
 +
==rsync to transfer files to server ==
 
*local current directory to home/pictures directory:  
 
*local current directory to home/pictures directory:  
 
<code>rsync -avz --stats --progress Pictures roberttwomey.com:~/pictures/</code>
 
<code>rsync -avz --stats --progress Pictures roberttwomey.com:~/pictures/</code>
Line 19: Line 20:
 
*grab documents from online backup:
 
*grab documents from online backup:
 
<code>rsync -n -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/Documents/dxarts473_s11/ Documents/</code>
 
<code>rsync -n -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/Documents/dxarts473_s11/ Documents/</code>
==== rsync push.sh ====
+
=== rsync push.sh ===
 
with optional delete
 
with optional delete
 
<pre>
 
<pre>
Line 57: Line 58:
 
</pre>
 
</pre>
  
==== rsync pull.sh ====
+
=== rsync pull.sh ===
  
 
<pre>
 
<pre>
Line 94: Line 95:
 
</pre>
 
</pre>
  
=== finding things with ls and grep ===
+
= finding things with ls and grep =
 
* find this filename in a recursive search and show previous 30 lines of result:
 
* find this filename in a recursive search and show previous 30 lines of result:
 
<code>ls -laR . | grep -b30 "scale_signal.o" </code>
 
<code>ls -laR . | grep -b30 "scale_signal.o" </code>
  
=== forwarding localhost mysql to a remote machine ===
+
= forwarding localhost mysql to a remote machine =
 
* do this to connect to 192.168.0.39 for instance:
 
* do this to connect to 192.168.0.39 for instance:
 
<code>ssh -f -L 3306:localhost:3306 rtwomey@192.168.0.39 sleep 10</code>
 
<code>ssh -f -L 3306:localhost:3306 rtwomey@192.168.0.39 sleep 10</code>
Line 106: Line 107:
 
ssh -fNg -L 3306:localhost:3306 rtwomey@192.168.1.191
 
ssh -fNg -L 3306:localhost:3306 rtwomey@192.168.1.191
 
</code>
 
</code>
=== grabbing a website with wget ===
+
= grabbing a website with wget =
 
*grab a website recursively
 
*grab a website recursively
 
<code> wget -r --level=1 http://www.ppc.sas.upenn.edu/ppquestionnaires.htm </code>
 
<code> wget -r --level=1 http://www.ppc.sas.upenn.edu/ppquestionnaires.htm </code>

Revision as of 12:02, 26 September 2012

<<< back to Wiki Home

Linux Commandline Stuff =

remove page numbers in place with perl

perl -pi -e "s/p+\s+\d+(-\d*)*\.|p+\d+(-\d*)*\.//g" reading.txt

Rsync

rsync to transfer files to server

  • local current directory to home/pictures directory:

rsync -avz --stats --progress Pictures roberttwomey.com:~/pictures/

  • local directory to current directory:

rsync -avz --stats --progress /Volumes/BOOTCAMP/Users/rtwomey/Documents/ .

  • local directory to server backup:

rsync -h -e ssh -avz --stats --progress ./Movies/* b393466@hanjin.dreamhost.com:~/Movies/

rsync -e ssh -avz --stats --progress ./Documents USER@SERVER.dreamhost.com:~/

  • server backup to local directory:

rsync -e ssh -avz --stats --progress USER@SERVER.dreamhost.com:~/Documents .

  • grab documents from online backup:

rsync -n -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/Documents/dxarts473_s11/ Documents/

rsync push.sh

with optional delete

#!/bin/bash

echo name of script is $0
echo first argument is $1

if [ $# -lt 1 ]
then
        echo "usage: $0 [DIRECTORY]"
        echo "  or"
        echo "       $0 -n [DIRECTORY]"
        echo "  or "
        echo "       $0 -n --delete [DIRECTORY]"
        exit
fi


if [ $1 = "-n" ]
then
        if [ $2 = "--delete" ]
        then
                cmd="rsync -n --delete -h -e ssh -avz --stats --progress $3 b393466@hanjin.dreamhost.com:~/$3"
        else
                cmd="rsync -n -h -e ssh -avz --stats --progress $2 b393466@hanjin.dreamhost.com:~/$2"
        fi
elif [ $1 = "--delete" ]
then
        cmd="rsync --delete -h -e ssh -avz --stats --progress $2 b393466@hanjin.dreamhost.com:~/$2"
else
        cmd="rsync -h -e ssh -avz --stats --progress $1 b393466@hanjin.dreamhost.com:~/$1"
fi

echo $cmd
$cmd

rsync pull.sh

#!/bin/bash

echo name of script is $0
echo first argument is $1

if [ $# -lt 1 ]
then
	echo "usage: $0 [DIRECTORY]"
	echo "  or"
	echo "       $0 -n [DIRECTORY]"
        echo "  or "
        echo "       $0 -n --delete [DIRECTORY]"
	exit
fi

if [ $1 = "-n" ]
then
        if [ $2 = "--delete" ]
        then
                cmd="rsync -n --delete -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/$3 $3"
        else
                cmd="rsync -n -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/$2 $2"
        fi
elif [ $1 = "--delete" ]
then
        cmd="rsync --delete -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/$2 $2"
else
        cmd="rsync -h -e ssh -avz --stats --progress b393466@hanjin.dreamhost.com:~/$1 $1"
fi

echo $cmd
$cmd

finding things with ls and grep

  • find this filename in a recursive search and show previous 30 lines of result:

ls -laR . | grep -b30 "scale_signal.o"

forwarding localhost mysql to a remote machine

  • do this to connect to 192.168.0.39 for instance:

ssh -f -L 3306:localhost:3306 rtwomey@192.168.0.39 sleep 10

  • tunnelMySql.sh:

ssh -fNg -L 3306:localhost:3306 rtwomey@192.168.1.191

grabbing a website with wget

  • grab a website recursively

wget -r --level=1 http://www.ppc.sas.upenn.edu/ppquestionnaires.htm

Open Files from Command Line (OS X)

  • open -e solipsist\ dialog\ 20120610\ storefront.txt