Tuesday, September 30, 2008

Common Linux/OS X Commands for the Java Developer

Common linux/OS X commands for the Java Developer: Find a file find . -name "filenamepattern" Find a file and execute something on it find . -name "filenamepattern" -exec somecommand {} \; (where {} is the filename) Recursively look for text in files showing the 5 lines before and after the match and printing the pathname of the found file find . -name "filenamepattern" -exec grep -H -A 5 -B 5 sometext {} \; Recursively delete files and directories matching pattern find . -name "filenamepattern" -exec rm -rf {} \; Ctrl-A/Ctrl-E Using ctrl-A to go to the beginning of a line, and ctrl-E to go to the end of a line. Other stuff is: Get OS version uname -a cat /etc/redhat-release (fedora/redhat/centos only) What is Listening on a Port netstat -a | grep LISTEN netstat -a | grep 8009 (replace 8009 with a port number) nmap What has the socket open/what has connection to certain server open netstat --program (doesn't always work) netstat -e -e (really verbose. includes user, etc.) Get system info cat /proc/meminfo cat /proc/cpuinfo dmesg | grep CPU mem free (number next to mem is only physical memory, for memory details [http://www.linuxhq.com/guides/TLK/mm/memory.html] [http://www.linuxforums.org/forum/misc/4154-where-see-processors-speed-ram-memory.html]) What processes are running/what is eating up CPU ps auxf top Java 5 JVM stuff (but use kill instead) vmstat UDP dump tcpdump udp -vvv -w /tmp/filename Find problems with system clock/NTP grep -B 5 -A 5 ticks /var/log/dmesg Other stuff for coherence debugging getconf GNU_LIBPTHREAD_VERSION Making a file become empty echo > file Debugging Tangosol issues: See here Threading library in use (used by Tangosol clustering) getconf GNU_LIBPTHREAD_VERSION Sending a process into the background and detaching it from the current terminal session nohup (executable-name) & Size of a directory du -h -c attachments/ Capture UDP Traffic tcpdump

No comments: