Linux命令之tzselect

tzselect命令用於選擇時區。要註意的是tzselect只是幫我們把選擇的時區顯示出來,並不會實際生效,也就是說它僅僅告訴我們怎麽樣去設置環境變量TZ。(TZ = Time Zone)(The  tzselect  program asks the user for information about the current location, and outputs the resulting time zone description to standard output.  The output is suitable as a value for the TZ environment variable. All interaction with the user is done via standard input and standard error.)如果妳要永久更改時區,按照tzselect命令提示的信息,在.profile或者/etc/profile中設置正確的TZ環境變量並導出。還有另外壹種更改時區的方法就是直接更改系統配置文件/etc/sysconfig/clock,然後修改符號鏈接/etc/locatime對應的文件,詳見示例三。

  常用參數

  無。

  使用示例

  示例壹 將時區更改為北京

  [root@new55 ~]# tzselect

  Please identify a location so that time zone rules can be set correctly.

  Please select a continent or ocean.

  1) Africa

  2) Americas

  3) Antarctica

  4) Arctic Ocean

  5) Asia

  6) Atlantic Ocean

  7) Australia

  8) Europe

  9) Indian Ocean

  10) Pacific Ocean

  11) none – I want to specify the time zone using the Posix TZ format.

  #? 5

  Please select a country.

  1) Afghanistan           18) Israel                35) Palestine

  2) armenia               19) Japan                 36) Philippines

  3) Azerbaijan            20) Jordan                37) Qatar

  4) Bahrain               21) Kazakhstan            38) Russia

  5) Bangladesh            22) Korea (North)         39) Saudi Arabia

  6) Bhutan                23) Korea (South)         40) Singapore

  7) Brunei                24) Kuwait                41) Sri Lanka

  8) Cambodia              25) Kyrgyzstan            42) Syria

  9) China                 26) Laos                  43) Taiwan

  10) Cyprus                27) Lebanon               44) Tajikistan

  11) East Timor            28) Macau                 45) Thailand

  12) Georgia               29) Malaysia              46) Turkmenistan

  13) Hong Kong             30) Mongolia              47) United Arab Emirates

  14) India                 31) Myanmar (Burma)       48) Uzbekistan

  15) Indonesia             32) Nepal                 49) Vietnam

  16) Iran                  33) Oman                  50) Yemen

  17) Iraq                  34) Pakistan

  #? 9

  Please select one of the following time zone regions.

  1) east China – Beijing, Guangdong, Shanghai, etc.

  2) Heilongjiang (except Mohe), Jilin

  3) central China – Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.

  4) most of Tibet & Xinjiang

  5) west Tibet & Xinjiang

  #? 1

  The following information has been given:

  China

  east China – Beijing, Guangdong, Shanghai, etc.

  Therefore TZ=’Asia/Shanghai’ will be used.

  Local time is now:      Mon Dec  6 09:40:35 CST 2010.

  Universal Time is now:  Mon Dec  6 01:40:35 UTC 2010.

  Is the above information OK?

  1) Yes

  2) No

  #? 1

  You can make this change permanent for yourself by appending the line

  TZ=’Asia/Shanghai’; export TZ

  to the file ‘.profile’ in your home directory; then log out and log in again.

  Here is that TZ value again, this time on standard output so that you

  can use the /usr/bin/tzselect command in shell scripts:

  Asia/Shanghai

  [root@new55 ~]#

  現在要做的事情就是按照提示,把  TZ=’Asia/Shanghai’; export TZ   添加到.profile中(bash對應加到.bash_profile)。

linux學習-linux配置文件出去註釋行

1、使用grep -v “^#”  來去掉註釋行,其中:-v  就是取相反的   ^# 表示註解行

  eg. grep -v “^#” /etc/vsftpd/vsftpd.conf (也可以使用“>”來重寫配置文件)

  2、有時也會連同空行壹起去掉,使用管道符來完成(^$表示空行  )

  eg. grep -v “^#”  httpd.conf | grep -v “^$”  >> vsftpd.conf

  上面用了 2次 grep 過濾命令 ,也就是把空行和註解行過濾掉,再把剩下的內容追加保存為原

  來的配置文件 vsftpd.conf  這個時候就文件裏的內容就沒有註解行和空行了,,,,

  提示: 對配置文件不熟悉的建議不要用這種方法,配置文件中的註解行還是有壹定的幫助的。

  另外,在更改配置文件時,建議先對配置文件做壹下備份:

  cp  -a  httpd.conf  httpd.conf.bak

Linux中如何創建靜態庫和動態庫

靜態庫在程序編譯時會被連接到目標代碼中,程序運行時將不再需要該靜態庫。

  動態庫在程序編譯時並不會被連接到目標代碼中,而是在程序運行是才被載入,因此在程序運行時還需要動態庫存在。

  程序1: hello.h

  #ifndef HELLO_H

  #define HELLO_H

  void hello(const char *name);

  #endif //HELLO_H

  程序2: hello.c

  #include <stdio.h>

  void hello(const char *name)

  {

  printf(“Hello %s!\n”, name);

  }

  程序3: main.c

  #include “hello.h”

  int main()

  {

  hello(“everyone”);

  return 0;

  }

  無論動態庫還是靜態庫都需要用到.o文件來生成,先編譯生成.o文件。

  # gcc -c hello.c

  1:創建靜態庫

  靜態庫文件名的命名規範是以lib為前綴,緊接著跟靜態庫名,擴展名為.a。例如:我們將創建的靜態庫名為myhello,則靜態庫文件名就是libmyhello.a。

  # ar cr libmyhello.a hello.o

  使用靜態庫:只需要在妳的源程序中加入包含妳所需要使用到的函數的聲明(即包含頭文件),然後在gcc生成目標文件時候指明靜態庫就OK了(除非妳包含的頭文件在/usr/include,庫文件在標準庫/usr/lib,/lib下,否則妳得顯示指明他們的路徑)

  # gcc -o hello main.c -L. -lmyhello

  # ./hello

  Hello everyone!

  刪除靜態庫文件運行./hello,程序正常運行,說明靜態庫公用函數已經鏈接到目標文件。

  2: 利用.o文件創建動態庫

  動態庫文件擴展名為.so。

  # gcc -shared -fPCI -o libmyhello.so hello.o

  動態庫的使用與靜態庫使用方式壹樣

  # gcc -o hello main.c -L. -lmyhello

  # ./hello

  ./hello: error while loading shared libraries: libmyhello.so: cannot open shared object file: No such file or directory

  哦!出錯了。快看看錯誤提示,原來是找不到動態庫文件libmyhello.so。程序在運行時,會在/usr/lib和/lib等目錄中查找需要的動態庫文件。若找到,則載入動態庫,否則將提示類似上述錯誤而終止程序運行。

  如何找到生成的動態庫有3種方式:

  1)把庫拷貝到/usr/lib和/lib目錄下。

  (2)在LD_LIBRARY_PATH環境變量中加上庫所在路徑。

  例如動態庫libhello.so在/home/example/lib目錄下:

  $export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/example/lib

  (3) 修改/etc/ld.so.conf文件,把庫所在的路徑加到文件末尾,並執行ldconfig刷新。這樣,加入的目錄下的所有庫文件都可見。

  當靜態庫和動態庫同名時, gcc命令將優先使用動態庫。

  函數庫分為靜態庫和動態庫兩種。

  靜態庫在程序編譯時會被連接到目標代碼中,程序運行時將不再需要該靜態庫。

  動態庫在程序編譯時並不會被連接到目標代碼中,而是在程序運行是才被載入,因此在程序運行時還需要動態庫存在。

  程序1: hello.h

  #ifndef HELLO_H

  #define HELLO_H

  void hello(const char *name);

  #endif //HELLO_H

  程序2: hello.c

  #include <stdio.h>

  void hello(const char *name)

  {

  printf(“Hello %s!\n”, name);

  }

  程序3: main.c

  #include “hello.h”

  int main()

  {

  hello(“everyone”);

  return 0;

  }

  無論動態庫還是靜態庫都需要用到.o文件來生成,先編譯生成.o文件。

  # gcc -c hello.c

  1:創建靜態庫

  靜態庫文件名的命名規範是以lib為前綴,緊接著跟靜態庫名,擴展名為.a。例如:我們將創建的靜態庫名為myhello,則靜態庫文件名就是libmyhello.a。

  # ar cr libmyhello.a hello.o

  使用靜態庫:只需要在妳的源程序中加入包含妳所需要使用到的函數的聲明(即包含頭文件),然後在gcc生成目標文件時候指明靜態庫就OK了(除非妳包含的頭文件在/usr/include,庫文件在標準庫/usr/lib,/lib下,否則妳得顯示指明他們的路徑)

  # gcc -o hello main.c -L. -lmyhello

  # ./hello

  Hello everyone!

  刪除靜態庫文件運行./hello,程序正常運行,說明靜態庫公用函數已經鏈接到目標文件。

  2: 利用.o文件創建動態庫

  動態庫文件擴展名為.so。

  # gcc -shared -fPCI -o libmyhello.so hello.o

  動態庫的使用與靜態庫使用方式壹樣

  # gcc -o hello main.c -L. -lmyhello

  # ./hello

  ./hello: error while loading shared libraries: libmyhello.so: cannot open shared object file: No such file or directory

  哦!出錯了。快看看錯誤提示,原來是找不到動態庫文件libmyhello.so。程序在運行時,會在/usr/lib和/lib等目錄中查找需要的動態庫文件。若找到,則載入動態庫,否則將提示類似上述錯誤而終止程序運行。

  如何找到生成的動態庫有3種方式:

  1)把庫拷貝到/usr/lib和/lib目錄下。

  (2)在LD_LIBRARY_PATH環境變量中加上庫所在路徑。

  例如動態庫libhello.so在/home/example/lib目錄下:

  $export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/example/lib

  (3) 修改/etc/ld.so.conf文件,把庫所在的路徑加到文件末尾,並執行ldconfig刷新。這樣,加入的目錄下的所有庫文件都可見。

  當靜態庫和動態庫同名時, gcc命令將優先使用動態庫。