linux使用心得(持續更新)

lykyl的自留地發表於2013-08-22
! 檢視發行版本資訊
lsb_release -a
uname -a
 
以下方法只適合redhat和centos
cat /etc/redhat-release
rpm -q redhat-release
rpm -q centos-release
 
! 關閉SHELL鈴聲
vi /etc/inputrc
將set bell-style none的註釋取消
 
!日期時間修改
修改日期
date -s MM/dd/YYYY
修改時間
date -s HH:mm:ss
 
! 日期時間格式化輸出
date +[格式化輸出符]
例如:
date +%H:%M:%S
17:18:24

!同步系統時間
ntpdate cn.pool.ntp.org;hwclock --systohc
 
! smbmount
使用 mount替代,格式為cifs
mount -t cifs -o username=xxx.password=xxx //hostname/dir /mnt/dir
也可以建立別名
alias smbmount='mount -t cifs'
 
! 終端中文設定
yum -y groupinstall chinese-support
 
vi /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"
LC_MESSAGES="en_US.UTF-8"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
再在PUTTY中將視窗-轉換-假定接收資料的字符集設為UTF-8
 
!設定DNS的IP
/etc/resolv.conf
nameserver xxx.xxx.xxx.xxx
 
!設定網路主機名,以及是否允許使用網路
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=xxx
 
!設定具體網路卡
/etc/sysconfig/network-scripts/ifcfg-eth<0起始的數字>
DEVICE=eth0
BOOTPROTO=static|dhcp
BROADCAST=
IPADDR=
NETMASK=
GATEWAY=
HWADDR=
ONBOOT=yes
MTU=1500
TYPE=Ethernet
 
!記錄主機名與IP對應關係
/etc/hosts
 
! 軟raid5預設需要spare盤,用--force 引數可以遮蔽掉這個功能
When creating a RAID5 array, mdadm will automatically create a degraded
   array   with   an   extra spare drive.   This is because building the spare
   into a degraded array is in general faster than resyncing the parity on
   a   non-degraded, but not clean, array.   This feature can be over-ridden
   with the --force option.
 
!/etc/passwd欄位定義
LoginName:Password:Uid:Gid:UserInfo:Home:Shell
 
!/etc/shadow欄位定義
LoginName:Passwd:LastChg:Min:Max:Warn:Inactive:Expire:Flag
 
!/etc/group欄位定義
GroupName:Password:Gid:UserList(split by ',')
 
!/etc/gshadow欄位定義
GroupName:Password:UserList(split by ',')
 
!強制踢掉線上使用者
通過使用者名稱踢
pkill -u <name>
 
通過TTY踢
pkill -kill -t <tty name>
 
!egrep不允許使用\{\}
 
!declare命令將變數轉成環境變數,供子程式呼叫。程式中的環境變數修改,隻影響自身與子程式。
 
!SELINUX開啟時ZendGuardLoader能在PHP命令列環境載入,但無法在APACHE中載入的解決辦法
execstack --clear-execstack /usr/lib64/php/modules/ZendGuardLoader.so
 
!複製虛擬機器啟動後網路卡報“Device eth0 does not seem to be present,delaying initialization”
編輯 /etc/sysconfig/network-scripts/ifcfg-eth0,將其中的MAC地址改成新虛擬機器網路卡的MAC地址。
rm -f /etc/udev/rules.d/70-persistent-net.rules
重啟系統。
 
! 脫離終端後臺執行shell
nohup ./test.sh &
 
!ubuntu刪除多餘的舊核心
查詢已經安裝的核心
dpkg --get-selections |grep linux-image
 
根據情況刪除舊核心
sudo apt-get remove <核心完整名稱>
 
! 獲取路徑裡檔名與目錄名的方法
basename <路徑>     #獲取路徑裡的檔名
dirname <路徑>     #獲取路徑裡的目錄名,不包含最後的/
 
!ubuntu處理DOS回車
sudo apt-get install tofrodos
fromdos <待轉換為UNIX回車的檔案>
todos <待轉換為DOS回車的檔案>
 
! ubuntu安裝HG
sudo add-apt-repository ppa:tortoisehg-ppa/releases
sudo add-apt-repository ppa:mercurial-ppa/releases
sudo apt-get update
sudo apt-get install mercurial python-nautilus tortoisehg
 

相關文章