`
wyzuomumu
  • 浏览: 104670 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SHELL点滴

阅读更多

1.Shell判断文件是否存在

 

#!/bin/sh
myPath="/var/log/httpd/"
myFile="/var /log/httpd/access.log"
# 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限
if [ ! -x "$myPath" ]; then
mkdir "$myPath"
fi
 # 这里的-d 参数判断$myPath是否存在
 if [ ! -d "$myPath" ]; then
 mkdir "$myPath"
 fi

 # 这里的-f参数判断$myFile是否存在
 if [ ! -f "$myFile" ]; then
 touch "$myFile"
 fi
 # 其他参数还有-n,-n是判断一个变量是否是否有值
 if [ ! -n "$myVar" ]; then
 echo "$myVar is empty"
 exit 0
 fi

 # 两个变量判断是否相等
 if [ "$var1" = "$var2" ]; then
 echo '$var1 eq $var2'
 else
 echo '$var1 not eq $var2'
 fi
-f 和-e的区别 

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. 


是用 -s 还是用 -f 这个区别是很大的!


2.Shell算术运算

 

$[1+2] #value:3

`expr 1 + 2` #value:3

$((1 + 2)) #value:3

 

3.遍历文件的每行数据

while read lines

do

echo $lines

done<filename#filename为文件名

 

4.提取行数据

awk语法:awk /pattern/{action} filename

awk简单用法

获取文件第一,列的数据:

awk '{print $1}' filename

 

5.显示日期格式为yyyyMMdd

date +%Y%m%d

 

6.Map通过key值排序的简单小例子

 

HashMap<String, String> map = new HashMap<String, String>();
map.put("2012-07-04", "2012-07-04");
map.put("2012-07-03", "2012-07-03");
map.put("2012-07-07", "2012-07-07");
map.put("2012-07-01", "2012-07-01");

Object[] key = map.keySet().toArray();
Arrays.sort(key);
for (int i = 0; i < key.length; i++) {
	System.out.println(map.get(key[i]));
}



 

分享到:
评论

相关推荐

    B shell与 C shell的区别

    B shell与 C shell的区别 ; B shell的详解和C shell 的详解

    shell shell练习 shell入门

    shell shell练习 shell入门 shell shell练习 shell入门

    shell算法shell算法shell算法

    shell排序shell排序shell排序shell排序shell排序shell排序shell排序

    shell讲义shell讲义

    shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义shell讲义...

    Shell源码(Shell源码)

    Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码Shell源码

    shell 编程shell 编程

    shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程shell 编程...

    UNIX shell 编程指南

    shell编程技巧点滴(基础篇) shell 脚本修改crontab实例 如何删除大量文件 如何删除某个月份的文件 find的日常用法举例 find的日常用法帮助 如何批量改名 bc指令的基本用法 检查服务器的连接状况的shell find 和 exec...

    LinuxShell脚本学习基础视频

    资源名称:Linux Shell脚本学习基础视频资源目录:【】11a00d99b60c4e2eba3440b8aa3a6bdd【】linux_shell脚本编程_01认识shell,如何编写shell脚本和执行【】linux_shell脚本编程_02vivim简单的常用操作【】linux_...

    shell编程点滴.chm

    Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这...另一方面也可以帮助用户组织文件,并为用户提供安全性保护。... ...  · 用户口令的管理。...

    shell编程指南shell编程指南shell编程指南shell编程指南

    shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南shell编程指南

    shell语言编程shell语言编程

    shell shellshellshell shell shell shell

    shell帮助文档shell帮助文档shell帮助文档

    shell帮助文档shell帮助文档shell帮助文档shell帮助文档shell帮助文档shell帮助文档shell帮助文档

    sshshell.zip

    sshshell ssh shell 服务器 远程连接 FTP for mac ssh shell 服务器 远程连接

    Shell脚本中获取进程ID的方法

    提问: 我想要知道运行中脚本子shell的进程id。我该如何在shell脚本中得到PID。 当我在执行shell脚本时,它会启动一个叫子shell的进程。作为主shell的子进程,子shell将shell脚本中的命令作为批处理运行(因此称为...

    Linux 下 Shell的工作原理

    shell是用户和Linux操作系统之间的接口。 什么是shell  Linux系统的shell作为操作系统的外壳,为用户提供使用操作系统的接口。它是命令语言、命令解释程序及程序设计语言的统称。  shell是用户和Linux内核之间的...

    shell精品教程shell精品教程shell精品教程

    linux shell 精品 教程 学习shell必看

    shell高级编程 shell的经典教程

    shell 是操作系统的最外层。shell 合并编程语言以控制进程和文件,以及启动和控制其它程序。shell 通过提示您输入,向操作系统解释该输入,然后处理来自操作系统的任何结果输出来管理您与操作系统之间的交互。  ...

    Shell编程详解,shell入门,shell实例

    Shell编程详解,shell入门,shell实例

    Unix Shell Shell编程

    6本pdf及chm的shell 编程的书 6本pdf及chm的shell 编程的书 6本pdf及chm的shell 编程的书 6本pdf及chm的shell 编程的书 6本pdf及chm的shell 编程的书

    shell 编程指南pdf

    初学shell 入门好书!!!! 目 录 译者序 前言 第一部分 shell 第1章 文件安全与权限 1 1.1 文件 1 1.2 文件类型 2 1.3 权限 2 1.4 改变权限位 4 1.4.1 符号模式 4 1.4.2 chmod命令举例 5 1.4.3 绝对模式 5 1.4.4 ...

Global site tag (gtag.js) - Google Analytics