shell 获取 目录名 当前目录名】的更多相关文章

转自http://blog.csdn.net/universe_hao/article/details/52640321 shell 提取文件名和目录名 在写shell脚本中,经常会有需要对路径和文件名做处理.有时候犯不着用sed命令来操作.bash提供的变量操作和一些外部命令都能很好的处理.   一.使用变量操作符 ${} 1.${var##*/} 该方式是从左开始最大化匹配到字符"/",然后截掉左边内容(包括字符"/"),返回余下右侧部分. $ var=/dir…
转载地址:http://weyo.me/pages/techs/linux-get-pid/ 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运行进程,因此在获取进程 pid 上二者也有所区别. 交互式 Bash Shell 获取进程 pid 在已知进程名(name)的前提下,交互式 Shell 获取进程 pid 有很多种方法,典型的通过 grep 获取 pid 的方法为(这里添加 -v grep是为了避免匹配到 grep 进程): ps…
用C++和shell获取本机CPU.网卡.内存.磁盘等的基本信息: 由于对C++相关的函数没多少了解,但是觉得用shell反而相对简单一些: 一.shell脚本,用来辅助C++获取主机的资源使用信息 (1) cpurate.sh 获取cpu的使用率 #!/bin/sh ##echo user nice system idle iowait irq softirq CPULOG_1=$(cat /proc/stat | grep 'cpu ' | awk '{print $2" "$3&…
linux中用shell获取昨天.明天或多天前的日期 时间 -- :: BlogJava-专家区 原文 http://www.blogjava.net/xzclog/archive/2015/12/08/428555.html 主题 Shell 原文地址:http://www.itwis.com/html/os/linux/20100202/7360.html linux中用shell获取昨天.明天或多天前的日期: 在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:…
linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time described by STRING, not `now’[root@Gman root]# date -d next-day +%Y%m%d #明天日期20091024[root@Gman root]# date -d last-day +%Y%m%d #昨天日期20091022[root@Gma…
shell 获取网关 以及修改ip 启用网卡 #!/bin/bash #autho freefei #script is a init computer eth #data 2014 10 09 192.168.1.1 netstats=$(netstat -r|grep default|cut -f 10 -d ' '); echo $netstats; #change other ifcfg eth1Path=/etc/sysconfig/network-scripts/ifcfg-eth1…
最近要获取服务器各种参数,包括cpu.内存.磁盘.型号等信息.试用了Hyperic HQ.Nagios和Snmp,它们功能都挺强大的,但是于需求不是太符,亦或者太heavy. 于是乎想到用python执行shell获取这些信息,python执行shell脚本有以下三种方法: 1. os.system() os.system('ls')#返回结果0或者1,不能得到命令的输出 2. os.popen() output = os.popen('ls') print output.read()#打印出的…
Shell获取格式化日期 shell date 获取昨天日期 使用date -d 选项: date +"%Y%m%d" -d "+n days" 今天的后n天日期 date +"%Y%m%d" -d "-n days" 今天的前n天日期 例如: [root@test-.dev.rokid-inc.com /home/zhangzhenghai] #date +"%Y%m%d" [root@test-.dev…
这篇文章主要介绍了Shell获取文件的文件名和扩展名的例子,简明版的代码实例,看了就懂,需要的朋友可以参考下 basename example.tar.gz .tar.gz # => example FILE="example.tar.gz" echo "${FILE%%.*}" # => example echo "${FILE%.*}" # => example.tar echo "${FILE#*.}"…
转载地址:http://weyo.me/pages/techs/linux-get-pid/ 根据pid,kill该进程:http://www.cnblogs.com/lovychen/p/5411391.html 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运行进程,因此在获取进程 pid 上二者也有所区别. 交互式 Bash Shell 获取进程 pid 在已知进程名(name)的前提下,交互式 Shell 获取进程 pid 有很多…