Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tips:threelinestip [2008/08/31 23:59]
a
tips:threelinestip [2015/01/07 07:47] (current)
mrizvic run local/remote webserver with python
Line 41: Line 41:
    $ diff -c prog.c.old prog.c > prog.patch    $ diff -c prog.c.old prog.c > prog.patch
    $ patch < prog.patch    $ patch < prog.patch
 +
  
 =====  Printing network traffic ===== =====  Printing network traffic =====
Line 49: Line 50:
    % sudo tcpdump -Atq -s 0 -i en1 host foobar.com    % sudo tcpdump -Atq -s 0 -i en1 host foobar.com
  
 +===== Couting openfiles per user =====
 +
 +   # lsof | grep ' root ' | awk '{print $NF}' | sort | wc -l
 +
 +Of course, if you want to drop the count and show the actual processes, you can run:
 +
 +   # lsof | grep ' root '
 +
 +===== How to check is service is tcpwrapper enable =====
 +   # ldd `which sshd` | grep -i libwrap
 +
 +or
 +
 +   # strings `which sshd` | grep -i libwrap
 +
 +
 +===== Comparing files & taking some action based on outcome =====
 +**Method 1**
 +<code>
 +cmp -s file1 file2 || {
 +  # do something
 +}
 +</code>
 +**Method 2**
 +<code>
 +cmp -s file1 file2
 +if [ $? = 1 ]
 +then
 +  # do something
 +fi
 +</code>
 +
 +===== IPv4 parsing / sorting =====
 +
 +   egrep '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
 +
 +and
 +
 +   sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
 +
 + 
 +
 +===== finding a string in a "live" stream =====
 +
 +tail -f filename |grep --line-buffered  STRING
 +
 +
 +===== Local/remote webserver =====
 +
 +Serve files on port 8080 for anybody from the directory from where you start this command: 
 +
 +<code bash|>
 +:;while [ $? -eq 0 ];do nc -vlp 8080 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed 's/[^a-z0-9_.-]//gi'`;h="HTTP/1.0";o="$h 200 OK\r\n";c="Content";if [ -z $f ];then($e $o;ls|(while $r n;do if [ -f "$n" ]; then $e "<a href=\"/$n\">`ls -gh $n`
 +";fi;done););elif [ -f $f ];then $e "$o$c-Type: `file -ib $f`\n$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done
 +</code>
 +
 +===== Local/remote webserver #2 (python) =====
 +
 +Serve files on port 8000 for anybody from the directory from where you start this command: 
 +
 +python 2.x
 +<code bash|>
 +python -m SimpleHTTPServer 
 +</code>
 +
 +python 3.x
 +<code bash|>
 +python -m http.server
 +</code>
 +
 +If other port is desired (for example 9000) then add port number to the command:
 +<code bash|>
 +python -m SimpleHTTPServer 9000
 +</code>
 +
 +===== resolving IP Addresse (nmap) =====
 +
 +<code bash|>
 +nmap -sL $1 2>/dev/null |
 +perl -ne 'print unless /^Host [\d.]+ /' |
 +grep 'not scanned' |
 +cut -d ' ' -f 2,3 |
 +sed -e 's/\(.*\) (\(.*\))/\2 resolves to \1/'
 +</code>
 +
 +output:
 +<code>
 +198.133.219.10 resolves to fed.cisco.com
 +198.133.219.11 resolves to asp-web-sj-1.cisco.com
 +198.133.219.12 resolves to asp-web-sj-2.cisco.com
 +198.133.219.13 resolves to fedtst.cisco.com
 +198.133.219.14 resolves to www.netimpactstudy.com
 +198.133.219.15 resolves to deployx-sj.cisco.com
 +198.133.219.16 resolves to contact-sj1.cisco.com
 +198.133.219.17 resolves to scc-sj-1.cisco.com
 +198.133.219.18 resolves to scc-sj-2.cisco.com
 +198.133.219.19 resolves to scc-sj-3.cisco.com
 +198.133.219.20 resolves to jmckerna-test.cisco.com
 +198.133.219.21 resolves to events.cisco.com
 +198.133.219.22 resolves to bam-prod-1.cisco.com
 +198.133.219.23 resolves to redirect.cisco.com
 +198.133.219.25 resolves to www.cisco.com
 +198.133.219.26 resolves to partners.cisco.com
 +</code>
 +
 +
 +===== Linux Get Hardware Serial Number From Command Line  =====
 +   dmidecode |grep -i serial
 +
 +===== Convert pdf to jpg =====
 +
 +  for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none \
 +    -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
 +
 +===== rename upper to lowercase in bash ====
 +
 +   for x in *.JPG; do y=$(echo $x | tr '[A-Z]' '[a-z]'); echo $y; mv $x $y; done
 +===== Find duplicate files in Linux =====
 +
 +Let’s say you have a folder with 5000 MP3 files you want to check for duplicates. Or a directory containing thousands of EPUB files, all with different names but you have a hunch some of them might be duplicates. You can cd your way in the console up to that particular folder and then do a
 +
 +<code>
 +find -not -empty -type f -printf “%s\n” | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
 +</code>
 +
 +This will output a list of files that are duplicates, according tot their HASH signature.
 +Another way is to install fdupes and do a
 +
 +   fdupes -r ./folder > duplicates_list.txt
 +
 +The -r is for recursivity. Check the duplicates_list.txt afterwards in a text editor for a list of duplicate files.
 +
 +===== Linux - Top 10 CPU-hungry apps =====
 +
 +   ps -eo pcpu,pid,args | sort -k 1 -r | head -10
 +
 +===== Create static mirror of dynamic web site (ex. Wordpress) =====
 +
 +
 +   wget --mirror -w 2 -p -r -np --html-extension --convert-links -R xmlrpc.php,trackback <URL>
 +   
 +===== Find processes utilizing high memory in human readable format ======
 +
 +   ps -eo size,pid,user,command | sort -rn | head -5 | awk '{ hr[1024^2]="GB"; hr[1024]="MB"; for (x=1024^3; x>=1024; x/=1024) { if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break } } } { printf ("%-6s %-10s ", $2, $3) } { for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'
tips/threelinestip.1220219982.txt.gz · Last modified: 2009/05/25 00:34 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready