2019/07/12_NGS Data Analysis Course (Harvard Chan Bioinformatics Core)_3

#Introduction to shell

https://hbctraining.github.io/Intro-to-Shell/lessons/01_the_filesystem.html

重要的链接:

Information on the shell

shell cheat sheets:

Explain shell - a web site where you can see what the different components of a shell command are doing.

Data Carpentry tutorial: Introduction to the Command Line for Genomics

let's start

‘cp’ is the command for copy. This command required you to specify the location of the item you want to copy (/groups/hbctraining/unix_lesson/) and the location of the destination (.); please note the space between the 2 in the command. The “-r” is an option that modifies the copy command to do something slightly different than usual.

The “.” means “here”, i.e. the destination location is where you currently are.

‘cd’ stands for ‘change directory’

#如何查看文件类型

What types of files are they?

We can use a “modifier” with ls to get more information; this modifier is called an argument (more below).

$ ls -F

 Anything with a “/” after it is a directory.

Things with a “*” after them are programs.

If there are no decorations after the name, it’s a file.

$ ls -l

可以给出更多信息

#Arguments

Most commands take additional arguments that control their exact behavior. For example, -F and -l are arguments to ls. The ls command, like many commands, take a lot of arguments. Another useful one is -a, which shows everything, including hidden files. How do we know what the available arguments that go with a particular command are? use man

 

Most commonly used shell commands have a manual available in the shell.

$ man ls

 This will open the manual page for ls.

Use the ‘space’ key to go forward and

‘b’ to go backwards.

When you are done reading, just hit q to quit.

$ pwd

This stands for ‘print working directory’. i.e. the directory you’re currently working in.

 To go ‘back up a level’ we can use ..

There is a handy command that can help you see the structure of any directory, namely tree.

 #Full vs. Relative Paths

A full path always starts with a /, a relative path does not.

use Tab to completion

The ‘*’ character is a shortcut for “everything”. Thus, if you enter ls *, you will see all of the contents of a given directory. 

$ ls *fq

$ ls /usr/bin/*.sh

$ ls Mov10*fq

 Lists every file in /usr/bin that ends in the characters .sh.

 lists only the files that begin with ‘Mov10’ and end with ‘fq’

#Command History

Hit the up arrow. Hit it again. You can step backwards through your command history.

The down arrow takes your forwards in the command history.

‘Ctrl-r’ will do a reverse-search through your command history. This is very useful.

You can also review your recent commands with the history command. Just enter:

$ history

  • Ctrl + C will cancel the command you are writing, and give you a fresh prompt.
  • Ctrl + A will bring you to the start of the command you are writing.
  • Ctrl + E will bring you to the end of the command.

 #如何查看文件内容

The easiest way to examine a file is to just print out all of the contents using the command cat

but when the file is really big, we will use the command  less, is useful for this case.

The less command opens the file, and lets you navigate through it. The keys used to move around the file are identical to the man command.

keyaction
SPACEto go forward
bto go backwards
gto go to the beginning
Gto go to the end
qto quit

 less 命令下查找文件中的内容

less also gives you a way of searching through files. Just hit the / key to begin a search. 

Enter the name of the string of characters you would like to search for and hit enter. It will jump to the next location where that string is found.

If you hit / then ENTER, less will just repeat the previous search. less searches from the current location and works its way forward.

If you are at the end of the file and search for the word “cat”, less will not find it. You need to go to the beginning of the file and search.

The commands are head and tail and they just let you look at the beginning and end of a file respectively.

The -n option to either of these commands can be used to print the first or last n lines of a file.

##Creating, moving, copying, and removing

拷贝

Lets copy the file using the copy cp command.

$ cp Mov10_oe_1.subset.fq Mov10_oe_1.subset-copy.fq

$ ls -l

Now Mov10_oe_1.subset-copy.fq has been created as a copy of Mov10_oe_1.subset.fq

创建一个copy 就是cp 空格 原文件名 空格 新文件名

在opsin 目录下从Emily文件夹里复制了一个文件夹forBrowser 到我的文件夹ATAC-Seq里

cp -r u/emily/forBrowser/. u/huifang/ATAC-Seq

 

#移动文件到其他路径

创建目录:mkdir 命令

 

Let’s make a ‘backup’ directory where we can put this file.

The mkdir command is used to make a directory. Just enter mkdir followed by a space, then the directory name.

$ mkdir backup

移动

We can move files around using the command mv. Enter this command:

$ mv *copy.fq backup

 移除:The rm file permanently removes the file.

 

此篇主要讲了shell的基础介绍,以及一处理文件的基本命令。本节全部命令符如下:

bash

cd

ls

man

pwd

~    # home dir

.    # current dir

..   # parent dir

*     # wildcard echo

ctrl + c # cancel current command

ctrl + a # start of line

ctrl + e # end of line

history

cat

less

head

tail

cp

mdkir

mv 

rm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值