Difference between revisions of "Linux Commandline Stuff"

From Robert-Depot
Jump to: navigation, search
(du to list size of subdirectories)
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
Linux Commandline Stuff
 
Linux Commandline Stuff
 +
 +
=uuencode=
 +
==make random text file==
 +
*put this in <code>make_random.sh</code>:
 +
<pre>head -c 100000 < /dev/random | uuencode -m - | tail -n 100000 > out.txt</pre>
 +
*see http://old.roberttwomey.com/uuencode/index.php
 +
 +
==encode image as text==
 +
*turning image to text: <pre>cat urs\ fischer\ 3.jpg | uuencode -m -o ursfischer.txt usfischer.jpg</pre>
 +
==decode text as image==
 +
*extract image: <pre>uudecode ursfischer_alt.txt </pre>
  
 
= du to list size of subdirectories =  
 
= du to list size of subdirectories =  
Line 53: Line 64:
  
 
= Rsync =  
 
= Rsync =  
 +
==rsync personae data to minibeast==
 +
*from Persona directory on local: <code>rtwomeys-work-object-2:Personae rtwomey$ rsync -avz --stats --progress . 192.168.1.31:/Volumes/Cistern/Personae/</code>
 
==rsync to transfer files to server ==
 
==rsync to transfer files to server ==
 
*local current directory to home/pictures directory:  
 
*local current directory to home/pictures directory:  
Line 141: Line 154:
 
</pre>
 
</pre>
  
= finding things with ls and grep =
+
= finding things with grep =
 +
== finding files recursively 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:
 
<pre>ls -laR . | grep -b30 "scale_signal.o" </pre>
 
<pre>ls -laR . | grep -b30 "scale_signal.o" </pre>
 +
 +
== finding text within files recursively with grep ==
 +
<pre>grep -Hrn 'HTS_Pauses' meghan_festival/</pre>
  
 
= forwarding localhost mysql to a remote machine =
 
= forwarding localhost mysql to a remote machine =
Line 162: Line 179:
 
=use sed to search and replace a file in place=
 
=use sed to search and replace a file in place=
 
<pre>sed -i .bak 's/na_play/play/g' bin/prompt_them </pre>
 
<pre>sed -i .bak 's/na_play/play/g' bin/prompt_them </pre>
 +
=gphoto2=
 +
*http://photolifetoys.blogspot.com/2012/08/control-your-camera-with-gphoto2-via.html

Latest revision as of 09:22, 16 March 2013

<<< back to Wiki Home

Linux Commandline Stuff

uuencode

make random text file

  • put this in make_random.sh:
head -c 100000 < /dev/random | uuencode -m - | tail -n 100000 > out.txt

encode image as text

  • turning image to text:
    cat urs\ fischer\ 3.jpg | uuencode -m -o ursfischer.txt usfischer.jpg

decode text as image

  • extract image:
    uudecode ursfischer_alt.txt 

du to list size of subdirectories

  • list size of subdirectories in human readable format: du -skh*
  • to sort by size: du -skh * | sort

add remote git repository

adding dxarts git repository

 505  git clone git@code.dxarts.washington.edu:gitosis-admin.git
 506  ls
 507  cd gitosis-admin/
 508  ls
 509  ll
 510  vi gitosis.conf 
 511  git status
 512  git add -u
 513  git status
 514  git commit
 515  git commit
 516  git status
 517  git push

  • create empty local repository
cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master
  • adding remote repository and pushing to it:

 664  git status
 665  git remote add origin git@code.dxarts.washington.edu:oftwomey.git
 666  git status
 667  git push origin master
 668  git
 669  ls
 670  git push

remove page numbers in place with perl

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

Rsync

rsync personae data to minibeast

  • from Persona directory on local: rtwomeys-work-object-2:Personae rtwomey$ rsync -avz --stats --progress . 192.168.1.31:/Volumes/Cistern/Personae/

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 grep

finding files recursively 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" 

finding text within files recursively with grep

grep -Hrn 'HTS_Pauses' meghan_festival/

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 

use sed to search and replace a file in place

sed -i .bak 's/na_play/play/g' bin/prompt_them 

gphoto2