Skip to main content

Useful commands and howtos at your finger tips

Useful commands and howtos at your finger tips

linux|unix|dos|windows|mac
jdk|regex|...

1. How to find files and operate some command on that file list

Example (a) Find all files updated within the last 11 minutes, and copy them to another directory:
find . -mmin 11 -exec cp '{}' /home/temp/ \;



2. How to read a file line by line through a unix/linux shell script

http://www.bashguru.com/2010/05/how-to-read-file-line-by-line-in-shell.html

3. How to extract only the file names after you have figured out which files from the ls -ltr listing

Assume filelist.txt contains the ls- ltr output redirected
cat filelist.lst
-rw-r-----  1 oraxxxx emsxxxx     2119 Dec  5 02:50 sid_ora_5565.trc
-rw-r-----  1 oraxxxx emsxxxx    11591 Dec  5 02:50 sid_ora_24464_TEST.trm
-rw-r-----  1 oraxxxx emsxxxx   469796 Dec  5 02:50 sid_ora_5565_TEST.trc
-rw-r-----  1 oraxxxx emsxxxx   698558 Dec  5 02:51 sid_lgwr_6551.trc
-rw-r-----  1 oraxxxx emsxxxx     5855 Dec  5 02:52 sid_ora_31733_TEST.trm
-rw-r-----  1 oraxxxx emsxxxx    12321 Dec  5 02:52 sid_ora_29474_TEST.trm

cat filelist.txt | cut -d ":" -f 2 | cut -d  " " -f 2 > fileslist.txt

Now fileslist.txt will have only the filenames

cat fileslist.tst
sid_ora_5565.trc
sid_ora_24464_TEST.trm
sid_ora_5565_TEST.trc
sid_lgwr_6551.trc
sid_ora_31733_TEST.trm
sid_ora_29474_TEST.trm


4. How to convert from postscript to pdf format


Ensure you have ghostscript installed
Then use the ps2pdf command

ps2pdf -dEmbedAllFonts=true -dOptimize=true -dUseFlateCompression=true myfile.ps

This will create a pdf file with the same name as the .ps file, in the current working directory.

[This page gives a detailed overview of the ps2pdf command.]


5. How to generate a keystore


JDK ships with a keytool program, that can be used to generate one keystore:

keytool -genkey -v -keystore filename.keystore -alias keyaliasname -keyalg RSA -keysize 2048 -validity 10000

6. How to list all files within a given directory in DOS/Windows

Use the following DOS command in the command window:
dir /b /s /a:-D

[Source: http://superuser.com/questions/653860/list-files-recursively-showing-only-full-path-and-file-size-from-windows-command]



7. Howzzat RegEx ?

7.1. How to get the file name only, from a list of full path names ?


For example, we have a file that has list of full path names, like as shown below:

D:\lib\SCEMDT-lib\xmlparserV2\xml.jar
D:\lib\SCEMDT-lib\xmlparserV2\xmlparserv2.jar
D:\lib\SCEMDT-lib\jdev-rt.jar
D:\lib\SCEMDT-lib\ant-launcher.jar

How do we get only the filenames then?

Answer: 
Use regex (.*?)(\\(?=[^\\]*$))(.*?$) as the matching pattern.
and then replace with \3

Explanation:
The second part of the regex i.e., (\\(?=[^\\]*$)) says to match a literal backslash \ and then asserts ((?=) is positive lookahead) that no other character up to the end of the string is a backslash \. 
The first part and the third part of the regex is plain and simple: the first part (.*?) points to the string before the last backslash \; and the second part (.*?$) points to the string after the last backslash \ till the end of the line.

The replacement pattern is \3 , which means the third part (i.e., the string after the last backslash \ till the end of the line)




8. Closing a session after running a blocking command line script

After you have started a blocking command line script (such as the startWebLogic.sh), you can not close the session from which you started the script. Because, if you close the session, then the script too closes.

One option is to use nohup & . But this can work when the script does not ask for any console input, such as credentials, etc.

For scripts like startWebLogic.sh that asks for console inputs, we still have a way:

Follow the following sequence of steps to detach the running startWeblogic.sh process after the weblogic has been started.
Pause: ^z
Send to background: bg
Check background jobs: jobs
Detach from session: disown
Verify if really detached: jobs



9. mactips - Tips & Howtos for your first mac

(esp. if this is the first time, you have moved to a Mac from a Windows or a Linux)

9.1. Setting environment variables that are available to all applications

Put the setenv statements in the file /etc/launchd.conf
It requires superuser permissions.

sudo vi /etc/launchd.conf

setenv JAVA_VERSION 1.6
setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
setenv GROOVY_HOME /Applications/Dev/groovy
Save the file, and reboot the mac. Or, run the following command, and relaunch the required applications:
grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl

Courtesy: Setting environment variables in OS X?

Later on, even after restarting, the env variable settings sometimes vanish. I added the above command into the ~/.bash_profile file.

9.2 Setting PATH on mac

By any of the following methods:
  1. $HOME/.bash_profile file using export syntax.
  2. /etc/paths.d directory.

9.3 Copy Path of a folder in mac

  • Open Automator.
  • Select the Service template.
  • Set options at the top to Service receives selected Files or Folders in Finder.
  • Drag over “Copy to Clipboard.”
  • Save the service with a name like “Copy Path as text
Now, in the right-click context menu for any folder in finder, you will see a new menu item "Copy Path as text"

The service can also be assigned a keyboard shortcut, from the System Preferences -> Keyboard -> Shortcuts

Courtesy: http://stationinthemetro.com/2014/06/04/copy-file-path-as-text-in-mac-os-x


...to be continued...

Comments

Popular posts from this blog

How to change message center number in Android?

Have issues with sending or receiving sms-es?? Tip: Your message center number might be empty or wrong! Solution: Very simple :)  Dial *#*#4636#*#*. You will get a menu, from that select Phone Information You will find a setting "SMSC"  Refresh it. It is most likely to retrieve the message center number from your operator. (Or call your operator, and get the message center number, and then update in this field) Then the problem should be resolved! Happy messaging! [Courtesy: http://www.droidforums.net/forum/tech-issues-bug-reports-suggestions/10135-how-do-you-change-sms-message-center-numbers.html]

My takeaways from JavaOne 2013

This year I attended the JavaOne at Novotel HICC Hyderabad. I attended mainly the sessions on Java. J2EE, and JavaFX, with a bit of extremely innovative enhancements to Oracle DB sessions. Here's the main takeaways from the sessions I attended: 1. Lambda operator and closure coming to JDK8. This is an outright change, a change to all the 4k+ classes in the java libraries. Code will become simpler, neater, and also improve in performance. This is not just a cosmetic sugar coating change, there have been performance improvements as well with these new features. 2. Going by their philosophy of less boiler plate code (which also includes the closure introduction), they have introduced simpler ways to code and work with various J2EE components like the JMS2.0, etc. 3. JavaFX can now be programmed from any of the languages that run on JVM, such as Groovy, Scala, Clojure, etc. I was amazed by the language Groovy! even learning it our of my own interest :) 4. A brand new JavaScript engine...

Part-time courses from IIIT Hyderabad

Let me paste here some details of the PGSSP course offered by IIIT-H for the working professionals in Hyderabad, and on the future route that one may wish to take (either a MTech, MS, or PhD). I had written this to one friend who was interested in PhD, but I feel that the same should give anyone (a working professional, looking for a part-time course) a good idea about the PGSSP programme, and a later MTech/MS, as well. [Disclaimer: The information and the opinion presented here are based on my personal opinion and experience. While I have tried to be as correct and unbiased as possible, the following can not be taken as the ultimate or the final word or information for the part-time courses offered by IIIT Hyderabad. For official information, please go to iiit.ac.in and also enquire from IIIT-H's admission office before taking any decision. ] Q. The offer says that u have to enroll in few courses max of two per semester. Does this course offer a degree of Master? If...