国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux 學習筆記

2024-06-28 13:21:59
字體:
來源:轉載
供稿:網友
linux 學習筆記Linux學習筆記

請切換web視圖查看,表格比較大,方法:視圖》》web板式視圖

博客園不能粘貼圖片嗎

http://wenku.baidu.com/view/bda1c3067fd5360cba1adb7d

目錄

Linux學習筆記... 1

請切換web視圖查看,表格比較大,方法:視圖》》web板式視圖... 1

1. 常用命令... 3

1.1文件處理命令... 3

1.2權限管理命令... 8

1.3文件搜索命令... 12

1.4幫助命令... 19

1.5壓縮解壓命令... 20

1.6網絡通信指令... 23

1.7 Shell應用技巧... 25

2. Vim/Vi 28

3. 引導... 34

4軟件包的安裝... 39

4.1掛載光盤... 39

5.用戶管理... 40

5.1組管理... 41

5.2批量添加用戶... 41

6. 進程管理... 44

6.2計劃任務... 45

7. shell編程... 46

7.1 hello world. 46

7.2標準輸入和輸出... 46

7.2變量,位置變量$! $$ $# $@ $* $?,環境變量,運算符... 47

7.3if…else. 52

7.4for. 53

7.5awk. 54

7.6一個顯示用戶信息的腳本... 54

7.7一個殺死登陸用戶的腳本... 56

結果如下... 56

腳本內容... 56

7.8select case. 57

select. 57

select+case. 57

case. 58

7.9while. 59

7.10批量添加用戶... 59

7.11批量刪除用戶... 60

7.12break .. continue. 60

7.13 shift,參數累加求和... 61

效果: 參數左移... 61

7.14用戶執行腳本的權限... 62

sh script. 62

1. 對腳本有r權限... 62

2. 腳本所在目錄要有r-x權限... 62

腳本直接執行... 62

1. 對腳本有rx權限... 62

2. 腳本所在目錄有rx權限... 62

7.15正則表達式... 62

7.16截取字符串awk,cut,set. 65

awk 列操作... 66

第一行不執行,第一行先讀取的... 66

所以加BEGIN.. 67

行操作... 67

選取某一行... 68

去掉某一行... 68

追加某一行或幾行... 68

替換... 69

7.17定時任務... 69

8. 安裝jdk. 71

[root@dc-01 java]# rpm -qa | grep jdk. 71

java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686. 71

卸載之:... 71

[root@dc-01 java]# yum -y remove java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.i686. 71

查看系統位數... 71

下載對應的安裝包... 71

http://pan.baidu.com/s/1qWnzJCK. 71

1.修改權限為可執行... 71

2.rpm –ivh 安裝包... 71

3.vi /etc/PRofile 尾部添加環境變量... 72

79 JAVA_HOME=/usr/java/jdk1.7.0_67. 72

80 PATH=$JAVA_HOME/bin:$PATH.. 72

81 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar. 72

82 export JAVA_HOME. 72

83 export PATH.. 72

84 export CLASSPATH.. 72

4. 執行source /etc/profile命令讓修改生效。... 72

5.查看安裝結果... 72

至此,安裝jdk成功... 73

9. 安裝Tomcat. 73

1.下載安裝包,千萬選好安裝源,因為安裝包的問題,硬是讓我調試了一天,真是傻逼,重新官網下載安裝之后立馬可以用了... 73

http://tomcat.apache.org/download-70.cgi 73

2.解壓到/usr/local 下,并重命名為tomcat. 73

#tar zxvf apache-tomcat-7.0.35.tar.gz /解壓... 73

#mv apache-tomcat-7.0.35 apache-tomcat /更名... 73

#cd /apache-tomcat/bin/ /打開此目錄... 74

#chmod 777 *.sh /加777權限... 74

#bash catalina.sh start /啟動... 74

1. 常用命令

命令存放,哪些命令可以執行?

root:

/sbin

/usr/sbin

all users:

/bin

/usr/bin

bin--binary 二進制文件

Linux所有都是文件,都是二進制文件

usr—user

sbin—super binary

1.1文件處理命令

文件處理命令

1

ls

英文原意是list 功能:顯示目錄文件 屬性可以連著寫,比如ls -ld

Eg

含義

-a all

顯示所有文件,包括隱藏文件

ls -a /

-l long

-I 顯示i節點

詳細信息顯示

[root@localhost ~]# ls -l

total 68

-rw------- 1 root root 1211 Feb 14 04:02 anaconda-ks.cfg

drwxr-xr-x 3 root root 4096 Feb 14 11:20 Desktop

-rw-r--r-- 1 root root 31736 Feb 14 04:02 install.log

-rw-r--r-- 1 root root 0 Feb 14 03:16 install.log.syslog

drwxr-xr-x 2 root root 4096 Feb 14 17:36 test

drwxr-xr-x 2 root root 4096 Feb 14 11:20

每三個表示權限 表示硬連接數 所有者 所屬組 文件大小 創建時間

數據塊 block 512字節

第一個字符表示如下:

d 目錄directory

- 二進制文件

l 軟鏈接文件

每三個分配如下:

r—read 讀 w—write寫 x—execute執行

rwx r-x r-x

所有者u 所屬組g 其他人o

user group others

-d

查看目錄屬性

[root@localhost ~]# ls -ld /test

drwxr-xr-x 3 root root 4096 Feb 14 17:42 /test

2

cd

切換目錄

Cd /

進入根目錄

Cd [目錄]

Cd ..

返回父級目錄

3

pwd

英文:print working directory

查看當前目錄

[root@localhost ~]# pwd

/root

4

touch

創建空文件

[root@localhost test]# touch testfile

[root@localhost test]# ls -l testfile

-rw-r--r-- 1 root root 0 Feb 14 18:51 testfile

5

mkdir

英文:make directories

創建空目錄

[root@localhost ~]# mkdir test

6

cp

英文:copy

復制文件

-R 復制目錄

copy [源文件,可多個] [目的目錄]

[root@localhost test]# cp /etc/inittab /etc/services /test

[root@localhost test]# ls /test

abc.txt inittab lost+found samlee services testfile

將etc拷貝到test下

[root@localhost test]# cp -R /etc /test

/etc 主要是配置文件,很重要,記得備份

命令停止快捷鍵:Ctrl+c

7.

mv

英文:move

移動文件,改名

[root@localhost test]# ls /test

abc.txt etc inittab lost+found samlee services testfile

改名:

[root@localhost test]# mv services service

[root@localhost test]# ls /test

abc.txt etc inittab lost+found samlee service testfile

移動:

[root@localhost test]# mv /test/inittab /tmp/

[root@localhost test]# ls /test

abc.txt etc lost+found samlee service testfile

改名+移動:

[root@localhost test]# mv /test/testfile /tmp/file.test

[root@localhost test]# ls /tmp

file.test scim-panel-socket:0-root

gconfd-root scim-socket-frontend-root

inittab ssh-yoUWCY4180

keyring-z1fmdW virtual-root.IYU2ep

mapping-root vmware-config0

orbit-root VMwareDnD

scim-bridge-0.3.0.lockfile-0@localhost:0.0 vmware-root

scim-bridge-0.3.0.socket-0@localhost:0.0 vmware-root-592157060

scim-helper-manager-socket-root

8

rm

remove

刪除

[root@localhost test]# ls /test

abc.txt etc lost+found samlee service

刪除service

[root@localhost test]# rm service

rm: remove regular file `service'? y

[root@localhost test]# ls /test

abc.txt etc lost+found samlee

刪除不詢問:

[root@localhost test]# touch testfile

[root@localhost test]# ls

abc.txt etc lost+found samlee testfile

[root@localhost test]# rm -f testfile

[root@localhost test]# ls

abc.txt etc lost+found samlee

rm –f 目錄名稱 不提示,強制刪除,在寫腳本的時候用,因為沒有yes交互

r表示刪除,f表示強制

9

cat

concatenate and display files

查看

[root@localhost test]# cat /etc/issue

CentOS release 5.5 (Final)

Kernel /r on an /m

適合查看文件小,因為多的話會把前面的覆蓋,不能翻頁。

比如cat /etc/services

10

more

(空格)或f 顯示下一頁

(enter)顯示下一行

q或Q 退出

分頁查看

[root@localhost test]# more /etc/services

11

head

-num 文件名

查看文件前num行

[root@localhost test]# head -5 /etc/services

# /etc/services:

# $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $

#

# Network services, Internet style

#

12

tail

-num 文件名

-f 文件名

查看文件尾num行

動態查看文件尾部信息

[root@localhost test]# tail -5 /etc/services

com-bardac-dw 48556/tcp # com-bardac-dw

com-bardac-dw 48556/udp # com-bardac-dw

iqobject 48619/tcp # iqobject

iqobject 48619/udp # iqobject

# Local services

[root@localhost test]# tail -f /etc/services

tail –f 為了監視日志文件,默認顯示10行

13

ln

英文:link

ln 文件名 目的目錄

ln –s 文件名 目的目錄

-s soft軟連接

創建硬鏈接

創建軟鏈接

[root@localhost test]# ln -s /etc/issue /issue.soft

[root@localhost test]# ls -l /etc/issue /issue.soft

-rw-r--r-- 1 root root 47 Apr 26 2010 /etc/issue

lrwxrwxrwx 1 root root 10 Feb 14 16:51 /issue.soft -> /etc/issue

硬鏈接:

[root@localhost test]# ln /etc/issue /issue.hard

[root@localhost test]# ls -l /etc/issue /issue.hard

-rw-r--r-- 2 root root 47 Apr 26 2010 /etc/issue

-rw-r--r-- 2 root root 47 Apr 26 2010 /issue.hard

拷貝:

[root@localhost test]# cp /etc/issue /test/issue

[root@localhost test]# ls -l /etc/issue /test/issue

-rw-r--r-- 2 root root 47 Apr 26 2010 /etc/issue

-rw-r--r-- 1 root root 47 Feb 14 20:31 /test/issue

拷貝并且不改變時間,比如某些備份

[root@localhost test]# cp -p /etc/issue /test/issue

cp: overwrite `/test/issue'? y

[root@localhost test]# ls -l /etc/issue /test/issue

-rw-r--r-- 2 root root 47 Apr 26 2010 /etc/issue

-rw-r--r-- 1 root root 47 Apr 26 2010 /test/issue

軟連接文件類型是l

軟連接所有人都有權限,但能不能訪問取決于源文件

軟連接時間值 是創建軟連接的時間

相當于快捷方式

類似于copy,文件大小相同

不同于copy的是,它是同步更新的。

還有一個不同的是,拷貝的時間是不同,時間是創建的時間

一個i節點可以映射到多個文件,所以硬鏈接可以同步更新。

1.2權限管理命令

權限管理命令

14

chmod

change the permissions mode of a file

chmod[{ugo0}{+-=}[文件或目錄][mode=421][文件或目錄]

功能:

改變文件或目錄權限

用數字表示

r--4

w--2

x—1

rwxr-xr-- 754

rw-r-x—x 651

文件:

r-car,more,head,tail

w-echo,vi 可以修改內容

x-命令,腳本

目錄:

r-ls

w-touch,mkdir,rm 對目錄有這些權限

x-cd 對目錄可以進去

所以,所有的目錄都有rx權限,表示可以讀取可以進去

[root@localhost test]# ls -l a

-rwxr-x--- 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod o+rwx a

[root@localhost test]# ls -l a

-rwxr-xrwx 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod o-rw a

[root@localhost test]# ls -l a

-rwxr-x--x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod g=r a

[root@localhost test]# ls -l a

-rwxr----x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod g=rx a

[root@localhost test]# ls -l a

-rwxr-x--x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chmod 641 a

[root@localhost test]# ls -l a

-rw-r----x 1 root root 0 Feb 19 15:45 a

chmod u+權限 文件或目錄-------給所屬者增加權限

chmod u+權限 文件或目錄-------給所屬者減少權限

chmod g=權限 文件或目錄-------給所屬組賦予權限

chmod o -----------------------------------同u,為加減權限

用數字表示權限,直接賦值就可以 chmod 641 a

15

chown

change file ownership

改變所有者

[root@localhost test]# ls -l a

-rw-r----x 1 root root 0 Feb 19 15:45 a

[root@localhost test]# chown helen a

[root@localhost test]# ls -l a

-rw-r----x 1 helen root 0 Feb 19 15:45 a

[root@localhost test]# chown nobody a

[root@localhost test]# ls -l a

-rw-r----x 1 nobody root 0 Feb 19 15:45 a

16

chgrp

change file group ownership

改變所屬組

[root@localhost test]# ls -l a

-rw-r----x 1 nobody root 0 Feb 19 15:45 a

[root@localhost test]# chgrp adm a

[root@localhost test]# ls -l a

-rw-r----x 1 nobody adm 0 Feb 19 15:45 a

17

umask

查看創建文件的默認權限

改變默認權限 umask 權限掩碼值

[root@localhost test]# mkdir newdir

[root@localhost test]# ls -ld newdir

drwxr-xr-x 2 root root 4096 Feb 20 10:40 newdir

[root@localhost test]# umask

0022

[root@localhost test]# umask -S

u=rwx,g=rx,o=rx

*

0022

特殊權限位

022-用戶權限位,權限掩碼值

777

022

755

022 就是表示755

SetUID 4

SetGID 2

chmod u+s

4755

2755 組id

6755同時SetUID和SetGID

*

Linux權限規則

缺省創建的文件不能授予可執行x權限

[root@localhost test]# touch testfile

[root@localhost test]# ls -l testfile

-rw-r--r-- 1 root root 0 Feb 20 10:50 testfile

雖然創建文件的默認權限是022,但創建的空文件testfile沒有x權限

*

添加用戶

[root@localhost test]# useradd miao

[root@localhost test]# passwd miao

Changing passWord for user miao.

New UNIX password:

BAD PASSWORD: it is too short

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

添加用戶信息

設置密碼

設置密碼

*

su -

切換用戶

1.3文件搜索命令

Linux中所有都是文件,命令也是文件

文件搜索命令

18

which

查詢命令所在的絕對路徑

[root@localhost ~]# which chmod

/bin/chmod

[root@localhost ~]# whereis ls

ls: /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz

命令也是文件

whereis除了絕對路徑,還包括幫助文檔

19

find

查找文件或目錄

find [搜索路徑][搜索關鍵字]

-name 文件名

*匹配任意字符 init*

?匹配單個字符 init???

-size 文件大小 block數據塊 512字節=0.5kb

大于+

小于-

等于 find / -size 204800

-user 文件所有者

時間

  1. 天 ctime atime mtime
  2. 分鐘 cmin amin mmin

c—change改變,表示文件的屬性被修改過,所有者、所屬組、權限

a—access訪問

m—modify修改,表示文件的內容被修改過

-之內,+超過

find /etc –mmin -120 一分鐘內被修改過

-type 文件類型 f 二進制文件

l 軟連接文件

d 目錄

  1. 連接符 -a and 邏輯與

-o or 邏輯或

2. 連接符 find …. –exec 命令{}/;

{}find查詢的結果

/轉義符,符號命令使用本身的含義

;結果

-ok提示

[root@localhost ~]# find /etc -name init

/etc/sysconfig/init

試驗通配符和占位符

[root@localhost ~]# find /etc -name init*

/etc/selinux/targeted/contexts/initrc_context

/etc/sysconfig/init

/etc/sysconfig/network-scripts/init.ipv6-global

/etc/init.d

/etc/mail/spamassassin/init.pre

/etc/inittab

/etc/initlog.conf

/etc/rc.d/init.d

[root@localhost ~]# find /etc -name init???

/etc/inittab

[root@localhost ~]# find /etc -name init?

[root@localhost ~]# find /etc -name init??

/etc/init.d

/etc/rc.d/init.d

查找用戶

[root@localhost ~]# find /home -user helen

/home/helen

/home/helen/.bash_logout

/home/helen/.kde

/home/helen/.kde/Autostart

/home/helen/.kde/Autostart/.directory

/home/helen/.mozilla

/home/helen/.mozilla/extensions

/home/helen/.mozilla/plugins

/home/helen/.bash_profile

/home/helen/.bashrc

/home/helen/.bash_history

測試轉義字符

[root@localhost ~]# which rm

alias rm='rm -i'

/bin/rm

[root@localhost ~]# rm abc.txt

rm: remove regular empty file `abc.txt'?

[root@localhost ~]# /rm abc.txt

查找二進制文件

[root@host141 ~]# find /etc -name init* -a -type f

/etc/inittab

/etc/initlog.conf

/etc/sysconfig/network-scripts/init.ipv6-global

/etc/sysconfig/init

/etc/selinux/targeted/contexts/initrc_context

測試連接符-exec

[root@localhost ~]# find /etc -name inittab

/etc/inittab

[root@localhost ~]# find /etc -name inittab -exec ls -l {} /;

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

[root@localhost ~]# cd /test

[root@localhost test]# pwd

/test

[root@localhost test]# ls

a a.hard a.soft etc issue lost+found

[root@localhost test]# find /test -name a.soft

/test/a.soft

[root@localhost test]# find /test -name a.soft -exec rm {} /;

[root@localhost test]# ls

a a.hard etc issue lost+found

測試連接符-ok

[root@localhost test]# find /etc -name inittab -exec ls -l {} /;

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

[root@localhost test]# find /etc -name inittab -ok ls -l {} /;

< ls ... /etc/inittab > ? y

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

[root@localhost test]# ls

a a.hard etc issue lost+found

[root@localhost test]# find /test -name a.hard -ok rm {} /;

< rm ... /test/a.hard > ? y

[root@localhost test]# ls

a etc issue lost+found

[root@localhost test]# find /etc -name init* -a -type f -exec ls -l {} /;

-rw-r--r-- 1 root root 28 Apr 10 2010 /etc/selinux/targeted/contexts/initrc_context

-rw-r--r-- 1 root root 1068 Jul 4 2009 /etc/sysconfig/init

-rwxr-xr-x 1 root root 5433 Jul 4 2009 /etc/sysconfig/network-scripts/init.ipv6-global

-rw-r--r-- 1 root root 1299 Jan 21 2009 /etc/mail/spamassassin/init.pre

-rw-r--r-- 1 root root 1666 Feb 14 04:02 /etc/inittab

-rw-r--r-- 1 root root 658 Sep 29 2009 /etc/initlog.conf

測試根據i節點刪除文件

[root@localhost test]# touch "a b";

[root@localhost test]# ls

a a b

[root@localhost test]# touch -- -abc

[root@localhost test]# ls

a a b -abc

[root@localhost test]# rm -abc

rm: invalid option -- a

Try `rm ./-abc' to remove the file `-abc'.

Try `rm --help' for more information.

[root@localhost test]# rm a b

rm: remove regular empty file `a'? a

rm: cannot lstat `b': No such file or directory

[root@localhost test]# rm a b

rm: remove regular empty file `a'? y

rm: cannot lstat `b': No such file or directory

[root@localhost test]# rm -- -abc "a b"

rm: remove regular empty file `-abc'? y

rm: remove regular empty file `a b'? y

[root@localhost test]# ls

[root@localhost test]#

[root@localhost test]# ls -i

1653280 a b 1653352 -abc

[root@localhost test]# find . -inum 1653280

./a b

[root@localhost test]# find . -inum 1653280 -exec rm {} /;

[root@localhost test]# ls

-abc

*通配符

大范圍查找只在晚上2點左右進行,因為訪問人數少,只占用一部分資源

?匹配單個字符,相當于占位

通常用>或者<

rm的別名是 rm-i

所以要提示,那么要使用本身的含義,加轉義字符/

查找二進制文件

查找inittab

查找并顯示詳細信息

進入test

顯示當前目錄

顯示當前目錄下的文件

查找a.soft文件

查找a.soft文件并刪除

a.soft已刪除

查找inittab并查看詳細信息

提示的查看(為了試驗,真正用在rm)

查找init開頭,文件類型是二進制文件的詳細信息

一些奇葩的創建文件

這時候想要刪除文件就會出問題

我們知道創建過程的時候可以這樣刪除,如果不知道呢?

查找i節點

.表示當前目錄,即/test

根據i節點刪除,萬能

20

locate

list files in databases

locate [搜索關鍵字]

locate file

可以查找所有跟file相關的文件,速度快

locate指令是根據數據庫查找的,如果數據庫中文件沒有更新,那么就會找不到。

定期updatedb,則可以直接locate找到

21

updatedb

update the slocate database

建立整個系統目錄文件的數據庫

22

grep

grep [指定字串][源文件]

在文件中搜尋字串匹配的行,并輸出

[root@localhost test]# grep tftp /etc/services

tftp 69/tcp

tftp 69/udp

tftp-mcast 1758/tcp

tftp-mcast 1758/udp

mtftp 1759/udp

subntbcst_tftp 247/tcp # SUBNTBCST_TFTP

subntbcst_tftp 247/udp # SUBNTBCST_TFTP

etftp 1818/tcp # Enhanced Trivial File Transfer Protocol

etftp 1818/udp # Enhanced Trivial File Transfer Protocol

tftps 3713/tcp # TFTP over TLS

tftps 3713/udp # TFTP over TLS

查找和tftp相關的行

1.4幫助命令

幫助命令

23

man

manual

man [命令或配置文件]

獲得幫助信息

命令和配置文件相同時優先查看命令的幫助

幫助分很多種,其中第一種是命令,第五種是配置文件,當名字相同時通過

man 5來查看配置文件

man ls 使用more查看,空格翻頁,enter下一行

[root@localhost test]# man 5 passwd

passwd可以修改用戶密碼,

和一個配置文件同名

24

info

information

info [任何關鍵字]

獲取幫助信息

25

whatis

whatis apropos[任何關鍵字]

獲得索引的簡短說明信息

[root@localhost test]# whatis whereis

whereis (1) - locate the binary, source, and manual page files for a command

26

help

命令 –help

help 內置命令

[root@localhost test]# ls --help

1.5壓縮解壓命令

windows可解壓Linux所有,但相反不可

共同:zip 但壓縮比不高,如果小文件建議使用

gzip 和 bzip2只能壓縮文件且不保留源文件,但后者-k可以保留

27

gzip

GNU zip

gzip 選項[文件]

壓縮后文件格式: .gz

只能壓縮文件,不能壓縮目錄

不保留源文件

解壓縮:

gunzip 壓縮文件

gzip –d 壓縮文件

[root@localhost test]# ls

etc issue lost+found newfile

[root@localhost test]# gzip newfile

[root@localhost test]# ls

etc issue lost+found newfile.gz

不能壓縮目錄

[root@localhost test]# mkdir newdir

[root@localhost test]# ls

etc issue lost+found newdir newfile.gz

[root@localhost test]# gzip newdir

gzip: newdir is a directory – ignored

解壓縮

[root@localhost test]# gzip -d newfile.gz

[root@localhost test]# ls

etc issue lost+found newdir newfile

[root@localhost test]# gzip newfile

[root@localhost test]# ls

etc issue lost+found newdir newfile.gz

[root@localhost test]# gunzip newfile.gz

[root@localhost test]# ls

etc issue lost+found newdir newfile

28

tar

打包目錄

tar 選項[cvf][目錄]

-c 產生.tar打包文件

-v 顯示詳細信息

-f 指定壓縮后的文件名

-z 打包同時壓縮

壓縮后文件格式: .tar.gz

解壓縮

-x 解包.tar文件

-v 顯示詳細信息

-f 指定解壓文件

-z 解壓縮

[root@localhost test]# ls

etc issue lost+found newdir newfile

[root@localhost test]# tar -zcf newdir.tar.gz newdir

[root@localhost test]# ls

etc issue lost+found newdir newdir.tar.gz newfile

當沒有后綴,或者不知道文件類型

[root@localhost test]# tar -zcf new newdir

[root@localhost test]# ls -l new

-rw-r--r-- 1 root root 113 Feb 26 14:56 new

[root@localhost test]# file new

new: gzip compressed data, from Unix, last modified: Thu Feb 26 14:56:08 2015

先打包再壓縮

[root@localhost test]# tar -cf newdir2.tar newdir

[root@localhost test]# gzip newdir2.tar

[root@localhost test]# ls

etc issue lost+found new newdir newdir2.tar.gz newdir.tar.gz newfile

解壓縮

[root@localhost test]# ls

etc issue lost+found new newdir newdir2.tar.gz newdir.tar.gz newfile

[root@localhost test]# tar -zxf newdir.tar.gz

[root@localhost test]# ls

etc issue lost+found new newdir newdir2.tar.gz newdir.tar.gz newfile

[root@localhost test]# tar -zxf newdir2.tar.gz

[root@localhost test]# ls

etc issue lost+found new newdir newdir2.tar.gz newdir.tar.gz newfile

[root@localhost test]# rm -rf newdir

[root@localhost test]# ls

etc issue lost+found new newdir2.tar.gz newdir.tar.gz newfile

[root@localhost test]# tar -zxf new

[root@localhost test]# ls

etc issue lost+found new newdir newdir2.tar.gz newdir.tar.gz newfile

tar –zcf 打包后的名字 要打包的文件名

注:打包后的文件名可以沒有后綴,但是為了辨識方便,養成良好習慣

看起來像是文本文件,但這種使用cat是無法查看的

使用file查看文件了性

29

zip

zip 選項[-r][壓縮后文件名稱][文件或

上一篇:Linux apt-get


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿尔山市| 南召县| 上杭县| 通道| 宝应县| 徐汇区| 临武县| 纳雍县| 永仁县| 方城县| 北票市| 舒城县| 茂名市| 青铜峡市| 洞口县| 梁山县| 浏阳市| 邵东县| 葵青区| 遂昌县| 顺义区| 东台市| 德惠市| 南皮县| 吐鲁番市| 蒲城县| 北流市| 阳泉市| 湖州市| 英山县| 昌黎县| 益阳市| 武邑县| 涟水县| 邹城市| 高要市| 女性| 茌平县| 康保县| 独山县| 衡阳县|