linux常用基本命令

ls

常用参数

-a all列出包括隐藏文件在内的所有文件

-l 包括文件名、文件权限、所有者、文件大小等

-s 以块为单位输出文件大小

-i 输出文件inode

-t 以文件修改时间排序

lsblk(List Block Devices)

常用参数

uname(Unix name)

-a 内核名称 主机名 内核版本号 内核版本 硬件名 处理器类型 硬件平台类型 操作系统名称

-n nodename主机名

-r release内核版本号

-v version内核版本

-p 处理器类型

-i 硬件平台类型

-o 操作系统名称

history

Ctrl+R可以搜索并执行使用过的命令

sudo(super user do)

mkdir(make directory)

touch

chmod(change file mode bits)

文件的三种权限如下:

4  read(r)
2  write(w)
1  execute(x)
0  无任何权限

可以利用数字相加代表用户拥有的权限,如 chmod 777 examplefile 表示将examplefile文件对所有可读可写可执行。

用法如下:

chmod [who][+|-|=][权限]

who:

u 目录或文件的当前用户
g 目录或当前文件的用户群
o 除了u和g之外的所有用户
a 所有用户和群组

chown(change file owner group)

修改文件的拥有者,只能root操作,也可以sudo。

chown tom:root examplefile

tar(tape archive)

# .tar.gz文件的压缩和解压
tar -zxvf examplefile.tar.gz -C targetDir
tar -zcvf examplefile.tar.gz examplefile

# .tar.bz2压缩和解压
tar -jxvf examplefile.tar.bz2 -C targetDir
tar -jcvf examplefile.tar.bz2 examplefile

# .zip文件压缩和解压
unzip examplefile. -C targetDir
zip examplefile.zip examplefile

# .rar
rar x examplefile -C targetDir
rar a examplefile.rar examplefile

cat(concatenation)

标准输出文件,有覆盖(>)和追加(>>)两种

cat a.txt b.txt c.txt >> c.txt

当有海量文件时,使用通配符使用功能更强大,常用的通配符有:

Wildcard            Matches
*           zero or more characters
?           exactly one character
[abcde]         exactly one character listed
[a-e]           exactly one character in the given range
[!abcde]        any character that is not listed
[!a-e]          any character that is not in the given range
{debian,linux}      exactly one entire word in the options given

cp(copy)

mv(move)

pwd(print work directory)

cal

date

find

查找目录下的内容,如查找当前目录下的文件,find -name *.sh

grep

man

ps(process)

参数

-a 显示同一终端下的所有进程

-x 显示所有进程不分终端机来区别

-u 显示进程的所有者

-e 显示所有进程

-f 显示UID,PPIP,C与STIME栏位。

kill

用法
kill [信号或选项] PID(s)

信号有:

 1) SIGHUP   2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT  7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
31) SIGSYS  34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX    

如我们经常使用强制杀死进程:

kill -9 pid1 pid2 pid3...

上面的 -9 就是对应的信号是SIGKILL,故上面的语句又可以写成

kill SIGKILL pid1 pid2 pid3...

若想在杀死进程之前需要时间存储进度,可以使用:

kill SIGTERM pid1 pid2 pid3...
或
kill -15 pid1 pid2 pid3...

查找进程并杀死:

kill -9 $(ps -ef | grep )

whereis

service

nohup

nohup表示不挂断,即关闭终端,脚本依然运行,&表示以后台方式运行,如果不加前面的nohup,关闭终端,脚本会结束运行,如:

nohup sh /etc/sh/shadowsocks.sh>>/etc/sh/nohup.out 2>&1 &

lsof

查看占用某个端口的进程:

lsof -i:1080

参考

Switching From Windows to Nix or a Newbie to Linux – 20 Useful Commands for Linux Newbies

20 Advanced Commands for Middle Level Linux Users

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值