Google

Jun 24, 2014

Top 17 Unix commands Java developers use frequently

Unix for software developers

1.Top 17 Unix commands Java developers use frequently 2.History commands 3.Shell scripting 4. Reading from a file
5.Purging older files 6.Splitting and archiving files 7.Emulator, SSH client 8.Unix commands for developers 9.Unix basic interview Q&A

1. Find with grep to search for files with a certain text. For example, search all properties files where there are "inbox" search texts defined.

$find . -type file -name "*.properties" | xargs grep inbox \{\}; #
$find . -type f -name "*.properties" -exec grep "inbox" {} /dev/null \;

This will recursively search all sub folders as well. Very handy if you are searching for something. The addition of /dev/null is for the grep to consistently print the file name when it finds a match.

If you are searching within a single folder, for example, to list all the log files that have "job-no-300"

grep -l "job-no-300" *.log

To recursively delete .svn folders of a project to remove any links to subversion

find . -type d -name .svn -exec rm -rf {} \;

2. If a log file is too large, split it into smaller files before using less -200 xaaaa.

split -b 1m -a 3 PUWPD394.20140623.172525.log

files are split into xaaa, xaab, xaaac, etc.

3. Identify the jar file that has a particular class or resource file. For example, to find the jar files that has MyConnection.class filer. Handy for identifying class loading issues for batch job.

find . -name '*.jar' -print0 |  xargs -0 -I '{}' sh -c 'jar tf {} | grep MyConnection.class


4. find all the files that has URLs that are http:// with https:// with the power of sed command

find . -type f -name '*.properties' -exec sed -i 's/http\:\/\//https\:\/\//g' {} \;


5. Create a symbolic link

ln -s myapp-test1.properties myapp.properties


now, myapp.properties -> myapp-test1.properties. Handy when you have different environmental properties files, and can use a symbolic link to connect to particular environment like test1, test2, test3, etc.

6. Execute a shell command

$./myapp.sh -env test1 -logile myapp.log

where -env test1 and -logfile myapp.log are arguments passed to the shell script.

7. Run a shell script in the background even after you log out  the session. For example, kick off a long running batch job.

$nohup  ./myapp.sh -env test1 -logile myapp.log &

nohup ensures that it runs even after you logout.  and & is for running in the background.

8. change directory, make a new directory, create an empty file, find the present folder, and list files.

$ cd folder1

$ mkdir folder2

$cd folder2

$touch test.txt   #new file

$pwd    #list current folder

$cat test.txt   #display contents
$more test.txt   #paginates

$ls -ltr
$ls -ltr *300* #all jobs with job number 300 

9. Copy or move files

$cp /test3/*.txt /test1/
$cp /test3/a.txt /test/b.txt # copy a file with another name
$mv /test3/a.txt /test/b.txt

If you mv, the source file will be deleted. You can use mv to rename a file as well.




10. history command to reuse some of the commands you already used.

$history

$history | grep mkdir

$!cd

$!35


11. Check a log file.

$less -200 myapp.log
tail -f myapp.log

shift+G to go to bottom of the file
g to go to beginning of the file
/INFO to search for "INFO"
:q to quit

12. Edit a file

$vi myapp.txt


a -> append
x --> delete a character

13. Java process control commands

$ps -ef | grep java
$vmstat
$kill-3 12345  #kill a process with pid 12345 

14 Network connections and sockets info. You can identify ports already in use.

$netstat -a | grep 444

15. archive the files in the current folder with tar.

tar cvzf myapp.tgz .   #z means gzip. c - create
tar xvzf myapp.tgz     #untar and un gzip x - extract

16. Transfer files with scp.

scp myappl.tgz myuser@myserver.com:/home/myuser   # copy to a server
scp myuser@myserver.com:/home/user/myapp.tgz .   # copy from a server


17. Commands to verify network connectivity

$ping hostname
$telnet hostname 25 #hostname and port number
$wget http://www.myapp.com/downloads/script.txt


This was meant to be a quick list. You can search for more detailed examples in this blog.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home