shell——判断文件是否存在
来源:互联网 发布:沙钢网络管理学院 编辑:程序博客网 时间:2024/06/14 22:36
初次使用Markdown编辑器来编写博客,希望有不一样的体会
本文通过网络文章来体会下shell中对文件的操作
- 1、这个编辑器和wiki有点像呢
- 2、Shell是一个很好用的脚本
以下为shell下的具体操作
shell判断文件,目录是否存在或者具有权限
” #!/bin/sh
myPath=”/var/log/httpd/”
myFile=”/var /log/httpd/access.log”
”这里的-x 参数判断$myPath是否存在并且是否具有可执行权限
if [ ! -x “
fi
”# 这里的-d 参数判断$myPath是否存在,如果不存在则进行创建
if [ ! -d “
fi
”# 这里的-f参数判断$myFile是否存在
if [ ! -f “
fi
”# 其他参数还有-n,-n是判断一个变量是否是否有值
if [ ! -n “
exit 0
fi
”# 两个变量判断是否相等
if [ “
echo ‘
else
echo ‘
fi
判断文件是否可读,然后根据结果进行不同的操作
myfile=”/home/qatest/abc.txt”
[ -r “
grep “^first ” $myfile
如果可读则:打印该文件中的”first”一行
如果不可读则:则打印错误信息,然后退出
以下为参数列表,可进行参考。
Conditional Logic on Files
-a file exists.
-b file exists and is a block special file.
-c file exists and is a character special file.
-d file exists and is a directory.
-e file exists (just the same as -a).
-f file exists and is a regular file.
-g file exists and has its setgid(2) bit set.
-G file exists and has the same group ID as this process.
-k file exists and has its sticky bit set.
-L file exists and is a symbolic link.
-n string length is not zero.
-o Named option is set on.
-O file exists and is owned by the user ID of this process.
-p file exists and is a first in, first out (FIFO) special file or
named pipe.
-r file exists and is readable by the current process.
-s file exists and has a size greater than zero.
-S file exists and is a socket.
-t file descriptor number fildes is open and associated with a
terminal device.
-u file exists and has its setuid(2) bit set.
-w file exists and is writable by the current process.
-x file exists and is executable by the current process.
-z string length is zero.
快捷键
- 加粗
Ctrl + B
- 斜体
Ctrl + I
- 引用
Ctrl + Q
- 插入链接
Ctrl + L
- 插入代码
Ctrl + K
- 插入图片
Ctrl + G
- 提升标题
Ctrl + H
- 有序列表
Ctrl + O
- 无序列表
Ctrl + U
- 横线
Ctrl + R
- 撤销
Ctrl + Z
- 重做
Ctrl + Y
Markdown及扩展
Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的HTML页面。 —— [ 维基百科 ]
使用简单的符号标识不同的标题,将某些文字标记为粗体或者斜体,创建一个链接等,详细语法参考帮助?。
本编辑器支持 Markdown Extra , 扩展了很多好用的功能。具体请参考Github.
表格
Markdown Extra 表格语法:
可以使用冒号来定义对齐方式:
定义列表
- Markdown Extra 定义列表语法:
- 项目1
- 项目2
- 定义 A
- 定义 B
- 项目3
- 定义 C
定义 D
定义D内容
代码块
代码块语法遵循标准markdown代码,例如:
@requires_authorizationdef somefunc(param1='', param2=0): '''A docstring''' if param1 > param2: # interesting print 'Greater' return (param2 - param1 + 1) or Noneclass SomeClass: pass>>> message = '''interpreter... prompt'''
脚注
生成一个脚注1.
目录
用 [TOC]
来生成目录:
- 初次使用Markdown编辑器来编写博客希望有不一样的体会
- 以下为shell下的具体操作
- shell判断文件目录是否存在或者具有权限
- 判断文件是否可读然后根据结果进行不同的操作
- 如果可读则打印该文件中的first一行
- 如果不可读则则打印错误信息然后退出
- 以下为参数列表可进行参考
- 快捷键
- Markdown及扩展
- 表格
- 定义列表
- 代码块
- 脚注
- 目录
- 数学公式
- UML 图
- 离线写博客
- 浏览器兼容
数学公式
使用MathJax渲染LaTex 数学公式,详见math.stackexchange.com.
- 行内公式,数学公式为:
Γ(n)=(n−1)!∀n∈N 。 - 块级公式:
更多LaTex语法请参考 这儿.
UML 图:
可以渲染序列图:
或者流程图:
- 关于 序列图 语法,参考 这儿,
- 关于 流程图 语法,参考 这儿.
离线写博客
即使用户在没有网络的情况下,也可以通过本编辑器离线写博客(直接在曾经使用过的浏览器中输入write.blog.csdn.net/mdeditor即可。Markdown编辑器使用浏览器离线存储将内容保存在本地。
用户写博客的过程中,内容实时保存在浏览器缓存中,在用户关闭浏览器或者其它异常情况下,内容不会丢失。用户再次打开浏览器时,会显示上次用户正在编辑的没有发表的内容。
博客发表后,本地缓存将被删除。
用户可以选择 把正在写的博客保存到服务器草稿箱,即使换浏览器或者清除缓存,内容也不会丢失。
注意:虽然浏览器存储大部分时候都比较可靠,但为了您的数据安全,在联网后,请务必及时发表或者保存到服务器草稿箱。
浏览器兼容
- 目前,本编辑器对Chrome浏览器支持最为完整。建议大家使用较新版本的Chrome。
- IE9以下不支持
- IE9,10,11存在以下问题
- 不支持离线功能
- IE9不支持文件导入导出
- IE10不支持拖拽文件导入
- 这里是 脚注 的 内容. ↩
- shell——判断文件是否存在
- shell判断文件是否存在
- Shell--判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell 判断文件是否存在
- shell 判断文件是否存在
- shell 判断文件是否存在
- shell判断文件是否存在
- Shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell 判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- shell判断文件是否存在
- 7.设计一个抽象类Shape, 属性为x和y,表示圆心坐标,计算面积的抽象方法double area(),并设计一个计算圆心距离坐标原点距离的方法distance(double x ,double y
- OSX Vmware优化
- DLL编程的导入导出,__declspec(dllimport),__declspec(dllexport)
- mybatis——使用mapper代理开发方式
- idea几个快捷键,,(改写父类的方法)
- shell——判断文件是否存在
- UML类之间关系的通俗讲解
- 医疗行业大数据应用实例
- 下载文件
- 关于cocos2dx3.0 cpp回调lua函数新方法
- undefined reference to 'pthread_create'解决方法
- KVC 键值编程的搜索模式
- Android_UI开发详解之ActionBar
- 单例模式