0%

启动difmap

服务器已经安装了Difmap2.4l版本,只需要在环境变量PATH中加入/usr/local/difmap即可,详细安装步骤可以参考DIFMAP安装手册。

安装好DIFMAP后,打开一个终端,然后进入到数据所在的目录。输入difmap即可得到如下提示信息:

TODO : Adding difmap startup terminal

这个示例我们使用源J1036+1326的C Band C Array的数据,
This is from Project AT0205, Seg A, source TEX1033+137, taken on 7/20/97 with 370 seconds TOS.

代码参考 https://www.github.com/shaoguangleo/radio_astronomy

引言

Difmap是一个强有力的处理多维数组成像的程序。
Difmap起初是为了处理VLBI连续谱数据,后来开始处理VLA数据集。
DIFMAP通过使用现代计算机日益增加的RAM容量来最小化加载数据和重构模型所花费的时间。
这个手册会带你畅游DIFMAP的基本操作,来进行CLEAN及自校准你的数据。

所有的测试数据位于/home/share/data/difmap中,请拷贝到自己的文件夹进行操作。

代码参考 https://www.github.com/shaoguangleo/radio_astronomy

Linux 的htop命令

htop可以查看每个进行的内存负载。

htop提供的信息与top类似,不过htop提供了更好的交互、彩色显示以及控制。

远程登录不需要密码

  1. 在本机上操作ssh-keygen
  2. ssh-copy-id -i .ssh/id_rsa.pub remote_username@remote_ipaddress
  3. ssh remote_username@remote_ipaddress

背景

最近参加了一个培训,分配了很多的账号,随便找个账号的密码,如下所示gyDYKdf39dk*dfs@&,关键操作的过程中,你还需要打开多个终端。

那么问题来了,如何才能缩短这个浪费生命的无聊过程呢,方法很简单,只有3步。

远程登录不需要密码

1 在本机上操作ssh-keygen,会在目录.ssh种生成一个id_rsa.pub文件 2 ssh-copy-id -i .ssh/id_rsa.pub remote_username@remote_ipaddress 3 ssh remote_username@remote_ipaddress

比如,来个实际操作:

打开一个终端 $ ssh-keygen 拷贝 $ ssh-copy-id -i .ssh/id_rsa.pub hero@192.168.2.3 愉快登录 $ ssh hero@192.168.2.3

此时即可无密码登陆remote了

在.ssh/config中输入下述信息,即可快捷将ssh remote_username@remote_ipaddress精简为ssh remote了

1
2
3
4
5
Host   remote
HostName 192.168.254.123
Port 22
User hero
IdentityFile ~/.ssh/id_rsa

The Ultimate Guide to SSH - Setting Up SSH Keys

The Ultimate Guide to SSH - Setting Up SSH Keys

Welcome to our ultimate guide to setting up SSH (Secure Shell) keys. This tutorial will walk you through the basics of creating SSH keys, and also how to manage multiple keys and key pairs.

Create a New SSH Key Pair

Open a terminal and run the following command:

1
ssh-keygen

You will see the following text:

1
2
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):

Press enter to save your keys to the default /home/username/.ssh directory.

Then you’ll be prompted to enter a password:

1
Enter passphrase (empty for no passphrase):

It’s recommended to enter a password here for an extra layer of security. By setting a password, you could prevent unauthorized access to your servers and accounts if someone ever gets a hold of your private SSH key or your machine.

After entering and confirming your password, you’ll see the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/qRoWhRcIBTw0D4KpTUyK6YepyL6RQ2CQrtWsaicCb4 username@871e129f767b
The key's randomart image is:
+---[RSA 2048]----+
| .o=+.... |
|+.*o+o . |
|+X.=o o |
|@.=.oo . |
|=O ...o S |
|o.oo . . |
|.E+ . . . . |
|oo . ... + |
|=.. .o. . . |
+----[SHA256]-----+

You now have a public and private SSH key pair you can use to access remote servers and to handle authentication for command line programs like Git.

Manage Multiple SSH Keys

Though it’s considered good practice to have only one public-private key pair per device, sometimes you need to use multiple keys or you have unorthodox key names. For example, you might be using one SSH key pair for working on your company’s internal projects, but you might be using a different key for accessing a client’s servers. On top of that, you might be using a different key pair for accessing your own private server.

Managing SSH keys can become cumbersome as soon as you need to use a second key. Traditionally, you would use ssh-add to store your keys to ssh-agent, typing in the password for each key. The problem is that you would need to do this every time you restart your computer, which can quickly become tedious.

A better solution is to automate adding keys, store passwords, and to specify which key to use when accessing certain servers.

SSH config

Enter SSH config, which is a per-user configuration file for SSH communication. Create a new file: ~/.ssh/config and open it for editing:

1
nano ~/.ssh/config

Managing Custom Named SSH key

The first thing we are going to solve using this config file is to avoid having to add custom-named SSH keys using ssh-add. Assuming your private SSH key is named ~/.ssh/id_rsa, add following to the config file:

1
2
3
4
5
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

Next, make sure that ~/.ssh/id_rsa is not in ssh-agent by opening another terminal and running the following command:

1
ssh-add -D

This command will remove all keys from currently active ssh-agent session.

Now if you try closing a GitHub repository, your config file will use the key at ~/.ssh/ida_rsa.

Here are some other useful configuration examples:

1
2
3
4
5
Host bitbucket-corporate
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_corp
IdentitiesOnly yes

Now you can use git clone git@bitbucket-corporate:company/project.git

1
2
3
4
5
Host bitbucket-personal
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes

Now you can use git clone git@bitbucket-personal:username/other-pi-project.git

1
2
3
4
5
6
7
Host myserver
HostName ssh.username.com
Port 1111
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes
User username
IdentitiesOnly yes

Now you can SSH into your server using ssh myserver. You no longer need to enter a port and username every time you SSH into your private server.

Password management

The last piece of the puzzle is managing passwords. It can get very tedious entering a password every time you initialize an SSH connection. To get around this, we can use the password management software that comes with macOS and various Linux distributions.

For this tutorial we will use macOS’s Keychain Access program. Start by adding your key to the Keychain Access by passing -K option to the ssh-add command:

1
ssh-add -K ~/.ssh/id_rsa_whatever

Now you can see your SSH key in Keychain Access:

But if you remove the keys from ssh-agent with ssh-add -D or restart your computer, you will be prompted for password again when you try to use SSH. Turns out there’s one more hoop to jump through. Open your SSH config file by running nano ~/.ssh/config and add the following:

1
2
3
Host *
AddKeysToAgent yes
UseKeychain yes

With that, whenever you run ssh it will look for keys in Keychain Access. If it finds one, you will no longer be prompted for a password. Keys will also automatically be added to ssh-agent every time you restart your machine.

Now that you know the basics of creating new SSH keys and managing multiple keys, go out and ssh to your heart’s content!

终端技巧

打开终端的方式

  1. 鼠标点右键–terminal,即可打开。
  2. 点任务栏的”application”里面的”terminal”打开
  3. 命令方式:Alt+F2后在出现”运行应用程序”中输入x-terminal-emulator(一般在你输入到x-term后系统会自己显示全部)或者输入”gnome-terminal”

使用终端的快捷方式

  • Shift+Ctrl+T:新建标签页
  • Shift+Ctrl+W:关闭标签页
  • Ctrl+PageUp:前一标签页
  • Ctrl+PageDown:后一标签页
  • Shift+Ctrl+PageUp:标签页左移
  • Shift+Ctrl+PageDown:标签页右移
  • Alt+1:切换到标签页1
  • Alt+2:切换到标签页2
  • Alt+3:切换到标签页3
  • Shift+Ctrl+N:新建窗口
  • Shift+Ctrl+Q:关闭终端

终端中的复制/粘贴:

  • Shift+Ctrl+C:复制
  • Shift+Ctrl+V:粘贴

终端改变大小:

  • F11:全屏
  • Ctrl+plus:放大
  • Ctrl+minus:减小
  • Ctrl+0:原始大小

打开多个终端时,要从一个终端转到另外一个终端,可以通过同时按下alt后,再按tab键,按到自己想要的终端后松开,即可跳到想要得终端

通配符 - 命令行的倚天剑、屠龙刀

命令行能干很多GUI图形界面不能做的事情,不知道你的Linux倚天剑、屠龙刀有没有出鞘呢。

很多熟悉Linux命令行的人,对命令行的威力应该叹为观止了。

这其中,我认为通配符,或者广一点来说,正则表达式,真的可以成为天下武林至尊,宝刀屠龙了。

说个最简单的例子

我想拷贝某个文件夹里面的在三个小时内曾经修改过的包含hero的文件。

请大家踊跃发言,如何解决。

下面就说下几个比较常用的通配符。

通配符 匹配项
* 匹配任意多个字符
? 匹配任一单个字符
[characters] 匹配任意一个属于字符集合中的字符
![characters] 匹配任意一个不属于字符集合中的额字符

现在我们执行ls命令,可以看到有下面几个文件:

1
2
ls
ab abb ac ad ae af

实例一 *

匹配任意多个字符

1
2
3
4
5
ls a*
ab abb ac ad ae af
ls ab*
ab abb

实例二 ?

匹配任一单个字符

1
2
3
4
5
ls a?
ab ac ad ae af
ls a??
abb

实例三 [characters]

匹配任意一个属于字符集合中的字符

1
2
➜   ls a[bcd]
ab ac ad

实例四 ![characters]

匹配任意一个不属于字符集合中的额字符

1
2
➜   ls a[!(bcd)]
ae af

通配符 - 命令行的倚天剑、屠龙刀

继续昨天的倚天剑的通配符操作。

为什么分两次:

  • 俺觉得昨天的知道的肯定知道,无外乎复习下
  • 不知道的其实也够一天几分钟的量了

为什么说通配符

  • 后面的很多操作都会用到通配符
  • 通配符不掌握不要说你会用Linux
  • 考虑花几十个tips来说下正则表达式

昨天的都比较简单,今天来点有难度的。

其实我觉得屠龙刀比倚天剑厉害,因为我喜欢灭绝师太,^_^。

首先看下目前文件夹里面都有什么,下面所有的操作都基于这个文件列表:

1
2
➜  ls
1a 1b a12 a123 a13 a14 ab AB abb ABC ac ad ae af b12 b123 b13 b14

实例 [:alnum:] - 匹配任意一个字母或数字

1
2
➜  ls [[:alnum:]]*
1a 1b a12 a123 a13 a14 ab AB abb ABC ac ad ae af b12 b123 b13 b14

实例 [:alpha:] - 匹配任意一个字母

1
2
➜  ls [[:alpha:]]*
a12 a123 a13 a14 ab AB abb ABC ac ad ae af b12 b123 b13 b14

实例 [:digit:] - 匹配任意一个数字

1
2
➜  ls [[:digit:]]*
1a 1b

实例 [:lower:] - 匹配任意一个小写字母

1
2
➜  ls [[:lower:]]*
a12 a123 a13 a14 ab abb ac ad ae af b12 b123 b13 b14

实例 [:upper:] - 匹配任意一个大写字母

1
2
➜  ls [[:upper:]]*
AB ABC

Git Contributor / PR 建议步骤

  1. 首先Fork将要提交的工程,比如原地址为https://github.com/offical/repo.git

  2. clone到本地,并创建一个upstream远程

    1. git clone git@github.com:username/repo.git
    2. git remote add upstream git@github.com:offical/repo.git
  3. 创建自己的特性分支

    1. git checkout -b Name/AmazingFeature
    2. 修改并提交修改 (git commit -m 'Add some AmazingFeature')
    3. 将更新推送到远程分支 (git push origin Name/AmazingFeature)
  4. 登陆到github,提交一个Pull Request到官方repository

  5. 如果PR被接收了,此时可以更新master分支并删除创建的branch

    1. 更新master分支git pull upstream master
    2. 删除branch分支 git branch -D Name/AmazingFeature
  6. 恭喜成为代码贡献者

如果PR出现冲突,解决方式为:

  1. 将源版本库添加为一个远端,并命名为“upstream”(上游)
  2. 从远端抓取最新的内容
  3. 将该仓库的主分支的内容合并到你的分支中
  4. 修复产生的冲突
  5. 再推送回同一个分支

当然,在这个过程中最好不要rebase操作

显示管理磁盘分区 fdisk

.. note::

浮云一别后,流水十年间。

  • 韦应物《淮上喜会梁川故人 》

fdisk是用于检查一个磁盘上分区信息最通用的命令。

fdisk可以显示分区信息及一些细节信息,比如文件系统类型等。

设备的名称通常是/dev/sda、/dev/sdb 等。

对于以前的设备有可能还存在设备名为 /dev/hd* (IDE)的设备,这个设备逐步淘汰了。

fdisk也可以用于创建并操控分区表信息,支持主任GPU、MBR、Sun、SGI和BSD。

块设备可以划分为一个或多个称为分区的逻辑磁盘。这种划分的记录会保存在分区表,通常位于磁盘的第 0 扇区。

fdisk的官方解释为:

fdisk - manipulate disk partition table

语法格式为:

1
2
3
$ fdisk [options] device

$ fdisk -l [device...]

其中一些常用的参数为:

  • -l 列出指定的外围设备的分区表状况
  • -L, --color[=when] :将输出颜色化,其中when可以指定为auto, never or always. 默认为 auto.

显示当前系统的分区情况

这个也是我唯一推荐入门者使用的 命令,仅仅list显示出目前的系统分区。

万万不要输入fdisk执行其他操作,极易格式化硬盘,切记切记。

1
2
3
4
5
6
7
8
9
$ fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 256.1 GB, 256060514304 bytes, 500118192 sectors # 磁盘空间及扇区信息
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: FAF37680-0ECE-4BE7-93FC-E87A8F2F6455

存同求异 join

.. note::
劝君莫惜金缕衣,劝君惜取少年时。

  • 杜秋娘《金缕衣》

Linux join命令用于将两个文件中指定栏位内容相同的行连接起来。

找出两个文件中,指定栏位内容相同的行,并加以合并,再输出到标准输出设备。

类似于SQL的JOIN操作

官方解释为:

join - join lines of two files on a common field

语法为:

1
$  join [OPTION]... FILE1 FILE2

这个命令的参数还是有一些的,不过基本默认的足够使用了。

join实例

最简单的连接两个文件。

首先看一下两个文件的内容,然后进行join操作。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 查看file1、file2 的文件内容:
$ cat file1
Zhangsan age 14
Lisi age 15
Wangwu age 16

$ cat file2
Zhangsan score 80
Lisi score 90
Wangwu score 85

# 使用join命令
$ join file1 file2
Zhangsan age 14 score 80
Lisi age 15 score 90
Wangwu age 16 score 85

# 交互两个文件的顺序
$ join file2 file1
Zhangsan score 80 age 14
Lisi score 90 age 15
Wangwu score 85 age 16

可以看到交换顺序对输出是有影响的,会影响到最终的输出内容。

不同的栏内容进行join操作

而如果两个文件的内容不同,那么在进行join操作时会有警告信息输出,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cat file1       
Jialiu age 15
Zhangsan age 14
Lisi age 15
Wangwu age 16
$ cat file2
Zhangsan score 80
Lisi score 90
Wangwu score 85
Jialiu score 88
$ join file1 file2
join: file1:3: is not sorted: Lisi age 15
join: file2:2: is not sorted: Lisi score 90
Zhangsan age 14 score 80
Lisi age 15 score 90
Wangwu age 16 score 85
$ join file2 file1
join: file2:2: is not sorted: Lisi score 90
join: file1:3: is not sorted: Lisi age 15
Zhangsan score 80 age 14
Lisi score 90 age 15
Wangwu score 85 age 16

TODO

语法

1
join [-i][-a<1或2>][-e<字符串>][-o<格式>][-t<字符>][-v<1或2>][-1<栏位>][-2<栏位>][--help][--version][文件1][文件2]

参数

  • -a<1或2> 除了显示原来的输出内容之外,还显示指令文件中没有相同栏位的行。
  • -e<字符串> 若[文件1]与[文件2]中找不到指定的栏位,则在输出中填入选项中的字符串。
  • -i或–igore-case 比较栏位内容时,忽略大小写的差异。
  • -o<格式> 按照指定的格式来显示结果。
  • -t<字符> 使用栏位的分隔字符。
  • -v<1或2> 跟-a相同,但是只显示文件中没有相同栏位的行。
  • -1<栏位> 连接[文件1]指定的栏位。
  • -2<栏位> 连接[文件2]指定的栏位。

-a FILENUM
also print unpairable lines from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2

-e EMPTY
replace missing input fields with EMPTY

-i, –ignore-case
ignore differences in case when comparing fields

-j FIELD
equivalent to ‘-1 FIELD -2 FIELD’

-o FORMAT
obey FORMAT while constructing output line

-t CHAR
use CHAR as input and output field separator

-v FILENUM
like -a FILENUM, but suppress joined output lines

-1 FIELD
join on this FIELD of file 1

-2 FIELD
join on this FIELD of file 2

–check-order
check that the input is correctly sorted, even if all input lines are pairable

–nocheck-order
do not check that the input is correctly sorted

–header
treat the first line in each file as field headers, print them without trying to pair them

-z, –zero-terminated
line delimiter is NUL, not newline

   Unless -t CHAR is given, leading blanks separate fields and are ignored, else fields are separated by CHAR.  Any FIELD is a  field
   number counted from 1.  FORMAT is one or more comma or blank separated specifications, each being 'FILENUM.FIELD' or '0'.  Default
   FORMAT outputs the join field, the remaining fields from FILE1, the remaining fields from FILE2, all separated by CHAR.  If FORMAT
   is the keyword 'auto', then the first line of each file determines the number of fields output for each line.

   Important:  FILE1 and FILE2 must be sorted on the join fields.  E.g., use "sort -k 1b,1" if 'join' has no options, or use "join -t
   ''" if 'sort' has no options.  Note, comparisons honor the rules specified by 'LC_COLLATE'.  If the input is not sorted  and  some
   lines cannot be joined, a warning message will be given.

​ comm(1), uniq(1)

为工程生成目标文件

语法:

1
2
3
add_executable(<name> [WIN32] [MACOSX_BUNDLE]
[EXCLUDE_FROM_ALL]
source1 [source2 ...])

简单的例子如下:

1
2
3
add_executable(demo
main.cpp
)