Wednesday, September 12, 2012

Linux commands I can not afford to lose



HTTP Requests -
GET - wget blog.kasunbg.org


GET request - curl --request GET http://localhost:9763/services/StudentService.StudentServiceHttpEndpoint/student/kasun




POST request - curl -d "age=01&name=kasun&subjects=unix" http://localhost:9763/services/StudentService.StudentServiceHttpEndpoint/student/kasun


SOAP POST request to a SOAP 1.2 endpoint -
curl -d '<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><p:echoString xmlns:p="http://echo.services.core.carbon.wso2.org"><in>kasun</in></p:echoString></soapenv:Body></soapenv:Envelope>'   -H "Content-Type: application/soap+xml"    http://localhost:9443/services/echo


Other commands - PUT, DELETE


SCP - 
scp -r -P 2200 /home/kasun/docbook-webhelp/  kasun@example.com:/home/kasun/public_html/
rsync


grep -ri "example" ../../ --include "*xml" -A5 -B5
find ../.. -iname "*xml"
tail -f target/carbontmp/wso2as-4.1.0-SNAPSHOT/repository/logs/wso2carbon.log


Replace a given word with a new one from a set of files - Here, I'm replacing the word 'oldWord' with 'newWord' of a set of files that ends with .xml in the current folder.

find . -name "*.xml" -exec sed -i "s/oldWord/newWord/g" '{}' \;


to replace the word "<webXml>${basedir}/../../web.xml</webXml>" with newWord. Note the escape charater (\) before $ and /. Used : for easy writing.

find . -name "pom.xml" -exec sed -i "s:<webXml>\${basedir}/../../web.xml<\/webXml>:newWord:g" '{}' \;


Find running Java processes - ps ax | grep java
Kill a process - kill -9 <process-id>

Subversion
Get only the modified files - svn status | egrep  "^M"
Create patch - svn diff > my-contribution.patch
Apply patch - patch -p0 < my-contribution.patch

Extract files -
tar -xjf my-archive.tar.bz2
tar -xzf my-archive.tar.gz
unzip my-archive.zip

Get the disk usage of a directory, sorted - du -s ./* | sort -g
Shutdown - sudo shutdown -h now
Reboot - reboot

The archive reader - file-roller
PDF reader - evince
Partition editor - gparted

Find the VGA driver in the machine - lspci -v | grep -i vga
Find attached USB devices - lsusb

Only copy a set of symbolic links in the current directory, and copy those to a separate folder. I did this in Ubuntu.
cp `l -1 | grep -ri @ | grep -ri "[^@]*" -o` ../my-symlinks/ -P

l -1 | grep -ri @ | grep -ri "[^@]*" -o - Selects outputs the file names of the symlinks. Then we copy it using cp with the parameter -P. -P means that cp won't follow the symlinks.

Bash for loop - in one line

for file in `fn pom.xml`; do echo $file; done

iPhone

Mount in Linux/Ubuntu

ifuse <mount_point> --root   - Only add --root if the phone is jail broken. Only jail broken phones can access the root / location.
ifuse /mnt/iPhone --root