×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles
    in:

    Unix/Usefull Commands: Difference between revisions

    Content added Content deleted
    imported>DrOwl
    No edit summary
    imported>DrOwl
    (added first ver of Move Selected Files with find and tar)
     
    (One intermediate revision by one other user not shown)
    Line 1: Line 1:
    just a quick dump of some usefull unix commands
    just a quick dump of some usefull [[unix]] commands


    ==List the top ten largest files==
    ==List the top ten largest files==


    du -sk * | sort -rn | head -10
    [[du]] -sk * | sort -rn | head -10


    == nslookup ==
    == nslookup ==
    nslookup will return infomation about domain names.
    [[nslookup]] will return infomation about domain names.


    nslookup
    nslookup
    Line 14: Line 14:


    == Host ==
    == Host ==
    host will return infomation about domain names.
    [[host]] will return infomation about domain names.


    host domain name
    host domain name
    Line 38: Line 38:
    Dig gets infomations from DNS
    Dig gets infomations from DNS


    dig @{servers NS} {server} [axfr|MX|NS|any]
    [[dig]] @{servers NS} {server} [axfr|MX|NS|any]


    axfr is a full zone tranfeer
    axfr is a full zone tranfeer
    Line 100: Line 100:
    ==List processes and ports:-==
    ==List processes and ports:-==


    ps -e -o pid= | xargs -i pfiles {} | xargs -i perl -e ' if
    [[ps]] -e -o pid= | xargs -i pfiles {} | xargs -i perl -e ' if
    (@ARGV[0]=~/^\d+.*$|port/){if (@ARGV[0]!~/mode/) {print @ARGV[0]."\n"}}' "{}"
    (@ARGV[0]=~/^\d+.*$|port/){if (@ARGV[0]!~/mode/) {print @ARGV[0]."\n"}}' "{}"


    Line 109: Line 109:
    ==Recursively chgrp:-==
    ==Recursively chgrp:-==


    find . -group 501 -exec chgrp 500 {} \;
    [[find]] . -group 501 -exec chgrp 500 {} \;


    ==Grep recursively ASCII files only:-==
    ==Grep recursively ASCII files only:-==
    Line 122: Line 122:
    ==Copying files from a remote machine without scp:-==
    ==Copying files from a remote machine without scp:-==


    ssh <user>@<remote> "cat /foo/bar/random.tar.gz" | cat >/local/dir/random.tar.gz
    [[ssh]] <user>@<remote> "cat /foo/bar/random.tar.gz" | cat >/local/dir/random.tar.gz


    ==Move Selected Files with find and tar==

    This command is quite nice if you want to move file/dir's around a system preserving there directory tree and permissions.
    I have made this to output to a temporary file first that you can then check on and run after. (you could of course remove the 'echo' and the move would happen right away)
    The 'E' flag in the first tar is a Solaris specific command and will need to be removed if you are running on Linux. (it is used to work with files larger then 8G and be more precise about time stamps)

    this fist example will just copy the files/dir's:

    for x in $(find . -type d -name "[1234].[0-9]*" -prune) ; do echo "tar cpEf - ${x} | (cd archive/ && tar xfp -)" ; done > /var/tmp/TEMP-ARCHIVE-COPY

    this second example will delete the files/dir's after the copy:

    for x in $(find . -type d -name "[1234].[0-9]*" -prune) ; do echo "tar cpEf - ${x} | (cd archive/ && tar xfp - && cd .. && rm -rf ${x} )" ; done > /var/tmp/TEMP-ARCHIVE-MOVE


    After running the above you can then less the output 'vi /var/tmp/TEMP-ARCHIVE-COPY', to check only the right files/dir's have been found,
    then run the file 'bash /var/tmp/TEMP-ARCHIVE-COPY'



    [[Category:Unix]]

    Latest revision as of 13:03, 22 July 2010

    just a quick dump of some usefull unix commands

    List the top ten largest files[edit]

    du -sk * | sort -rn | head -10

    nslookup[edit]

    nslookup will return infomation about domain names.

    nslookup

    nslookup -d {server}
    


    Host[edit]

    host will return infomation about domain names.

    host domain name


    -t querytype

                    Allows you to specify a particular querytype of information
                    to be looked up.  The arguments are defined in the man page
                    for named(8).  Currently-supported types include: ``a,
                    ``ns, ``md, ``mf, ``cname, ``soa, ``mb, ``mg,
                    ``mr, ``null, ``wks, ``ptr, ``hinfo, ``minfo,
                    ``mx, ``uinfo, ``uid, ``gid, ``unspec. Additional-
                    ly, the wildcard, which may be written as either ``any or
                    ``*, can be used to specify any (all) of the above types.
                    Types must be given in lower case.  Note that the default is
                    to look first for ``a, and then ``mx, except that if the
                    verbose option is turned on, the default is only ``a. The
                    ``-t option is particularly useful for filtering informa-
                    tion returned by host; see the explanation of the ``-l op-
                    tion, below, for more information.
    

    dig[edit]

    Dig gets infomations from DNS

    dig @{servers NS} {server} [axfr|MX|NS|any]

    axfr is a full zone tranfeer

    any will retreave every thing it can


    example of finding out about a domain name[edit]

    $ host -t NS microsoft.com
    microsoft.com name server ns3.msft.net.
    microsoft.com name server ns4.msft.net.
    microsoft.com name server ns5.msft.net.
    microsoft.com name server ns1.msft.net.
    microsoft.com name server ns2.msft.net.
    
    $ dig @ns3.msft.net microsoft.com any
    
    ; <<>> DiG 9.3.2 <<>> @ns3.msft.net microsoft.com any
    ; (1 server found)
    ;; global options:  printcmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 259
    ;; flags: qr aa rd; QUERY: 1, ANSWER: 12, AUTHORITY: 0, ADDITIONAL: 5
    
    ;; QUESTION SECTION:
    ;microsoft.com.                 IN      ANY
    
    ;; ANSWER SECTION:
    microsoft.com.          3600    IN      A       207.46.232.182
    microsoft.com.          3600    IN      A       207.46.197.32
    microsoft.com.          172800  IN      NS      ns4.msft.net.
    microsoft.com.          172800  IN      NS      ns5.msft.net.
    microsoft.com.          172800  IN      NS      ns1.msft.net.
    microsoft.com.          172800  IN      NS      ns2.msft.net.
    microsoft.com.          172800  IN      NS      ns3.msft.net.
    microsoft.com.          3600    IN      SOA     dns.cp.msft.net. msnhst.microsoft.com. 2007010701 300 600 2419200 3600
    microsoft.com.          3600    IN      MX      10 mailb.microsoft.com.
    microsoft.com.          3600    IN      MX      10 mailc.microsoft.com.
    microsoft.com.          3600    IN      MX      10 maila.microsoft.com.
    microsoft.com.          3600    IN      TXT     "v=spf1 mx include:_spf-a.microsoft.com include:_spf-b.microsoft.com include:_spf-c.microsoft.com include:_spf-ssg.microsoft.com ~all"
    
    ;; ADDITIONAL SECTION:
    ns4.msft.net.           3600    IN      A       207.46.66.126
    ns5.msft.net.           3600    IN      A       65.55.238.126
    ns1.msft.net.           3600    IN      A       207.68.160.190
    ns2.msft.net.           3600    IN      A       65.54.240.126
    ns3.msft.net.           3600    IN      A       213.199.144.151
    
    ;; Query time: 12 msec
    ;; SERVER: 213.199.144.151#53(213.199.144.151)
    ;; WHEN: Mon Jan  8 04:25:11 2007
    ;; MSG SIZE  rcvd: 502
    


    Ill try to add info about waht all this means.


    List processes and ports:-[edit]

    ps -e -o pid= | xargs -i pfiles {} | xargs -i perl -e ' if
    (@ARGV[0]=~/^\d+.*$|port/){if (@ARGV[0]!~/mode/) {print @ARGV[0]."\n"}}' "{}"
    

    Rename files with 'tr':-[edit]

    for i in *.xml; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
    
    

    Recursively chgrp:-[edit]

    find . -group 501 -exec chgrp 500 {} \;
    

    Grep recursively ASCII files only:-[edit]

    find . -type f -print -exec file {} \; | grep ASCII | awk -F: '{print $1}'
    | xargs -i grep --with-filename searchstring {}
    

    Sum memory usage of process:-[edit]

    ps -aux | grep java | awk '{sum = sum + $5} END {print sum}'
    

    Copying files from a remote machine without scp:-[edit]

    ssh <user>@<remote> "cat /foo/bar/random.tar.gz" | cat >/local/dir/random.tar.gz
    


    Move Selected Files with find and tar[edit]

    This command is quite nice if you want to move file/dir's around a system preserving there directory tree and permissions. I have made this to output to a temporary file first that you can then check on and run after. (you could of course remove the 'echo' and the move would happen right away) The 'E' flag in the first tar is a Solaris specific command and will need to be removed if you are running on Linux. (it is used to work with files larger then 8G and be more precise about time stamps)

    this fist example will just copy the files/dir's:

    for x in $(find . -type d -name "[1234].[0-9]*" -prune) ; do echo "tar cpEf - ${x} | (cd archive/ && tar xfp -)" ; done > /var/tmp/TEMP-ARCHIVE-COPY
    

    this second example will delete the files/dir's after the copy:

    for x in $(find . -type d -name "[1234].[0-9]*" -prune) ; do echo "tar cpEf - ${x} | (cd archive/ && tar xfp - && cd .. && rm -rf ${x} )" ; done > /var/tmp/TEMP-ARCHIVE-MOVE
    


    After running the above you can then less the output 'vi /var/tmp/TEMP-ARCHIVE-COPY', to check only the right files/dir's have been found, then run the file 'bash /var/tmp/TEMP-ARCHIVE-COPY'

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.