Linux 指令学习

最近实习终于派给我了可以学到东西的活,在sxp的鼓励下开始学习指令。再次谢谢她!

  1. 密钥登陆
ssh -i [privatekey] username@ip_address

使用ssh密钥登陆

  1. 密钥上传下载
scp -i [privatekey] -r username@ip_address:remote_dictionary ./local_dictionary/

使用ssh复制文件夹到本地

scp -i [privatekey] username@ip_address:remote_dictionary/file ./local_dictionary/

使用ssh复制文件到本地

交换后面两个参数则是上传

  1. crontab

我理解的crontab是一种类似heroku scheduler的定时运行某条指令的文件。该文件包含cron(8)守护进程的指令。可以自定义时间,指令,用户。

例如:

2,7,12,17,22,27,32,37,42,47,52,57 5-19 * * * /home/solarkun/jishakanshi_sh/controlCompcs.sh MONITOR 1

表示每天5~19点的2分,7分,…,57分,运行一遍后面的指令。

crontab的设置cron 配置指南

crontab指令

crontab -l

crontab -e

  1. grep

  2. source

  3. sh文件

linux脚本类型。sh是linux中运行shell的命令,是shell的解释器。shell脚本是linux中shell与命令行界面,用户可以在shell脚本输入命令来执行各种各样的任务。

执行sh文件: ./xxx.sh

或:sh xxx.sh

sh文件有时会遇到权限问题。chmod命令可以更改权限。

chmod 744 filename

在这里,每个数字代表允许的权限的总和:

4赋予读取权限

2赋予写权限

1赋予执行权限

0没有权限

参考链接: chmod参数

  1. $ 是什么

读项目sh源码总会碰到$美元符号搭配各种各样数字字母,初学者实在很难理解。总结如下。

$+var_name: 引用变量值

$?: Expands to the exit status of the most recently executed foreground pipeline.扩展到最近执行的前台管道的退出状态。

$+number:引用传入当前脚本的第几个参数。

例如:

./script.sh filename1 dir1

$0 是脚本本身的名称 (script.sh)

$1 是第一个参数 (filename1)

$2 是第二个参数 (dir1)

$9 是第九个参数

${10} 是第十个参数,必须在 $9 之后用括号括起来。

更多特殊符号:bash特殊符号

  1. vi vim tail

vi

编辑:i,insert

退出编辑:Esc

退出vi::q

保存退出vi: :wq

vim

tail

tail -10 log_file_name: 查看最后10行log