Linux命令总结2
Linux命令总结2
大概前面半个月写了一些吧,后面由于忙着考试等事情就没有写了,但是还是希望自己做事情能够有始有终,把一件事坚持做完,刚好考完试也有时间了,就把剩下的一些命令总结一下吧。目的还是希望自己能多看看,因为知识这种东西,只有用你才会记着,不用就会忘记。
关于文件的一些操作
1.重命名文件
将test.png命名为temp.png
~ $ mv test.png temp.png
2.删除文件
~$ rm test.png
~$ ls
注意:‘-v’表示当文件移除时提示是否移除;‘-i’表示当文件移除时显示文件信息
~$ cp ocr_pi.png test.png
~$ ls
~$ rm -vi test.png
~$ ls3.移除目录
~$ rmdir myfiles
~$ ls
4.展示文件的内容
~$ cat lstest.txt
5.将内容打一个到屏幕输出
~$ echo $((5*6))
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191217154310227.png
注意在两个括号前需要加上 $
~ $ echo a line of text > lin.dat
6.匹配字符
~ $ grep line lin.dat
- 7.显示文件内容的前10行或者后10行
- $ head lin.dat
~$ tail lin.dat
超级用户命令
- 1.改变文件拥有者权限
- $ chmod u+rwx lin.dat
- $ ls -lh
- $ sudo chown root lin.dat
- $ ls -lh
- 2.安装软件
- $ yum insatll
注意:Ubuntu的安装软件的命令是
~$ sudo apt-get insatll
3.前台和后台的进程管理
注意:显示在屏幕上的程序是前台运行的,但是在Linux中是单线程运行的,而在后台可以运行多个应用,在后台跑的程序叫做job
强制把一个程序在后台运行在最后加上一个& - $ ls -l > files &
Task Schedule
Task Schedule的意思就是定时运行某一个程序,时间格式分别是:
下面的表格从上到下的顺序
| Minute | 0-59 |
|---|---|
| Hour | 0-23 |
| Day of month | 0-12 |
| Month of year | 1-12 |
| Day of week | 0-6 |
| String | meaning |
|---|---|
| @reboot | run once at startup |
| @yearly | run once every year |
| @monthly | run once every month |
| @weekly | run once a week |
| @daily | run once a day |
| @hourly | run once an hour |
举例:
30,50 22-23 * 6 fri-sat /home/john/mycron.sh
the meanning:
Run at the 30th and 50th minutes ,for the hour between 10 p.m. and midnight on Fridays and Saturdays during June
下面做一个小的task schedule
题目:要求每分钟执行一次myscript.sh文件脚本中的内容,其输出的文件名为:myfile
这个脚本文件的内容:
echo ‘hello there’ > /home/tml/myfile #输出到myfile中
solution:
第一步:创建myscript.sh文件
sudochmod 755 myscript.sh
crontab -e #进入vi编辑器
输入:***** /home/tml/myscript.sh #每分钟执行一次
保存后退出
执行输出文件:cat myfiles
执行结果:用esc键进入编辑状态,用:wq表示保存并退出
每分钟都会发一份邮件到mail/tml这个文件夹里面
删除all schedule tasks:
crontab -r
crontab -l
关于task schedule还有很多例子,时间原因就写一个吧。