0%

Linux

在这里插入图片描述

unnatural 石原里美 入坑了她的美

Linux基本知识

查询命令 man

linux的命令和参数太多,而且容易记错,我们可以通过man [命令] 来查看如何命令的使用文档,这才是学习命令最好的办法。

其次要首先搞懂:文件,用户与组的概念。

man ls

or

ls --help 会以中文展示出来。

Tips:

  • Use the manual man for more information on commands.
  • If you want to rerun a command you can use the up-arrow key to recall the previous entry.
  • You can press TAB to ask your shell to try to complete a file name. It is convenient! Always try to have the shell fill in the filename for you, that way you will never mistype these”

摘录来自: “The Biostar Handbook: 2nd Edition。” Apple Books.

Linux的文件权限和目录配置

用户组与用户

1571385663320

其中 老王家就代表一个用户组 ,单个人代表为用户。

  • linux的用户是记录在
    /etc/passwd
  • 密码记录在
    /etc/shadow
  • 所有的组记录在
    /etc/group
添加新用户 :
1
2
3
adduser wvdon 
#修改所添加用户的密码
passwd wvdon

添加用户之后可以把用户添加到相应的组中。

1
2
3
groupadd lab
# 将用户添加到组里面
sudo useradd -g labuser la

新建的用户如果想使用root,将bashrc copy 过去。

如果新建的用户没有用户目录,就新建一下用户目录。

sudo cp /home/wvdon/.bashrc /home/labuser/.bashrc

文件权限

文件的权限被分为 可读(read) 可写(write) 可执行(execute) 简称为 r w x

用数字表示 r:4 w:2 x:1

文件显示的权限

1
2
>  -rw-rw-r-- 1 wuweidong061 wvdon    0 Oct 18 23:08 testfile.txt
>

①第一个符合 为 d 或者 - 分别代表 文件夹或者文件
②2-4符号代表所属用户的权限 rw- 即可读可写(4+2+0)
③5-7符号代表所属用户组的权限 rw- 即可读可写(4+2+0)
④8-10符号代表其他用户的权限为r–仅读(4)
⑤代表连接数
⑥代表 文件所有者 wuweidong061
⑦代表 文件所属用户组 wvdon
⑧时间代表文件最后修改的时间
⑨文件名

修改文件用户与权限的三个命令
chgrp
1
2
3
4
#chgrp=change group
#修改用户组
-R 递归更改(连着文件夹下的目录和文件都进行更改)
chgrp user filename
chown
1
2
3
#chown=change owner
#修改文件所属者
chown [-R] 账户名称 文件或目录
chmod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#chmod = chmod mode
#更改文件的权限
#一个文件共有三种权限分别是w r x,同时一个文件也对三种用户组状态设置权限 所有者用户② 用户组③ 其他用户④
#更改权限的方法有三种,
#1 利用对应的数值
chmod 777 filename
#2 利用对应的身份状态设置
# a u g o代表 all[所有用户] user[文件所有者] group[用户所有组] other[其他用户]
#设置类型可以为 + - =
chmod u=rwx,g=rx,o=x filename
#增加或者减少文件的权限 可以通过
#chmod [用户类型][设置类型 + -][权限w r x] filename
#例如添加w或者减去x
chmod a+w filename
chmod a-x filename
对文件与目录的常见操作

1. ls

列出文件或者目录的信息,目录的信息就是其中包含的文件。

1
2
3
4
# ls [-aAdfFhilnrRSt] file|dir
-a :列出全部的文件
-d :仅列出目录本身
-l :以长数据串行列出,包含文件的属性与权限等等数据

2. cd

更换当前目录。

1
cd [相对路径或绝对路径]

3. mkdir

创建目录。

1
2
3
# mkdir [-mp] 目录名称
-m :配置目录权限
-p :递归创建目录

4. rmdir

删除目录,目录必须为空。

1
2
rmdir [-p] 目录名称
-p :递归删除目录

5. touch

更新文件时间或者建立新文件。

1
2
3
4
5
6
# touch [-acdmt] filename
-a : 更新 atime
-c : 更新 ctime,若该文件不存在则不建立新文件
-m : 更新 mtime
-d : 后面可以接更新日期而不使用当前日期,也可以使用 --date="日期或时间"
-t : 后面可以接更新时间而不使用当前时间,格式为[YYYYMMDDhhmm]

6. cp

复制文件。如果源文件有两个以上,则目的文件一定要是目录才行。

1
2
3
4
5
6
7
8
cp [-adfilprsu] source destination
-a :相当于 -dr --preserve=all
-d :若来源文件为链接文件,则复制链接文件属性而非文件本身
-i :若目标文件已经存在时,在覆盖前会先询问
-p :连同文件的属性一起复制过去
-r :递归复制
-u :destination 比 source 旧才更新 destination,或 destination 不存在的情况下才复制
--preserve=all :除了 -p 的权限相关参数外,还加入 SELinux 的属性, links, xattr 等也复制了

7. rm

删除文件。

1
2
# rm [-fir] 文件或目录
-r :递归删除

8. mv

移动文件。

1
2
3
# mv [-fiu] source destination
# mv [options] source1 source2 source3 .... directory
-f : force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖

“How do I view the data one page at a time”

1
more file

Biostat:

cat SGD_features.tab |cut -f 2|sort |uniq -c|sort -rn|head

tree

Rsync|scp

Sed

cut

awk

shell 脚本

$1,$2 可以在终端依次接受参数。

1
2
3
for name in *.fastq; do
echo cutadapt -l 20 $name -o $name.trimmed.fq
done
1
2
3
4
begin=$(date +%s -d $class)
current_date="`date +%s`"
current=$(($current_date-28800-$begin))
echo $(($current/60

md5sum chr22.fa.gz >md5.txt

md5sum -c md5.txt

进程管理

Ctrl + Z : 终止执行
Ctrl + C :暂停执行,挂到后台。
jobs :查看在后台执行的进程
& : 命令末尾加上,可在后台执行。
fg n: 将命令进程号码为N的命令进程放到前台执行
bg n :将命令进程号码为N的命令进程放到后台执行

1
2
nohup comand &>nohup.out
fg 3

附表

命令缩写一览表

摘要

每每都会忘记linux命令,不过我记得全拼的时候可能就能想起来了。

wc :word counter(计算行数,单词数,字母数) “prints the number of lines, words, and characters in the stream:”

ls:list(列出目录内容)

cd:Change Directory(改变目录)

su:switch user 切换用户

rpm:redhat package manager 红帽子打包管理器

pwd:print work directory 打印当前目录显示出当前工作目录的绝对路径

ps: process status(进程状态,类似于 windows 的任务管理器)

常用参数:-auxf

ps -auxf 显示进程状态

df: disk free 其功能是显示磁盘可用空间数目信息及空间结点信息。换句话说,就是报告在任何安装的设备或目录中,还剩多少自由的空间。

rpm:即 RedHat Package Management,是 RedHat 的发明之一

rmdir:Remove Directory(删除目录)

rm:Remove(删除目录或文件)

cat: concatenate 连锁 cat file1 file2>>file3把文件1和文件2的内容联合起来放到 file3中

insmod: install module,载入模块

ln -s : link -soft 创建一个软链接,相当于创建一个快捷方式

mkdir:Make Directory(创建目录

touch

man: Manual

pwd:Print working directory

su:Swith user

cd:Change directory

ls:List files

ps:Process Status

mkdir:Make directory

rmdir:Remove directory

mkfs: Make file system

fsck:File system check

cat: Concatenate

uname: Unix name

df: Disk free

du: Disk usage

lsmod: List modules

mv: Move file

rm: Remove file

cp: Copy file

ln: Link files

fg: Foreground

bg: Background

chown: Change owner

chgrp: Change group

chmod: Change mode

umount: Unmount

dd: 本来应根据其功能描述“Convert an copy”命名为“cc”,但“cc”已经被用以代表“C Complier”,所以命名为“dd”

tar:Tape archive

ldd:List dynamic dependencies

insmod:Install module

rmmod:Remove module

lsmod:List module

文件结尾的”rc”(如.bashrc、.xinitrc 等):Resource configuration

Knnxxx / Snnxxx(位于 rcx.d 目录下):K(Kill);S(Service);nn(执行顺序号);xxx(服务标识)

.a(扩展名 a):Archive,static library

.so(扩展名 so):Shared object,dynamically linked library

.o(扩展名 o):Object file,complied result of C/C++ source file

RPM:Red hat package manager

dpkg:Debian package manager

apt:Advanced package tool(Debian 或基于 Debian 的发行版中提供)

bin = BINaries

/dev = DEVices

/etc = ETCetera

/lib = LIBrary

/proc = PROCesses

/sbin = Superuser BINaries

/tmp = TeMPorary

/usr = Unix Shared Resources

/var = VARiable ?

FIFO = First In, First Out

GRUB = GRand Unified Bootloader

IFS = Internal Field Seperators

Tk = ToolKit

VT = Video Terminal

YaST = Yet Another Setup Tool

apache = “a patchy” server

apt = Advanced Packaging Tool

ar = archiver

as = assembler

awk = “Aho Weiberger and Kernighan” 三个作者的姓的第一个字母

bash = Bourne Again SHell

bc = Basic (Better) Calculator

bg = BackGround

biff = 作者 Heidi Stettner 在 U.C.Berkely 养的一条狗,喜欢对邮递员汪汪叫。

cal = CALendar

cat = CATenate

cd = Change Directory

chgrp = CHange GRouP

chmod = CHange MODe

chown = CHange OWNer

chsh = CHange SHell

cmp = compare

cobra = Common Object Request Broker Architecture

comm = common

cp = CoPy

cpio = CoPy In and Out

cpp = C Pre Processor

cron = Chronos 希腊文时间

cups = Common Unix Printing System

cvs = Current Version System

daemon = Disk And Execution MONitor

dc = Desk Calculator

dd = Disk Dump

df = Disk Free

diff = DIFFerence

dmesg = diagnostic message

du = Disk Usage

ed = editor

egrep = Extended GREP

elf = Extensible Linking Format

elm = ELectronic Mail

emacs = Editor MACroS

eval = EVALuate

ex = EXtended

exec = EXECute

fd = file descriptors

fg = ForeGround

fgrep = Fixed GREP

fmt = format

fsck = File System ChecK

fstab = FileSystem TABle

fvwm = F*** Virtual Window Manager

gawk = GNU AWK

gpg = GNU Privacy Guard

groff = GNU troff

hal = Hardware Abstraction Layer

joe = Joe’s Own Editor

ksh = Korn SHell

lame = Lame Ain’t an MP3 Encoder

lex = LEXical analyser

lisp = LISt Processing = Lots of Irritating Superfluous Parentheses

ln = LiNk

lpr = Line PRint

ls = list

lsof = LiSt Open Files

m4 = Macro processor Version 4

man = MANual pages

mawk = Mike Brennan’s AWK

mc = Midnight Commander

mkfs = MaKe FileSystem

mknod = MaKe NODe

motd = Message of The Day

mozilla = MOsaic GodZILLa

mtab = Mount TABle

mv = MoVe

nano = Nano’s ANOther editor

nawk = New AWK

nl = Number of Lines

nm = names

nohup = No HangUP

nroff = New ROFF

od = Octal Dump

passwd = PASSWorD

pg = pager

pico = PIne’s message COmposition editor

pine = “Program for Internet News & Email” = “Pine is not Elm”

ping = 拟声又 = Packet InterNet Grouper

pirntcap = PRINTer CAPability

popd = POP Directory

pr = pre

printf = PRINT Formatted

ps = Processes Status

pty = pseudo tty

pushd = PUSH Directory

pwd = Print Working Directory

rc = runcom = run command, rc 还是 plan9的 shell

rev = REVerse

rm = ReMove

rn = Read News

roff = RunOFF

rpm = RPM Package Manager = RedHat Package Manager

rsh, rlogin, rvim 中的 r = Remote

rxvt = ouR XVT

seamoneky = 我

sed = Stream EDitor

seq = SEQuence

shar = SHell ARchive

slrn = S-Lang rn

ssh = Secure SHell

ssl = Secure Sockets Layer

stty = Set TTY

su = Substitute User

svn = SubVersioN

tar = Tape ARchive

tcsh = TENEX C shell

tee = T (T 形水管接口)

telnet = TEminaL over Network

termcap = terminal capability

terminfo = terminal information

tex = τ

wc word counter

参考

鸟哥的linux私房菜 第三版

https://cyc2018.github.io/CS-Notes/#/notes/Linux

命令缩写

查询手册

-------------本文结束感谢您的阅读-------------