linux technology share notes

1. View Log

Display command file using less, PageUp keys with Page Up, Page Down keys with PageDown. To exit the program less, should the Q key.

// Check log.txt log file to the line that there are spring and 10 rows back and forth to print out

[root@Slave2 test1]#               less log.txt | grep "spring" -C 10

Dynamic view the log:? Less log.txt -> shift + g pulled the last -> / + or keyword search

2. Add the environment variable

/ etc / profile: This file is set up for each user environment information system, when a user first logs in, the file is executed.
and collect shell settings from the configuration file /etc/profile.d directory.

~ / .bash_profile: Each user can use the file input information specific to shell their own use, when a user logs in, the
file is performed only once by default, he set some environment variables, execute .bashrc file users!.
3. Timing execution (measured their affinity both methods)

The first step: [root @ Slave2 crontabTest] # crontab -u root -e
Step two: add the following command syntax
* / 1 * * * * echo ". Have a break now" >> /tmp/test.txt // run the command
* / 1 * * * * /root/zhangwenqiang1/test1/funct.sh >> / tmp / test.txt// run the script file

or

The first step: [root @ Slave2 crontabTest] # vim / etc / crontab

Step two: * / 1 * * * * root run-parts / root / zhangwenqiang1 / crontabTest >> / tmp / test.txt // run all folder files


************************************************************************************
cron is a linux under the regular implementation of the tool, you can run the job without the need for manual intervention. Because Linux Cron is a built-in services, but it does not auto-up, you can start with the following methods to close this service:
 
/ sbin / service crond start // start the service
/ sbin / service crond stop // close the service
/ sbin / service crond restart // restart the service
/ sbin / service crond reload // reload the configuration
 
You can also use this service to start automatically at system startup:
 
At the end of the /etc/rc.d/rc.local script plus:
/ sbin / Service crond Start
 
Cron is now in the process of this service has been there, and we can use this service, the Cron service provides several interfaces for your use:
 
1. crontab command directly edit
 
cron service providers to set the cron crontab command service, the following are some of the parameters and description of this command:
 
crontab -u // set a user's cron service, usually root user needs this parameter when executing this command
crontab -l // set out in detail the contents of a user cron services
crontab -r // not delete a user's cron service
crontab -e // edit a user's cron service
 
比如说root查看自己的cron设置:crontab -u root -l
再例如,root想删除fred的cron设置:crontab -u fred -r
在编辑cron服务时,编辑的内容有一些格式和约定,输入: crontab -u root -e
 
进入vi编辑模式,编辑的内容一定要符合下面的格式:*/1 * * * * ls >> /tmp/ls.txt
 
这个格式的前一部分是对时间的设定,后面一部分是要执行的命令,如果要执行的命令太多,可以把这些命令写到一个脚本里面,然后在这里直接调用这个脚本就可以了,调用的时候记得写出命令的完整路径。时间的设定我们有一定的约定,前面五个*号代表五个数字,数字的取值范围和含义如下:
 
分钟 (0-59)
小時(0-23)
日期(1-31)
月份(1-12)
星期(0-6//0代表星期天
 
    除了数字还有几个个特殊的符号就是"*"、"/"和"-"、",",*代表所有的取值范围内的数字,"/"代表每的意思,"*/5"表示每5个单位,"-"代表从某个数字到某个数字,","分开几个离散的数字。以下举几个例子说明问题:
 
每天早上6点
-----------------
0 6 * * * echo "Good morning." >> /tmp/test.txt //注意单纯echo,从屏幕上看不到任何输出,因为cron把任何输出都email到root的信箱了。
 
每两个小时
-----------------
0 */2 * * * echo "Have a break now." >> /tmp/test.txt
 
晚上11点到早上8点之间每两个小时,早上八点
-----------------
0 23-7/28 * * * echo "Have a good dream:)" >> /tmp/test.txt
 
每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点
-----------------
0 11 4 * 1-3 command line
 
1月1日早上4点
-----------------
0 4 1 1 * command line
 
    每次编辑完某个用户的cron设置后,cron自动在/var/spool/cron下生成一个与此用户同名的文件,此用户的cron信息都记录在这个文件中,这个文件是不可以直接编辑的,只可以用crontab -e 来编辑。cron启动后每过一份钟读一次这个文件,检查是否要执行里面的命令。因此此文件修改后不需要重新启动cron服务。
 
2.编辑/etc/crontab 文件配置cron
 
    cron服务每分钟不仅要读一次/var/spool/cron内的所有文件,还需要读一次/etc/crontab因此我们配置这个文件也能运用cron服务做一些事情。用crontab配置是针对某个用户的,而编辑/etc/crontab是针对系统的任务。此文件的文件格式是:
 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //如果出现错误,或者有数据输出,数据作为邮件发给这个帐号
HOME=/      //使用者运行的路径,这里是根目录
# run-parts
01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本
02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本
22 4 * * 0 root run-parts /etc/cron.weekly //每星期执行/etc/cron.weekly内的脚本
42 4 1 * * root run-parts /etc/cron.monthly //每月去执行/etc/cron.monthly内的脚本
 
大家注意"run-parts"这个参数了,如果去掉这个参数的话,后面就可以写要运行的某个脚本名,而不是文件夹名了。
************************************************************************************

4.查看磁盘容量

df- report file system disk space usage

df-l/df-lh



5.赋予权限

三种访问权限

r- 读取权限

w- 写权限

x-执行权限

三种访问级别

u- 文件的owner

g- 用户组

o- 其他用户

a-所有用户


chmod<permission><files>

eg:

chmod a+x abc.sh

chmod g-x abc.sh

chmod +x abc.sh

chmod -R a+x abc/           //-R代表递归

chmod 777 abc.sh

chmod a-wx,a+r  abc.sh










发布了159 篇原创文章 · 获赞 75 · 访问量 19万+

Guess you like

Origin blog.csdn.net/xuehuagongzi000/article/details/66478622