2016年11月9日 星期三
使用 find 尋找日期區間內的檔案
find 是 Unix/Linux 中好用的尋找檔案指令,本篇介紹如何使用 find 找出指定日期區間內的檔案。
使用 touch 建立一個修改日期為 2013-01-01 的檔案
touch --date "2013-01-01" /tmp/start.txt
使用 touch 建立一個修改日期為 2013-12-31 的檔案
touch --date "2013-12-31" /tmp/end.txt
尋找 /path 裡日期在 2013-01-01 與 2013-12-31 之間的檔案
find /path -type f -newer /tmp/start.txt -not -newer /tmp/end.txt
查看建立檔案的結果
ls --full-time end.txt
-rw-r--r-- 1 root root 0 2013-12-31 00:00:00.000000000 +0800 end.txt
若是要找的檔案要當年,你需要將日期延後一天
touch --date "2014-01-01" end.txt
或是加上時間
touch --date "2013-12-31 23:59:59" end.txt
查看建立檔案的結果
ls --full-time end.txt
-rw-r--r-- 1 root root 0 2013-12-31 23:59:59.000000000 +0800 end.txt
你也可以用
find /path -newermt "2013-01-01 00:00:00" ! -newermt "2013-01-01 23:59:59" -type f
RedHat 4.x, 5.5 沒有 newermt 這參數,RedHat 7.x 就有支援這參數了
參考來源:
https://goo.gl/Xl5Npb
http://liaozi.blogspot.tw/2014/11/find.html
使用 find 尋找日期區間內的檔案
find 是 Unix/Linux 中好用的尋找檔案指令,本篇介紹如何使用 find 找出指定日期區間內的檔案。
使用 touch 建立一個修改日期為 2013-01-01 的檔案
touch --date "2013-01-01" /tmp/start.txt
使用 touch 建立一個修改日期為 2013-12-31 的檔案
touch --date "2013-12-31" /tmp/end.txt
尋找 /path 裡日期在 2013-01-01 與 2013-12-31 之間的檔案
find /path -type f -newer /tmp/start.txt -not -newer /tmp/end.txt
查看建立檔案的結果
ls --full-time end.txt
-rw-r--r-- 1 root root 0 2013-12-31 00:00:00.000000000 +0800 end.txt
若是要找的檔案要當天,你需要將日期延後一天
touch --date "2014-01-01" end.txt
或是加上時間
touch --date "2013-12-31 23:59:59" end.txt
查看建立檔案的結果
ls --full-time end.txt
-rw-r--r-- 1 root root 0 2013-12-31 23:59:59.000000000 +0800 end.txt
你也可以用
find /path -newermt "2013-01-01 00:00:00" ! -newermt "2013-01-01 23:59:59" -type f
RedHat 4.x, 5.5 沒有 newermt 這參數,RedHat 7.x 就有支援這參數了
參考來源:
https://goo.gl/Xl5Npb
http://liaozi.blogspot.tw/2014/11/find.html
2016年8月26日 星期五
command not found
CentOS
lsb_release: command not found
安裝 CentOS 7.1 用最小安裝,執行 lsb_release 出現錯誤 command not found
用以下指令查找
# yum provides */lsb_release
...
redhat-lsb-4.0-3.el6.centos.i686 : LSB base libraries support for CentOS
Repo : base
Matched from:
Filename : /usr/bin/lsb_release
redhat-lsb-4.0-3.el6.centos.x86_64 : LSB base libraries support for CentOS
Repo : base
Matched from:
Filename : /usr/bin/lsb_release
dkms-2.2.0.3-2.el6.noarch : Dynamic Kernel Module Support Framework
Repo : epel
Matched from:
Filename : /usr/lib/dkms/lsb_release
由以上資訊中
redhat-lsb-4.0-3.el6.centos.i686 : LSB base libraries support for CentOS
得知,該指令在 redhat-lsb-4.0-3.el6.centos.i686 套件中
安裝套件
# yum install redhat-lsb
...
Transaction Summary
==========================================================
Install 106 Package(s)
Total download size: 86 M
Installed size: 246 M
Is this ok [y/N]:
...
lsb_release: command not found
安裝 CentOS 7.1 用最小安裝,執行 lsb_release 出現錯誤 command not found
用以下指令查找
# yum provides */lsb_release
...
redhat-lsb-4.0-3.el6.centos.i686 : LSB base libraries support for CentOS
Repo : base
Matched from:
Filename : /usr/bin/lsb_release
redhat-lsb-4.0-3.el6.centos.x86_64 : LSB base libraries support for CentOS
Repo : base
Matched from:
Filename : /usr/bin/lsb_release
dkms-2.2.0.3-2.el6.noarch : Dynamic Kernel Module Support Framework
Repo : epel
Matched from:
Filename : /usr/lib/dkms/lsb_release
由以上資訊中
redhat-lsb-4.0-3.el6.centos.i686 : LSB base libraries support for CentOS
得知,該指令在 redhat-lsb-4.0-3.el6.centos.i686 套件中
安裝套件
# yum install redhat-lsb
...
Transaction Summary
==========================================================
Install 106 Package(s)
Total download size: 86 M
Installed size: 246 M
Is this ok [y/N]:
...
2016年8月4日 星期四
CentOS 7 修改主機名稱 - hostnamectl
以下文章摘自http://blog.xuite.net/tolarku/blog/359546118-CentOS+7+%E4%BF%AE%E6%94%B9%E4%B8%BB%E6%A9%9F%E5%90%8D%E7%A8%B1+-+hostnamectl+
在之前的 CentOS 或其他的 Unix 主機,想要修改主機名稱可以使用「hostname」指令。但到 CentOS 7 之後,雖然 hostname 指令還在卻沒作用了,去修改 /etc/sysconfig/network 也沒作用 ...... 這是因為他改用了「hostnamectl 」指令了。
hostnamectl - Control the system hostname
# 查看目前的主機名稱 #
hostnamectl
$ hostnamectl
Static hostname: localhost.localdomain
Transient hostname: web2
Icon name: computer
Chassis: n/a
Machine ID: 927683d8736xx3345622b982d75
Boot ID: 8226be1192e74w532525c235325f38
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-229.20.1.el7.x86_64
Architecture: x86_64
# 設定主機名稱 #
hostnamectl set-hostname [NAME]
$ hostnamectl set-hostname www
==== AUTHENTICATING FOR org.freedesktop.hostname1.set-static-hostname ===
Authentication is required to set the statically configured local host name, as well as the pretty host name.
Authenticating as: root
## 這個功能是 CentOS 7 提供的新作法,假設一般使用者要執行需要 root 權限的指令,他會跳出要你輸入 root 的密碼來做驗證,驗證過當然就執行囉!....這跟以往直接跟你說需要 root 權限不一樣。
$ sudo hostnamectl set-hostname www
[user@www ~]$
有這個指令之後,就不用再去修改 network 設定了,直接一行指令搞定,重開機也不會改變了。
>> 這個動作會寫入到 /proc/sys/kernel/hostname 設定檔裡
----------------
另外針對主機名稱多了「icon-name」、「chassis」
set-icon-name [NAME]
Set the system icon name. The icon name is used by some graphical applications to visualize this host. The icon
name should follow the Icon Naming Specification[1]. Pass an empty string to this operation to reset the icon name
to the default value, which is determined from chassis type (see below) and possibly other parameters.
set-chassis [TYPE]
Set the chassis type. The chassis type is used by some graphical applications to visualize the host or alter user
interaction. Currently, the following chassis types are defined: "desktop", "laptop", "server", "tablet",
"handset", as well as the special chassis types "vm" and "container" for virtualized systems that lack an
immediate physical chassis. Pass an empty string to this operation to reset the chassis type to the default value
which is determined from the firmware and possibly other parameters.
~End
在之前的 CentOS 或其他的 Unix 主機,想要修改主機名稱可以使用「hostname」指令。但到 CentOS 7 之後,雖然 hostname 指令還在卻沒作用了,去修改 /etc/sysconfig/network 也沒作用 ...... 這是因為他改用了「hostnamectl 」指令了。
hostnamectl - Control the system hostname
# 查看目前的主機名稱 #
hostnamectl
$ hostnamectl
Static hostname: localhost.localdomain
Transient hostname: web2
Icon name: computer
Chassis: n/a
Machine ID: 927683d8736xx3345622b982d75
Boot ID: 8226be1192e74w532525c235325f38
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-229.20.1.el7.x86_64
Architecture: x86_64
# 設定主機名稱 #
hostnamectl set-hostname [NAME]
$ hostnamectl set-hostname www
==== AUTHENTICATING FOR org.freedesktop.hostname1.set-static-hostname ===
Authentication is required to set the statically configured local host name, as well as the pretty host name.
Authenticating as: root
## 這個功能是 CentOS 7 提供的新作法,假設一般使用者要執行需要 root 權限的指令,他會跳出要你輸入 root 的密碼來做驗證,驗證過當然就執行囉!....這跟以往直接跟你說需要 root 權限不一樣。
$ sudo hostnamectl set-hostname www
[user@www ~]$
有這個指令之後,就不用再去修改 network 設定了,直接一行指令搞定,重開機也不會改變了。
>> 這個動作會寫入到 /proc/sys/kernel/hostname 設定檔裡
----------------
另外針對主機名稱多了「icon-name」、「chassis」
set-icon-name [NAME]
Set the system icon name. The icon name is used by some graphical applications to visualize this host. The icon
name should follow the Icon Naming Specification[1]. Pass an empty string to this operation to reset the icon name
to the default value, which is determined from chassis type (see below) and possibly other parameters.
set-chassis [TYPE]
Set the chassis type. The chassis type is used by some graphical applications to visualize the host or alter user
interaction. Currently, the following chassis types are defined: "desktop", "laptop", "server", "tablet",
"handset", as well as the special chassis types "vm" and "container" for virtualized systems that lack an
immediate physical chassis. Pass an empty string to this operation to reset the chassis type to the default value
which is determined from the firmware and possibly other parameters.
~End
2016年4月18日 星期一
Linux查看CPU個數/多核/多執行緒的查看(實體/邏輯)
以下文章摘自 Linux查看CPU個數/多核/多執行緒的查看
在Linux系統中,如何詳細瞭解CPU的資訊呢? 當然是通過cat
/proc/cpuinfo來檢查了,但是比如幾個物理CPU/幾核/幾執行緒,這些問題怎麼確定呢?
/proc/cpuinfo來檢查了,但是比如幾個物理CPU/幾核/幾執行緒,這些問題怎麼確定呢?
判斷依據:
1.具有相同core id的cpu是同一個core的超執行緒。
2.具有相同physical id的cpu是同一顆cpu封裝的執行緒或者cores。
1.具有相同core id的cpu是同一個core的超執行緒。
2.具有相同physical id的cpu是同一顆cpu封裝的執行緒或者cores。
#邏輯CPU個數
cat /proc/cpuinfo | grep "processor" | wc -l
echo "physical CPU number:"
#物理CPU個數:
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
echo "core number in a physical CPU:"
#每個物理CPU中Core的個數:
cat /proc/cpuinfo | grep "cpu cores" | uniq | awk -F: '{print $2}'
#查看每個physical cpu上core id的數量,即為每個物理CPU上的core的個數
cat /proc/cpuinfo | grep "core id"
#是否為超執行緒?
#如果有兩個邏輯CPU core具有相同的”core id”,那麼超執行緒是打開的。
# 當然也可知直接查詢 /proc/cpuinfo 中的 "ht"這個flag
cat /proc/cpuinfo | grep flags | grep ht
#每個物理CPU中邏輯CPU(可能是core, threads或both)的個數:
cat /proc/cpuinfo | grep "siblings"
2016年1月14日 星期四
Using while loop to ssh to multiple servers
我有一個檔案,檔名叫 ip_list.txt ,內容如下
192.168.0.1
192.168.0.2
192.168.0.3
當我透過 while 使用 read 指令將檔案內容一行一行讀入的時後,它的表現會像是這樣
while read line; do echo $line ; done < ip_list.txt
192.168.0.1
192.168.0.2
192.168.0.3
但是當我使用上面的方法,將echo 改成 ssh ,我的 loop 只會執行第一個loop就停了。
while read line ; do ssh $line "hostname" ; done < ip_list.txt
server1.mydomain.com
原因是因為 ssh 會重設標準輸入輸出資訊
解決方法:1
可以用 -n 選項來處理
while read line ; do ssh -n $line "hostname" ; done < ip_list.txt
server1.mydomain.com
server2.mydomain.com
server3.mydomain.com
解決方法:2
改用for
for line in $(cat ip_list.txt ) ; do ssh $list "hostneme" ; done
解決方法:3
給予第二個轉向符
while read line ; do ssh $line "hostname" < /dev/null; done < ip_list.txt
2015年11月13日 星期五
centos雙網卡綁定技術
以下資料取自http://codex.wiki/post/164939-821
在/etc/sysconfig/network-scripts/目錄下建立ifcfg-bond0文件,文件內容如下:
DEVICE=bond0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.100.17
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
TYPE=UnKnown
BONDING_OPTS="miimon=80 mode=0"
綁定mode為0,是rond-robin模式。
然後分別修改ifcfg-eth0文件,如下:
DEVICE="eth0"
#HWADDR="00:0D:60:9A:7B:0A"
ONBOOT="yes"
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
在把ifcfg-eth1文件修改如下:
DEVICE="eth1"
#HWADDR="00:0D:60:9A:7B:0B"
ONBOOT="yes"
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
在/etc/modprobe.d/目錄下建立bonding.conf文件,文件內容如下:
alias bond0 bonding
然後重啟網路service network restart
之後就可以用ifconfig -a看到綁定好的bond0網卡,bond0與eth0,eth1的mac地址均為一樣。
可以同過cat /proc/net/bonding/bond0 此命令查看綁定情況
訂閱:
文章 (Atom)