linux 雜記

1解壓與壓縮

1.以.a爲擴展名的文件:
#tar xv file.a
2.以.z爲擴展名的文件:
#uncompress file.Z
3.以.gz爲擴展名的文件:
#gunzip file.gz
4.以.bz2爲擴展名的文件:
#bunzip2 file.bz2
5.以.tar.Z爲擴展名的文件:
#tar xvZf file.tar.Z 
或 #compress -dc file.tar.Z | tar xvf -
6.以.tar.gz/.tgz爲擴展名的文件:
#tar xvzf file.tar.gz 
或 gzip -dc file.tar.gz | tar xvf -
7.以.tar.bz2爲擴展名的文件:
#tar xvIf file.tar.bz2 
或 bzip2 -dc file.tar.bz2 | xvf -
8.以.cpio.gz/.cgz爲擴展名的文件:
#gzip -dc file.cgz | cpio -div
9.以.cpio/cpio爲擴展名的文件:
#cpio -div file.cpio 
或cpio -divc file.cpio
10.以.rpm爲擴展名的文件安裝:
#rpm -i file.rpm
11.以.rpm爲擴展名的文件解壓縮:
#rpm2cpio file.rpm | cpio -div
12.以.deb爲擴展名的文件安裝:
#dpkg -i file.deb
13.以.deb爲擴展名的文件解壓縮:
#dpkg-deb --fsys-tarfile file.deb | tar xvf - ar p 
file.deb data.tar.gz | tar xvzf -
14.以.zip爲擴展名的文件:
#unzip file.zip

2.爲什麼要用/dev/null 2>&1 這樣的寫法.

這條命令的意思是將標準輸出和錯誤輸出全部重定向到/dev/null中,也就是將產生的所有信息丟棄.下面我就爲大家來說一下, command > file 2>file   與command > file 2>&1 有什麼不同的地方.
       首先~command > file 2>file 的意思是將命令所產生的標準輸出信息,和錯誤的輸出信息送到file 中.command   > file 2>file 這樣的寫法,stdoutstderr都直接送到file中, file會被打開兩次,這樣stdoutstderr會互相覆蓋,這樣寫相當使用了FD1和FD2兩個同時去搶佔file 的管道.
       而command >file 2>&1 這條命令就將stdout直接送向file,stderr 繼承了FD1管道後,再被送往file,此時,file 只被打開了一次,也只使用了一個管道FD1,它包括了stdoutstderr的內容.
       從IO效率上,前一條命令的效率要比後面一條的命令效率要低,所以在編寫shell腳本的時候,較多的時候我們會用command > file 2>&1 這樣的寫法。

3 .名稱 : crontab

使用權限 : 所有使用者
使用方式 :
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }
說明 :
crontab 是用來讓使用者在固定時間或固定間隔執行程序之用,換句話說,也就是類似使用者的時程表。-u user 是指設定指定 user 的時程表,這個前提是你必須要有其權限(比如說是 root)才能夠指定他人的時程表。如果不使用 -u user 的話,就是表示設定自己的時程表。
餐數 :
-e : 執行文字編輯器來設定時程表,內定的文字編輯器是 VI,如果你想用別的文字編輯器,則請先設定 VISUAL 環境變數來指定使用那個文字編輯器(比如說 setenv VISUAL joe)
-r : 刪除目前的時程表
-l : 列出目前的時程表
時程表的格式如下 :
f1 f2 f3 f4 f5 program  
  
其中 f1 是表示分鐘,f2 表示小時,f3 表示一個月份中的第幾日,f4 表示月份,f5 表示一個星期中的第幾天。program 表示要執行的程序。
當 f1 爲 * 時表示每分鐘都要執行 program,f2 爲 * 時表示每小時都要執行程序,其餘類推
當 f1 爲 a-b 時表示從第 a 分鐘到第 b 分鐘這段時間內要執行,f2 爲 a-b 時表示從第 a 到第 b 小時都要執行,其餘類推
當 f1 爲 */n 時表示每 n 分鐘個時間間隔執行一次,f2 爲 */n 表示每 n 小時個時間間隔執行一次,其餘類推
當 f1 爲 a, b, c,... 時表示第 a, b, c,... 分鐘要執行,f2 爲 a, b, c,... 時表示第 a, b, c...個小時要執行,其餘類推
使用者也可以將所有的設定先存放在檔案 file 中,用 crontab file 的方式來設定時程表。
例子 :
每月每天每小時的第 0 分鐘執行一次 /bin/ls :
0 7 * * * /bin/ls  
  
在 12 月內, 每天的早上 6 點到 12 點中,每隔 20 分鐘執行一次 /usr/bin/backup :
0 6-12/3 * 12 * /usr/bin/backup  
  
週一到週五每天下午 5:00 寄一封信給 [email protected] :

0 17 * * 1-5 mail -s "hi" [email protected]  /dev/null 2>&1 即可

4. ls 常用參數

顯示目錄  ls -F | grep /$   或者   ls -l | grep “^d”    或者ls -p
-F  :根據文件、目錄等資訊,給予附加數據結構,例如*:代表可運行檔; /:代表目錄; =:代表 socket 文件; |:代表 FIFO 文件
-p 在目錄後面加上/符號
顯示全部文件 ls -a
只顯示文件而不顯示目錄:ls -l |grep ^-  
顯示詳細信息 ls -ld  (參數d表示將文件大小以人的可讀方式列出)
-S  :以文件容量大小排序,而不是用檔名排序
-t  :依時間排序,而不是用檔名
-r  :將排序結果反向輸出

5 ftp 客戶端命令

  • ! - Runs the specified command on the local computer
  • ? - Displays descriptions for ftp commands
  • append - Appends a local file to a file on the remote computer
  • ascii - Sets the file transfer type to ASCII, the default
  • bell - Toggles a bell to ring after each file transfer command is completed (default = OFF)
  • binary - Sets the file transfer type to binary
  • bye - Ends the FTP session and exits ftp
  • cd - Changes the working directory on the remote computer
  • close - Ends the FTP session and returns to the command interpreter
  • debug - Toggles debugging (default = OFF)
  • delete - Deletes a single file on a remote computer
  • dir - Displays a list of a remote directory's files and subdirectories
  • disconnect - Disconnects from the remote computer, retaining the ftp prompt
  • get - Copies a single remote file to the local computer
  • glob - Toggles filename globbing (wildcard characters) (default = ON)
  • hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF)
  • help - Displays descriptions for ftp commands
  • lcd - Changes the working directory on the local computer
  • literal - Sends arguments, verbatim, to the remote FTP server
  • ls - Displays an abbreviated list of a remote directory's files and subdirectories
  • mdelete - Deletes one or more files on a remote computer
  • mdir - Displays a list of a remote directory's files and subdirectories
  • mget - Copies one or more remote files to the local computer
  • mkdir - Creates a remote directory
  • mls - Displays an abbreviated list of a remote directory's files and subdirectories
  • mput - Copies one or more local files to the remote computer
  • open - Connects to the specified FTP server
  • prompt - Toggles prompting (default = ON)
  • put - Copies a single local file to the remote computer
  • pwd - Displays the current directory on the remote computer (literally, "print working directory")
  • quit - Ends the FTP session with the remote computer and exits ftp (same as "bye")
  • quote - Sends arguments, verbatim, to the remote FTP server (same as "literal")
  • recv - Copies a remote file to the local computer
  • remotehelp - Displays help for remote commands
  • rename - Renames remote files
  • rmdir - Deletes a remote directory
  • send - Copies a local file to the remote computer (same as "put")
  • status - Displays the current status of FTP connections
  • trace - Toggles packet tracing (default = OFF)
  • type - Sets or displays the file transfer type (default = ASCII)
  • user - Specifes a user to the remote computer
  • verbose - Toggles verbose mode (default = ON)

5 掛接光盤

mount -r /dec/cdrom /mnt/cdrom 以只讀方式掛接

chown -R owner:group file 改變文件夾所有者,遞歸

發佈了33 篇原創文章 · 獲贊 4 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章