学习Linux-------------第一天

其实学习Linux已经不是第一天了.只是之前一直都没有写过学习笔记,这次准备重新写一遍

在vi编辑器中
查找
/keyword
?keyword
翻页
向后翻一屏 :space
向前翻一屏:B
向后一行:enter
向前一行:K
sapce b 翻页
enter k 翻行
ctrl+d ctrl+u 翻半屏

查找:
/需要查找的对象: 向后
n:下一个
N:前一个
?需要查找的对象: 向前
n:下一个
N:前一个

q 退出
#G 数字+G 跳到第几行,如果什么都数字都不加直接G切换到最末行
q:退出


修改时间:
date 查看系统时间
date -s 设置系统时间
date -s "07/20/19 16:15:20" 格式: “ 月/日/年 时:分:秒 ”
date 07181144 或者 格式 “月日时分年”
上面是手动配置系统时间的
还可以直接同步网络世间,通过ntpdate命令实现
ntpdate time.nist.gov等时间服务器
time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org
往往这样配置了之后还是不能够确保服务器时间一定不出问题。这样我们最好让服务器定时的去更新自己的系统时间
这里我们通过 crontab -e来添加定时任务
~]# crontab -e
进入像vi编辑器一样的界面。在这里面添加我们系统的定时任务
* * * * *
五个星分别代表 分,时,日,月,周
全*表示每分钟执行一次,如果要每隔多少分钟就是*/5 * * * * ,表示每隔5分钟执行一次
周最好不要和天重复,很容易混淆,这几个的关系是包含
*/20 * * * * root ntpdate time.nuri.net;hwclock -w
每20分钟同步一次网络时间,并且将系统时间写入硬件时间。
Linux系统有2个时间,一个是系统时间date查看,一个是硬件时间hwclock查看
hwclock -w:让硬件时间学习系统时间
hwclock -s:让系统时间学习硬件时间


命令:查询一个命令是内部还是外部使用type命令
type command
内部命令:系统自带的命令builtin
外部命令:有一个配置文件的命令,显示为命令文件的路径。命令可以有别名,别名可以与原名相同。此时原名被隐藏;此时如果需要运行原命令。则使用\command

命令别名:
获取所有可用别名的定义:
~]# alias
定义别名:
~]# alias NAME=command
撤销别名:
~]# unalias NAME
如果想要永久生效,则需要写入配置文件

type 命令主要用于查看一个命令是否是系统自带的命令

~]# type ls 用type查看ls时,显示ls是一个系统别名。他的真实命令是 ls --color
ls is aliased to `ls --color=auto'

~]# type if 用type查看if时,提示if是shell的关键字
if is a shell keyword

~]# type type 用type查看type时,提示type是一个系统内置的命令
type is a shell builtin

~]# type gedit 用type查看gedit时,提示没有找到该命令
-bash: type: gedit: not found
type同时可以用在脚本中:
用来判断一个名字是否是alias(别名),keyword(关键字),function(函数),builtin(内置命令),file(文件),或者什么都不是
比如:
~]# type -t ls 用type -t查看ls命令, 显示alias
alias

~]# type -t if 用type -t查看if命令, 显示keyword
keyword

~]# type -t type 用type -t查看type命令, 显示bulitin
builtin

~]# type -t file 用type -t查看file命令, 显示file
file

~]# type -t frydsh 用type -t查看frydsh命令, 显示什么都没有,为空
当然平时用的比较多少的还是用来查看一个字符的类型


echo命令
echo 主要是用来输出结果的如果我们希望输出的信息可以换行,则需要在echo命令中加上-e的参数如:

另一个输出命令:printf(格式化输出)

printf命令后面直接跟string的效果跟 echo -n string的效果是一样的
所以printf在直接输出的时候需要加上\n换行符进行换行。如:

[syn@localhost ~]$ printf "today is good day"
today is good day[syn@localhost ~]$
上面是默认输出效果
[syn@localhost ~]$ printf "today is good day\n"
today is good day
下面是加换行符效果


whereis command
-b: 直接查看命令地址
-m: 查看命令的手册地址

who
查看用户
-b:系统最后一次开机时间
-r:当前的运行级别

获取帮助:
command --help
man command
info command
google
文档:/usr/share/doc

练习:
1、echo的命令类型 :
type echo
2、使用帮助:
man echo
3、如何换行显示:
echo 的命令使用如果需要使用转义符需要加-e选项
如:
[root@localhost doc]# echo -e "today is 07/18,\nnow is 12:37"
today is 07/18,
now is 12:37

1、printf的命令类型 :
[root@localhost doc]# printf
printf: usage: printf [-v var] format [arguments]
2、使用帮助:

3、如何换行显示:
[root@localhost doc]# printf "today is new life\n"
today is new life

[root@localhost doc]# printf "today is new life\nthis time is 12:43"
today is new life
this time is 12:43[root@localhost doc]#
所以需要每一行后面都需要加 “ \n ” 换行符

file命令及其用法:
查看所用的shell类型
[root@localhost doc]# echo $SHELL
/bin/bash

远程连接
ssh协议:secure shell
ss -tnl
可以查看tcp下的端口
ifconfig
ip addr list
查看IP地址

确保防火墙是关闭状态
~]# iptables -L -n
~]# iptables -f
Centos 7:
~]# systemctl disable firewalld.service
~]#s ystemctl stop firewalld.service
Centos 6:
~]# service iptables stop
~]# chkconfig iptables off


猜你喜欢

转载自www.cnblogs.com/rsyn/p/12081154.html