Quickies

[categories] [index] [all (527)] [latest]

Unix
  1. data.txt

    380 EUR-USD
    105 EUR-CHF
    200 CHF-USD
    

    command

    $ awk '/EUR/ {print $1}' data.txt
    

    result

    380
    105
    
  2. rsync -av --delete /src/ /dst/
    
  3. stuff

    $ tar cjvf my_dir.tar.bz2 my_dir
    

    unstuff

    $ tar xjvf my_dir.tar.bz2
    
  4. Set the 4th byte of /tmp/test to 0xFF:

    $ printf '\xFF' | dd bs=1 seek=4 conv=notrunc of=/tmp/test
    
  5. $ sudo ifconfig en0 ether YOUR_NEW_ADDRESS_HERE
    
    $ ifconfig en0
    en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
            ether YOUR_NEW_ADDRESS_HERE 
            media: autoselect (none) status: inactive
            supported media: none autoselect 10baseT/UTP <half-duplex> ...
    
  6. $ touch -t 201206100230.00 x.txt
    
    $ ls -l x.txt 
    -rw-r--r--  1 nst  staff  0 Jun 10 02:30 x.txt
    
  7. $ iconv -c -f UTF-8 -t LATIN1 utf8.txt > latin1.txt
    
  8. $ openssl sha1 my_image.dmg
    
  9. $ nc -z -u time.euro.apple.com 123
    Connection to time.euro.apple.com port 123 [udp/ntp] succeeded!
    
  10. Google Chrome > bookmarks.html > raw URLs

    grep -o 'http[^\"]*' bookmarks.html
    
  11. On the client machine

    Generate keys (without passphrase)

    $ ssh-keygen -t rsa
    

    Copy the public key on the server

    $ scp ~/.ssh/id_rsa.pub nst@10.0.1.2:~/new_key
    

    On the server machine

    $ cat ~/new_key >> ~/.ssh/authorized_keys 
    $ rm new_key
    
  12. $ man -t ls | pstopdf -i -o ls.pdf
    
  13. $ date -ur 1234567890
    Fri Feb 13 23:31:30 UTC 2009
    
  14. $ tr '[:upper:]' '[:lower:]' < $1 > $2
    
  15. $ wc -l `find . -name "*.py" | awk '{print $1}'`
    
  16. cloc can't count the lines properly in multi-line Objective-C strings.

    It counts two lines instead of three here:

    NSString *s = "/* \
    x \
    */";
    

    The best way I can find is to use the cpp preprocessor:

    $ /usr/bin/cpp -fpreprocessed -P MyClass.m | grep -cve '^\s*$'
    
  17. $ dd if=/dev/urandom of=random.dat bs=1k count=128
    
  18. $ enscript --color --language=html -Epython --output=file.html file.py
    
  19. or any other header:

    $ curl -H "Cookie: KEY=VALUE" URL
    
  20. $ curl -u USER:PASSWORD URL
    
  21. $ curl -F "KEY=VALUE" URL
    
  22. $ curl -k URL
    
  23. data.txt

    <option>A</option>
    <option>B</option>
    <option>C</option>
    

    extract contents with cut

    $ cat data.txt | cut -d ">" -f 2 | cut -d "<" -f 1
    

    A
    B
    C

  24. $ ./hello
    Hello world
    
    $ xxd hello > hello.hex
    
    $ xxd -r hello.hex > hello2
    
    $ chmod hello2
    
    $ ./hello2
    Hello world
    

    Use -p for dumping and reloading a file without addresses.

  25. $ xxd -p hello
    
    $ hexdump -ve '1/1 "%.2x"' hello
    
    $ od -v -t x1 -An hello |tr -d '\n '
    
    $ od -t x4 -v hello
    
  26. $ cat *.m | sort | uniq -c | sort
    
  27. $ my_program > out.txt 2>&1 &
    
  28. $ file Base
    Base: Mach-O universal binary with 2 architectures
    Base (for architecture x86_64): Mach-O 64-bit executable x86_64
    Base (for architecture i386):   Mach-O executable i386
    
    $ lipo Base -extract i386 -output Base32
    
    $ file Base32
    Base32: Mach-O universal binary with 1 architecture
    
  29. $ find . -exec grep "my_string" '{}' \; -print
    

    or

    $ grep "$1" * -Ri
    

    useful with an alias

    $ alias ffind="grep $1 * -Ri"
    
  30. $ find . -name "*.txt" -print
    
  31. $ cd -
    
  32. $ egrep '.{6,}' data.txt
    
  33. strings digests

    MD5

    $ echo "asd" | md5
    e07910a06a086c83ba41827aa00b26ed
    

    now without digesting the trailing NUL

    $ md5 -s "asd"
    MD5 ("asd") = 7815696ecbf1c96e6894b779456d330e
    

    SHA

    $ echo "asd" | shasum -a 256
    dc460da4ad72c482231e28e688e01f2778a88ce31a08826899d54ef7183998b5  -
    

    -a may be 1 (default), 224, 256, 384, 512

    files digests

    $ echo "asd" > asd.txt
    

    MD5

    $ openssl dgst -md5 asd.txt
    MD5(asd.txt)= e07910a06a086c83ba41827aa00b26ed
    

    SHA

    $ openssl dgst -sha256 asd.txt
    SHA256(asd.txt)= dc460da4ad72c482231e28e688e01f2778a88ce31a08826899d54ef7183998b5
    
  34. $ history|awk '{a[$2]++ }END{for(i in a){print a[i]" "i}}'|sort -rn|head
    159 svn
    112 rm
    53 cd
    38 python2.5
    26 open
    12 ls
    9 python
    7 pdflatex
    6 whois
    6 locate
    
  35. $ lsof -i -a -p 99340
    
  36. $ sudo fs_usage -f filesys -w
    
  37. $ ncftp
    > open -u ******** -p ******** ftp.seriot.ch
    
  38. . R W X
    1 0 0 1
    2 0 1 0
    3 0 1 1
    4 1 0 0
    5 1 0 1
    6 1 1 0
    7 1 1 1
    
  39. $ du -c -h -s *
    184M    Books
    9.0G    Conferences
     20K    toto.csv
    
  40. $ wget -O - --post-data="login=0000000000&password=0000000000" "https://wifi.free.fr/Auth"
    
  41. $ ./xxx >> xxx.logs 2>&1
    
  42. $ ./screenshooter &
    $ jobs
    $ disown %1
    $ exit
    

    or

    $ (screenshooter &)
    
  43. $ man ls | col -bx > ls.txt
    
  44. $ man -f python
    Inline::Python(3pm)      - Write Perl subs and classes in Python
    pydoc(1)                 - the Python documentation tool
    python(1)                - an interpreted, interactive, object-oriented programming language
    python(1), pythonw(1)    - an interpreted, interactive, object-oriented programming language
    pythonw(1)               - run python script allowing GUI
    pythonw(1)               - run python script with GUI
    python2.7(1), python(1)  - an interpreted, interactive, object-oriented programming language
    
  45. $ df -k
    
  46. Into 15 lines chunks:

    $ split -l 15 text_file.txt text_file
    $ cat text_file* > text_file.txt
    

    Into 5 MB blocks:

    $ split -b 5m binary_file
    $ cat binary_file* > binary_file
    
  47. $ kill -STOP <PID>
    $ kill -CONT <PID>
    
  48. ssh stb@192.168.0.210 <<EOT
    touch test_file
    EOT
    exit 0
    
  49. $ find . -name "*.txt" -print | xargs zip -qr archive.zip