博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
shell——判断文件是否存在
阅读量:4050 次
发布时间:2019-05-25

本文共 3219 字,大约阅读时间需要 10 分钟。

初次使用Markdown编辑器来编写博客,希望有不一样的体会

本文通过网络文章来体会下shell中对文件的操作

  • 1、这个编辑器和wiki有点像呢
  • 2、Shell是一个很好用的脚本

以下为shell下的具体操作

shell判断文件,目录是否存在或者具有权限

” #!/bin/sh

myPath=”/var/log/httpd/”
myFile=”/var /log/httpd/access.log”

”这里的-x 参数判断$myPath是否存在并且是否具有可执行权限

if [ ! -x “ myPath];thenmkdir myPath”

fi

”# 这里的-d 参数判断$myPath是否存在,如果不存在则进行创建

if [ ! -d “ myPath];thenmkdir myPath”

fi

”# 这里的-f参数判断$myFile是否存在

if [ ! -f “ myFile];thentouch myFile”

fi

”# 其他参数还有-n,-n是判断一个变量是否是否有值

if [ ! -n “ myVar];thenecho myVar is empty”
exit 0
fi

”# 两个变量判断是否相等

if [ “ var1"=" var2” ]; then
echo ‘ var1eq var2’
else
echo ‘ var1noteq var2’
fi

判断文件是否可读,然后根据结果进行不同的操作

myfile=”/home/qatest/abc.txt”

[ -r “ myfile]||echocannotreadabc.txt;exit1;echo myfile is from: ”
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 ,  扩展了很多好用的功能。具体请参考.

表格

Markdown Extra 表格语法:

项目 价格
Computer $1600
Phone $12
Pipe $1

可以使用冒号来定义对齐方式:

项目 价格 数量
Computer 1600 元 5
Phone 12 元 12
Pipe 1 元 234

定义列表

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'''

脚注

生成一个脚注.

目录

[TOC]来生成目录:

数学公式

使用MathJax渲染LaTex 数学公式,详见.

  • 行内公式,数学公式为: Γ(n)=(n1)!nN
  • 块级公式:

x=b±b24ac2a

更多LaTex语法请参考 .

UML 图:

可以渲染序列图:

或者流程图:

  • 关于 序列图 语法,参考 ,
  • 关于 流程图 语法,参考 .

离线写博客

即使用户在没有网络的情况下,也可以通过本编辑器离线写博客(直接在曾经使用过的浏览器中输入即可。Markdown编辑器使用浏览器离线存储将内容保存在本地。

用户写博客的过程中,内容实时保存在浏览器缓存中,在用户关闭浏览器或者其它异常情况下,内容不会丢失。用户再次打开浏览器时,会显示上次用户正在编辑的没有发表的内容。

博客发表后,本地缓存将被删除。 

用户可以选择 把正在写的博客保存到服务器草稿箱,即使换浏览器或者清除缓存,内容也不会丢失。

注意:虽然浏览器存储大部分时候都比较可靠,但为了您的数据安全,在联网后,请务必及时发表或者保存到服务器草稿箱

浏览器兼容

  1. 目前,本编辑器对Chrome浏览器支持最为完整。建议大家使用较新版本的Chrome。
  2. IE9以下不支持
  3. IE9,10,11存在以下问题
    1. 不支持离线功能
    2. IE9不支持文件导入导出
    3. IE10不支持拖拽文件导入


  1. 这里是 脚注内容.

转载地址:http://rlcci.baihongyu.com/

你可能感兴趣的文章
[LeetCode By Python]136. Single Number
查看>>
Android/Linux 内存监视
查看>>
Android2.1消息应用(Messaging)源码学习笔记
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>
[Mac]Mac 操作系统 常见技巧
查看>>
苹果Swift编程语言入门教程【中文版】
查看>>
捕鱼忍者(ninja fishing)之游戏指南+游戏攻略+游戏体验
查看>>
iphone开发基础之objective-c学习
查看>>
iphone开发之SDK研究(待续)
查看>>
计算机网络复习要点
查看>>
Variable property attributes or Modifiers in iOS
查看>>
NSNotificationCenter 用法总结
查看>>
C primer plus 基础总结(一)
查看>>
剑指offer算法题分析与整理(三)
查看>>
Ubuntu 13.10使用fcitx输入法
查看>>
pidgin-lwqq 安装
查看>>
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>