githubEdit

2.Linux

1) Examples

  • grep

grep -v -c pattern FILES  #(-v exclude -c count lines)
grep -l pattern FILES #(-l: list of the files)
  • head, tail V.S. cut

  • cat V.S. paste

head -100 FILE
tail -100 FILE
cut -f 2 FILE #(-f: field)
cut -d ; -f 2 FILE #(-d change delimiter)

cat FILES* > NEW_FILE
paste FILES* > NEW_FILE
  • rev and tac

echo john temp | rev     #(output pmet nhoj)
tac    #(reverse by lines)
  • wc

ls * |wc -w   or  wc -l  #(count the number of files)
  • comm and vimdiff, diff

  • sort

  • uniq

  • seq

  • sed

  • awk

  • history

  • find and locate

  • xargs

grep for pattern in all files on the system:

Move files in olddir to newdir, showing each command:

2) Tips

(1) bashrc and .bash_profile

Example:

more examplesarrow-up-right

(2) nohup, screen and qsub

  • run something at background

./run.bat >& run.log &

fg

  • nohup:

nohup nice -19 run.bat >& run.log&

  • tmux:

    • start a new session: tmux or tumx new-session -s session-name

    • detach: ctrl-a, d

    • re-attach: tmux attach-session -d -t session-name #detach it first

  • screen: # a popular alternative of tmux

    • start a new session: screen

    • detach: ctrl-a, d

    • re-attach: screen -R -D # detach it first

  • qsub:

(3) secure your files

  • make your files Read-only

    • permission for a executable bash script is usually 755

    • using chmod -R a-w for raw data and input files

  • 777, rwxrwxrwx is forbidden (using chmod -R o-w)

  • Change user group and permission

  • Blocking the root:

vim /etc/ssh/sshd_config #PermitRootLogin yes —>no

(4) Setup ssh key

  • ssh-keygen (authorized_keys id_rsa.pub 权限设置为 600)

This will be very useful later when we work on remote machine as a local one, especially for jobs like backup and script editing.

(5) System

  • kernel version

  • mount dir/ to local machine using NFS or sshfs (then you can Edit text and view figures remotely)

I recommend using "transmit" app in your mac instead of mounting NFS or sshfs.

  • forward the log file to an email address

  • Kill batch job

3) More Readings and Practices

  • Teaching Video:Week I. 2. Linux

  • for Beginners

    • 阅读和练习《鸟哥的Linux私房菜-基础学习篇》如下章节:

    • 《“笨办法”学python》附录“命令行快速入门”

第5章 5.3.1 man page 第6章 6.1用户与用户组 6.2 LINUX文件权限概念 6.3 LINUX目录配置 第7章Linux文件与目录管理 7.1目录与路径 7.2文件与目录管理 7.3文件内容查阅 7.5命令与文件的查询 7.6权限与命令间的关系 第8章 8.2文件系统的简单操作 第9章 9.1压缩文件的用途与技术 9.2 Linux系统常见的压缩命令 9.3打包命令:tar 第10章vim程序编辑器 (或者其他编辑器文档) 第11章 认识与学习bash 第25章 LINUX备份策略 25.2.2完整备份的差异备份 25.3鸟哥的备份策略 25.4灾难恢复的考虑 25.5重点回顾

第11章 认识与学习bash 第12章 正则表达式与文件格式化处理 第13章 学习shell script

  • for Advanced Readers

《Bioinformatics Data Skills》

3) Remedial Unix Shell

7) Unix Data Tools

4) Homework

  1. 解释gtf/gff文件中第4、5列($4,$5)代表什么,exon长度应该是$5-$4+1还是$5-$4

  2. 从gtf/gff文件中寻找3个最长的exon:

    grep exon *.gtf | awk '{print $5-$4+1}' | sort -n | tail -3这个方法有什么bug?

    有新的方法加分,但必须注释清楚每个语句和参数的意义和结果。

  3. 从gtf/gff文件中寻找并计算每一个transcript的长度,注意不能重复计算,不能包含intron。

5) Video

5a) Linux

@youtubearrow-up-right

@Bilibiliarrow-up-right

Last updated