2013年12月29日星期日

Linux的五个查找命令:find,locate,whereis,which,type

1. find
find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件。
find的使用格式如下:
  $ find <指定目录> <指定条件> <指定动作>
  - <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。
  - <指定条件>: 所要搜索的文件的特征。
  - <指定动作>: 对搜索结果进行特定的处理。
如果什么参数也不加,find默认搜索当前目录及其子目录,并且不过滤任何结果(也就是返回所有文件),将它们全都显示在屏幕上。
find的使用实例:
  $ find . -name "my*"
搜索当前目录(含子目录,以下同)中,所有文件名以my开头的文件。
  $ find . -name "my*" -ls
搜索当前目录中,所有文件名以my开头的文件,并显示它们的详细信息。
  $ find . -type f -mmin -10
搜索当前目录中,所有过去10分钟中更新过的普通文件。如果不加-type f参数,则搜索普通文件+特殊文件+目录。
2. locate
locate命令其实是“find -name”的另一种写法,但是要比后者快得多,原因在于它不搜索具体目录,而是搜索一个数据库(/var/lib/locatedb),这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,所以使用locate命令查不到最新变动过的文件。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。
locate命令的使用实例:
  $ locate /etc/sh
搜索etc目录下所有以sh开头的文件。
  $ locate ~/m
搜索用户主目录下,所有以m开头的文件。
  $ locate -i ~/m
搜索用户主目录下,所有以m开头的文件,并且忽略大小写。
3. whereis
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b)、man说明文件(参数-m)和源代码文件(参数-s)。如果省略参数,则返回所有信息。
whereis命令的使用实例:
  $ whereis grep
4. which
which命令的作用是,在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。
which命令的使用实例:
  $ which grep
5. type
type命令其实不能算查找命令,它是用来区分某个命令到底是由shell自带的,还是由shell外部的独立二进制文件提供的。如果一个命令是外部命令,那么使用-p参数,会显示该命令的路径,相当于which命令。
type命令的使用实例:
  $ type cd
系统会提示,cd是shell的自带命令(build-in)。
  $ type grep
系统会提示,grep是一个外部命令,并显示该命令的路径。
  $ type -p grep
加上-p参数后,就相当于which命令。
From: http://www.kuqin.com/linux/20091009/70532.html

LINUX 命令—— 文本操作命令 cat more less head tail

【文本文件操作命令】
cat        查看文件内容   
more      逐屏查看文件内容
less       逐行查看文件内容
head      显示文件开头部分内容
tail        显示文件结尾部分内容

tail –f  20 /var/log/messages      -f可以一直追踪这个文件内容,一般是日志文件,20表示显示的行数。运维工作中常用重要命令。

Cut  –d: -f1 /etc/passwd 以:为分隔符 截取每行第一段字符

sort 排序
如:du |sort –n–r        -n是以数字排序,-r是反向排序
-t:以冒号为分隔符
+2以第二列开始排

wc  统计文件下有多少行 多少字符
[root@localhostddd]# wc /etc/passwd
  36   541637 /etc/passwd
如上:36行 54个单词1637个字符
参数:
 –l     行
 –w    单词
-c     字符

unip 将相邻的相同行的去掉
如:
[root@localhostddd]# cut -d: -f7 /etc/passwd |uniq
/bin/bash
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin

/sbin/nologin
/bin/bash

diff  文件A 文件B  对比A和B的区别


【正则表达式】
echo *与echo “*”的区别
[root@localhost~]# echo *
aaaall.sql anaconda-ks.cfg bastest case Desktop install.log install.log.syslogxunhuan
[root@localhost~]# echo"*"
*
echo*     中bash将*理解为任意位置的任意字符
echo“*”中双引号的作用是将内容注释为字符串

.       任意的一个字符
*       任意多的任意字符
\        脱意符
^       以……开头
$       以……结尾
\<  \>   以……开头以……结尾
a\{18\}    a重复18次

为配置文件瘦身
#grep '.\{10\}' /usr/share/dict/words
.重启10次的(字符为10)的单词
#grep '.\{10,\}' /usr/share/dict/words
 在此文件中找出.重复10次以上的(字符大于10)的单词
grep -v ‘^#’ /etc/httpd.conf  | grep –v ‘^$’
 找出除了以#开头的,并除去以刚开头就结尾的(空行)的内容

[abc]表示当前一个位置a、b或c
#grep ‘^[abc]’ /etc/passwd  以a或b或c开头的
#grep '^[^1-9]' /etc/passwd 不是以1-9开头的


更多0

2013年12月9日星期一

Make good astronomical images or rgb image. (deal with the large dynamic range problem)

Usually, the images we get with a CCD is just in grey color. Would you like to make some amazing color images.

There is some easy way to do that. Check the Trilogy by Dan Coe. The introduction on the website is quite enough for first using.

Another way I found is the
Here is a paper about one method to create the rgb images (http://arxiv.org/pdf/astro-ph/0312483v1.pdf). Some examples are here (http://www.astro.princeton.edu/~rhl/PrettyPictures/).


The thing you should think about is that these images have large dynamic ranges as shown below.

Human Eye 10,000:1
CRT 100:1
Real-life Scenes up to 500,000:1


In real life, the images always contain a large range of flux. It is quite bright in some points, but it is dark in others. So if you use a linear plot, some details will not be obvious. So you should think about to rescale the image. Unlike you take photo in which you should make longer exposure inside room, the exposure time you use is better for longer. For longer exposure time, you can detected faint sources. In the plot, if you want to show these faint sources, some bright objects will be too brighter and make the figure too ugly. Right? The thing is about how to make a good contrast with keeping enough informations. now let us compare different scale methods.
Check the above, for the same observations, it seems different. If you are familiar with DS9, you can try these scale with any fits file. I use log scale usually. There is a comparation of the stretch function.


In order to show some more details about faint objects, I suggest to use log scale or even log(log) scale. In Trilogy sofeware, Coe uses the scale method:
y = log10( k * (x - xo) + 1 ) / r
# Current settings:
# x0: 0 (0 in the input yields black in the output)
# x1: mean + std (1-sigma above the noise)
# x2: set so only some small fraction of pixels saturate (with output = 1)
The x1 and x2 is determined by the two parameters satpercent and noiselum. 


Most of these images are from the ppt: chandra.harvard.edu/graphics/talks/christensen_sixth.ppt

【IRAF】The commands in IRAF you may want to use

I want to collect some commands that I have used or I like to learn here. Just to make a collection. Hope this will help for you.  Most of these commands are used in my works because I am dealing with HST images in these days.

To be continued...

imcopy      copy a region of images  to another file. It will keep the coordinate information!
    iraf.imcopy(infile[0:10,0:10], outfile, verbose=0)

imarith    useful when you want to divide the exposure time or divide two images.
 cl> imarith exp1[10:90,10:90] * 1.2 temp1
 cl> imarith exp2[10:90,10:90] * 0.9 temp2
 cl> imarith temp1 / temp2 final title='Ratio of exp1 and exp 2'
 cl> imdelete temp1,temp2

mosaic_display  display a list of images. 
    mosaic_display image.* ncols=4 nrows=2 


wregister  register a list of images to a reference image using WCS information. I really like this commands. It is much faster and easier then my own program. What is also important, it uses an algorithm to smooth the images, so the results look quite pretty
       wregister input reference output
One important usage in my work. Use wregister to register Spitzer/IRAC images to match HST images. Then you can use the python script to read the images to plot nice stamp images. This image comes from Dan Coe's paper about the redshift z~10 galaxy. 


artdata Make arificial data with IRAF
--> apropos noao.artdata   
gallist - Make an artificial galaxies list (noao.artdata) 
mk1dspec - Make/add artificial 1D spectra (noao.artdata) 
mk2dspec - Make/add artificial 2D spectra using 1D spectra templates
(noao.artdata) 
mkechelle - Make artificial 1D and 2D echelle spectra (noao.artdata)  mkexamples - Make artificial data examples (noao.artdata) 
mkheader - Append/replace header parameters (noao.artdata)   
mknoise - Make/add noise and cosmic rays to 1D/2D images  (noao.artdata)
mkobjects - Make/add artificial stars and galaxies to 2D images  (noao.artdata) 
mkpattern - Make/add patterns to images (noao.artdata) 
starlist - Make an artificial star list (noao.artdata) 
imcombine
combine several images into one fitsfile. You can define the grid and the black region between them. It's useful when you want to plot stamp images for check.
    imcopy rejmask[*,*,1] mask1
    grid [n1] [s1] [n2] [s2]
where ni is the number of images in dimension i and si is the step in dimension i. For example "grid 5 100 5 100" specifies a 5x5 grid with origins offset by 100 pixels.

the purpose is quite similar to mosaic_display. The different is that you can scale the combined fits file easily here.


imexam


Others I have not used so far:
imtranspose
imexpr  
        imexpr a?1:b a='.fits'

ellipse 
    Fit elliptical isophotes to galaxy images.

mkobjects

mknoise

imstat

SPECTRUM
wspectext
 wspectext -- convert 1D image spectra to an ascii text spectra
dopcor, dispcor
Apply doppler correction, Dispersion correct and resample spectra 
cl> dopcor qso001.ms qso001rest.ms 3.2 flux+
ir> dispcor spec dcspec 9,10,447-448

See all task in IRAF here .