程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 還是不想改報告,伊阿憶啊喲-Linux基礎繼續,啊喲-linux

還是不想改報告,伊阿憶啊喲-Linux基礎繼續,啊喲-linux

編輯:關於PHP編程

還是不想改報告,伊阿憶啊喲-Linux基礎繼續,啊喲-linux


  hi

雖然今天是最最美好的周六(前不著工作日後不著工作日),但老子還要來改報告,但額就是不想改,你拿我有啥辦法啊。。。

爭取完結Linux基礎

一、Linux常用命令(三)

4、幫助命令

4.1 幫助命令man

man 命令

--例子

man ls

LS(1) User Commands LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [OPTION]... [FILE]...

DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of
-cftuvSUX nor --sort.

Mandatory arguments to long options are mandatory for short options too.

-a, --all
do not ignore entries starting with .

-A, --almost-all
do not list implied . and ..

--author
with -l, print the author of each file

-b, --escape
print octal escapes for nongraphic characters

--block-size=SIZE
use SIZE-byte blocks. See SIZE format below

-B, --ignore-backups
:

學點英文,這些東西看起來都是沒問題的。

在命令行輸入/+想看的,比如/-g就可以跳轉,同時n鍵是下一個符合的查找。

q退出。

--

man是官方的幫助手段。

man man可以查看man的用法

MANUAL SECTIONS
The standard sections of the manual include:

1 User Commands

2 System Calls

3 C Library Functions

4 Devices and Special Files

5 File Formats and Conventions

6 Games et. Al.

7 Miscellanea

8 System Administration tools and Deamons

這裡有man的級別,比如剛才的ls,就是ls(1).

查看命令的man等級,man -f 命令

man 數字(級別) 命令

[root@localhost ~]# man -f ls
ls (1) - list directory contents
ls (1p) - list directory contents

[root@localhost ~]# man -f passwd
passwd (1) - update user's authentication tokens
passwd (5) - password file
passwd [sslpasswd] (1ssl) - compute password hashes
[root@localhost ~]# man 5 passwd

用whereis再來一次

[root@localhost ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz

也可以看到。

再用whatis試一下

[root@localhost ~]# whatis ls
ls (1) - list directory contents
ls (1p) - list directory contents
[root@localhost ~]# whatis passwd
passwd (1) - update user's authentication tokens
passwd (5) - password file
passwd [sslpasswd] (1ssl) - compute password hashes

再舉個栗子

[root@localhost ~]# whereis ifconfig
ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
[root@localhost ~]# whatis ifconfig
ifconfig (8) - configure a network interface
[root@localhost ~]# man 8 ifconfig

可以看到ifconfig的等級是8——看一下等級說明,也就是只能是root用戶使用的命令,同時看到ifconfig命令在sbin目錄下,也就是驗證了sbin目錄下都是只能root用戶使用的命令

--

查看與命令相關的幫助

man -k 命令 或者 apropos 命令

[root@localhost ~]# apropos passwd
chpasswd (8) - update passwords in batch mode
fgetpwent_r [getpwent_r] (3) - get passwd file entry reentrantly
getpwent_r (3) - get passwd file entry reentrantly
gpasswd (1) - administer /etc/group and /etc/gshadow
kpasswd (1) - change a user's Kerberos password
lpasswd (1) - Change group or user password
lppasswd (1) - add, change, or delete digest passwords
pam_localuser (8) - require users to be listed in /etc/passwd
pam_passwdqc (8) - Password quality-control PAM module
passwd (1) - update user's authentication tokens
passwd2des [xcrypt] (3) - RFS password encryption
passwd (5) - password file
passwd [sslpasswd] (1ssl) - compute password hashes
saslpasswd2 (8) - set a user's sasl password
smbpasswd (5) - The Samba encrypted password file
smbpasswd (8) - change a users SMB password
userpasswd (1) - A graphical tool to allow users to change their passwords
ypchfn [yppasswd] (1) - change your password in the NIS database
ypchsh [yppasswd] (1) - change your password in the NIS database
yppasswd (1) - change your password in the NIS database

4.2 其他幫助命令

--選項幫助

help 命令

命令 --help ,可以查看命令的所有選項

[root@localhost ~]# ls --help
--shell

內部(內核)命令幫助

凡是whereis,有命令的執行位置(文件),就是外部命令,比如

[root@localhost ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

[root@localhost ~]# whereis cd
cd: /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz

對比以上兩個就能很好理解。

對於外部命令,用man;對於內部命令,用help。

--詳細命令幫助info

但是,太過於詳細了。。。不太實用,操作不方便。

它會把所用的幫助文檔調出來,然後找到你要查詢的命令。

4.3 總結

man ls

ls --help

whereis cd

help cd

 

5、壓縮命令

5.1 格式

這裡提到5種linux常用的壓縮格式.zip .gz .bz2 .tar.gz .tar.bz2

5.2 .zip格式

這個格式可以windows和linux的通用

--命令格式

zip 壓縮名.zip 源文件

注意,寫壓縮名一定要添加所謂的後綴——雖然不加也可以,但是通用的做法就是加上後綴,方便你我

舉個栗子

[root@localhost ~]# ll
總用量 48
-rw-------. 1 root root 1272 9月 24 21:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 26420 9月 24 21:31 install.log
-rw-r--r--. 1 root root 7572 9月 24 21:29 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 25 07:20 japan
[root@localhost ~]# zip sex_text.zip japan
adding: japan/ (stored 0%)
[root@localhost ~]# ll
總用量 52
-rw-------. 1 root root 1272 9月 24 21:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 26420 9月 24 21:31 install.log
-rw-r--r--. 1 root root 7572 9月 24 21:29 install.log.syslog
drwxr-xr-x. 2 root root 4096 11月 25 07:20 japan
-rw-r--r--. 1 root root 162 11月 25 07:20 sex_text.zip

壓縮了一個空文件japan,然後顯示出來,會發現壓縮文件更大一點

--壓縮目錄

zip -r 名字 源文件

[root@localhost ~]# mkdir japan2
[root@localhost ~]# touch japan2/cangls
[root@localhost ~]# touch japan2/longls
[root@localhost ~]# touch japan2/boduols
[root@localhost ~]# zip -r jp.zip japan2
adding: japan2/ (stored 0%)
adding: japan2/longls (stored 0%)
adding: japan2/cangls (stored 0%)
adding: japan2/boduols (stored 0%)
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 jp.zip sex_text.zip

你懂的。

--解壓縮

unzip 壓縮文件

[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 jp.zip sex_text.zip
[root@localhost ~]# rm -rf japan
[root@localhost ~]# rm -rf japan2
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog jp.zip sex_text.zip
[root@localhost ~]# unzip jp.zip
Archive: jp.zip
creating: japan2/
extracting: japan2/longls
extracting: japan2/cangls
extracting: japan2/boduols
[root@localhost ~]# unzip sex_text.zip
Archive: sex_text.zip
creating: japan/
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 jp.zip sex_text.zip

5.3 .gz格式

是可以實現在windows中解壓縮的

--壓縮

gzip 源文件

壓縮完,直接生成一個.gz文件,然後源文件被刪除,當然可以保存下來源文件。

壓縮目錄:gzip -r 

[root@localhost ~]# gzip japan2
gzip: japan2 is a directory -- ignored
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2
[root@localhost ~]# gzip -r japan
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2

會發現沒變化,實際上gzip壓縮目錄的命令,是對目錄下的子文件都進行壓縮。所以很麻煩。。。

--解壓縮

gzip -d 壓縮文件

gunzip 壓縮文件

5.4 .bz2格式

不能壓縮目錄

--壓縮

bzip2 源文件

同樣不保留源文件

--解壓縮

bzip2 -d 壓縮文件

bunzip2 壓縮文件

-k 保留源文件

5.5 打包命令tar&.tar.bz2&tar.gz

--

tar -cvf 打包文件名 源文件

-c 打包;-v 顯示過程;-f 指定打包名

舉個栗子

[root@localhost ~]# tar -cvf japan.tar japan
japan/
japan/japan.tar

然後再用相關的壓縮命令即可

[root@localhost ~]# bzip2 japan.tar
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 japan.tar.bz2

總結一下就是先打包後壓縮——完美解決無法壓縮目錄的問題——但是麻煩(一會兒說)

--解壓縮

同樣以栗子來說

[root@localhost ~]# bunzip2 japan.tar.bz2
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 japan.tar
[root@localhost ~]# tar -xvf japan.tar
japan/
japan/japan.tar

解壓縮-》解打包——tar -xvf tar文件

--直接實現

tar -zcvf 壓縮文件.tar.gz 源文件

tar -jcvf 壓縮文件.tar.bz2 源文件

[root@localhost ~]# rm -f japan.tar
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2
[root@localhost ~]# tar -zcvf jp.tar.gz japan
japan/
japan/japan.tar
[root@localhost ~]# tar -jcvf jp.tar.gz japan
japan/
japan/japan.tar
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 jp.tar.gz
[root@localhost ~]# tar -jcvf jp.tar.bz2 japan
japan/
japan/japan.tar
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 jp.tar.bz2 jp.tar.gz

--

解壓縮的時候還可以選擇解壓縮位置

[root@localhost ~]# tar -jxvf jp.tar.bz2 -C /tmp/
japan/
japan/japan.tar

注意位置選項書寫的位置

--高級壓縮

tar -jcvf /tmp/jp.tar.bz2 japan japan2

這裡把壓縮文件存到指定目錄,而且壓縮的是兩個目錄的文件

5.6 總結

最常用的是最後兩個.tar.gz和.tar.bz2

 

6、關機與重啟(服務器)

6.1 shutdown

shutdown [] 時間

-c 取消

-h 關機

-r 重啟

舉個栗子

[root@localhost ~]# date
2015年 11月 25日 星期三 08:37:52 CST
[root@localhost ~]# shutdown -r 12:20

Broadcast message from [email protected]
(/dev/pts/0) at 8:38 ...

The system is going down for reboot in 222 minutes!
shuit^H^H^H^H^H^H^H^H^H^Cshutdown: Shutdown cancelled
[root@localhost ~]# shutdown -r 12:20 &
[1] 25959
[root@localhost ~]#
Broadcast message from [email protected]
(/dev/pts/0) at 8:39 ...

The system is going down for reboot in 221 minutes!

這個例子是說:顯示當前時間,然後設定關機時間,然後ctrl+c退出,然後同樣的命令加&,讓這條命令不影響以後的使用,兩次enter回來

注意,虛擬機的時間是不確定的

[root@localhost ~]# shutdown -c
shutdown: Shutdown cancelled
[1]+ Done shutdown -r 12:20

然後shutdown -c 取消上一個關機的命令

標准的關機命令是shutdown -r now

注意,一般不要關機,而是用-r重啟比較好——服務器在遠端

而且,鑒於該命令的安全和日期保存等,一般關機重啟都是用shutdown命令

6.2 其他關機命令

halt,poweroff,init 0

不是很安全,一般不要用

6.3 其他重啟命令

reboot 可以用

init 6

6.4 退出登錄命令

logout

使用完遠程工具,最好不要直接關閉——不然用戶會卡住,造成不必要的問題

這裡的logout就是注銷

 

7、其他常用命令

7.1 掛載命令

簡單的理解就是分配盤符

7.1.1 查詢與自動掛載

--

mount

[root@localhost ~]# mount
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda2 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

很簡單,就是目錄+類型+權限。就看懂根分區,home和boot就行了。

--

mount -a 實現自動掛載,依據是/etc/fstab這個文件的配置

用vi命令看一下


#
# /etc/fstab
# Created by anaconda on Thu Sep 24 21:12:39 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=81a087d8-5e03-442d-a138-a0a5b16a0e4c / ext4 defaults 1 1
UUID=e27af68c-c4a8-4982-b81e-7c1ca4ef5eaa /boot ext4 defaults 1 2
UUID=04f853b6-845f-459f-a858-1f84d6a98ce7 /home ext4 defaults 1 2
UUID=8315579c-295e-4254-9c27-1c30894b4544 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
大概看看就行,暫時不要動。

假設想自動掛載U盤,不建議,因為系統每次都要自動掛載,如果沒有找到設備,就會系統崩潰。

7.1.2 掛載命令格式

mount [-t 文件系統] [-o 特殊選項] 設備 文件名 掛載點

文件系統-ext4,沒寫的話,默認為iso9660

特殊選項比較多,但每一個都有默認值

[root@localhost ~]# cd /home
[root@localhost home]# vi hello.sh
[root@localhost home]# chmod 755 hello.sh
[root@localhost home]# ll
總用量 20
-rwxr-xr-x. 1 root root 36 11月 25 09:19 hello.sh
drwx------. 2 root root 16384 9月 24 21:09 lost+found
[root@localhost home]# ./hello.sh
hello cangls!!!
[root@localhost home]# hello.
-bash: hello.: command not found
[root@localhost home]# /home/hello.sh
hello cangls!!!

可以拿這個文件去做權限等的實驗

7.1.3 掛載光盤

第一步:在虛擬機中放一個iso鏡像,相當於放個光盤先。記得在虛擬機中的已連接打勾

第二步:建立掛載點(盤符)

任何空目錄就可以作為盤符

[root@localhost home]# ls /
bin cgroup etc lib media mnt opt root selinux sys usr
boot dev home lost+found misc net proc sbin srv tmp var

這裡的mnt常作為U盤光盤等的掛載點。

[root@localhost ~]# mkdir /mnt/cdrom

第三步:執行掛載命令

[root@localhost ~]# mount -t iso9660 /dev/sr0 /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only

這樣其實就ok了

--讀取

[root@localhost ~]# cd /mnt/cdrom
[root@localhost cdrom]# ls
AUTHORS ChangeLog COPYING isolinux user_guide.html user_guide.tex

7.1.4 卸載命令

用於彈出光盤

umount 設備名或者掛載點

[root@localhost cdrom]# umount /mnt/cdrom/
umount: /mnt/cdrom: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))

發現設備正忙。。。因為當前用戶就在當前目錄下。。。。。。。

[root@localhost cdrom]# cd
[root@localhost ~]# umount /mnt/cdrom/

注意,卸載命令是必須有的。

7.1.5 U盤的掛載

光盤的設備是一直都在/dev的,sr0

[root@localhost ~]# ls /dev/
agpgart dvd loop1 net ram13 scd0 systty tty21 tty36 tty50 tty8 vcs6
autofs dvdrw loop2 network_latency ram14 sda tty tty22 tty37 tty51 tty9 vcsa
block fb loop3 network_throughput ram15 sda1 tty0 tty23 tty38 tty52 ttyS0 vcsa1
bsg fb0 loop4 null ram2 sda2 tty1 tty24 tty39 tty53 ttyS1 vcsa2
btrfs-control fd loop5 nvram ram3 sda3 tty10 tty25 tty4 tty54 ttyS2 vcsa3
bus full loop6 oldmem ram4 sda4 tty11 tty26 tty40 tty55 ttyS3 vcsa4
cdrom fuse loop7 parport0 ram5 sda5 tty12 tty27 tty41 tty56 urandom vcsa5
cdrw hidraw0 lp0 port ram6 sg0 tty13 tty28 tty42 tty57 usbmon0 vcsa6
char hidraw1 lp1 ppp ram7 sg1 tty14 tty29 tty43 tty58 usbmon1 vga_arbiter
console hpet lp2 ptmx ram8 shm tty15 tty3 tty44 tty59 usbmon2 zero
core hugepages lp3 pts ram9 snapshot tty16 tty30 tty45 tty6 vcs
cpu hvc0 MAKEDEV ram0 random snd tty17 tty31 tty46 tty60 vcs1
cpu_dma_latency input mapper ram1 raw sr0 tty18 tty32 tty47 tty61 vcs2
crash kmsg mcelog ram10 root stderr tty19 tty33 tty48 tty62 vcs3
disk log mem ram11 rtc stdin tty2 tty34 tty49 tty63 vcs4
dmmidi loop0 midi ram12 rtc0 stdout tty20 tty35 tty5 tty7 vcs5

U盤則是看成是一個硬盤。插入後,被認為是新的一塊硬盤。要查看一下

[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000018cb

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 281 2048000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 281 409 1024000 82 Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4 409 1306 7207936 5 Extended
/dev/sda5 409 1306 7206912 83 Linux

fdisk -l 看一下已經識別的硬盤。

一般來說,U盤是sdb1

掛載

mount -t vfat /dev/sdb1 /mnt/usb/

注意,vfat類型就是fat32,linux系統默認不支持ntfs。所以,移動硬盤和ntfs的U盤是無法直接掛載的。好在大多數U盤是fat32的文件系統。

解決辦法是安裝驅動——NTFS 3G,但是只能是只讀的。想寫,只能修改內核。

實際上,都直接網絡傳輸了。

7.2 用戶登錄查看命令

--w

查看用戶的登錄信息

[root@localhost ~]# w
10:04:45 up 1:10, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.2.111 08:59 0.00s 0.56s 0.21s w

分別是系統時間,使用的時間,已登錄用戶,三次時間點的平均負載。

然後是,用戶名,登錄地點(/0是遠程),

--who

[root@localhost ~]# who
root pts/0 2015-11-25 08:59 (192.168.2.111)

不用解釋了吧,只是w要多看一點負載

--last

[root@localhost ~]# who
root pts/0 2015-11-25 08:59 (192.168.2.111)
[root@localhost ~]# last
root pts/0 192.168.2.111 Wed Nov 25 08:59 still logged in
root pts/0 192.168.2.111 Wed Nov 25 08:55 - 08:59 (00:03)
reboot system boot 2.6.32-504.el6.i Wed Nov 25 08:54 - 10:11 (01:16)
root pts/0 192.168.2.111 Wed Nov 25 06:26 - down (02:26)
root pts/0 192.168.1.101 Wed Nov 25 06:09 - 06:22 (00:13)
root tty4 Wed Nov 25 06:02 - down (02:51)
root tty1 Wed Nov 25 05:09 - down (03:44)
reboot system boot 2.6.32-504.el6.i Wed Nov 25 05:05 - 08:53 (03:48)
root pts/0 192.168.0.235 Wed Nov 25 05:00 - down (00:03)
root tty1 Wed Nov 25 04:43 - down (00:20)
reboot system boot 2.6.32-504.el6.i Wed Nov 25 04:42 - 05:04 (00:21)
root tty1 Thu Sep 24 22:24 - down (00:01)
reboot system boot 2.6.32-504.el6.i Thu Sep 24 22:24 - 22:26 (00:02)

wtmp begins Thu Sep 24 22:24:03 2015

查看過去的登錄用戶信息

--lastlog

[root@localhost ~]# lastlog
用戶名 端口 來自 最後登陸時間
root pts/0 192.168.2.111 三 11月 25 08:59:28 +0800 2015
bin **從未登錄過**
daemon **從未登錄過**
adm **從未登錄過**
lp **從未登錄過**
sync **從未登錄過**
shutdown **從未登錄過**
halt **從未登錄過**
mail **從未登錄過**
uucp **從未登錄過**
operator **從未登錄過**
games **從未登錄過**
gopher **從未登錄過**
ftp **從未登錄過**
nobody **從未登錄過**
dbus **從未登錄過**
vcsa **從未登錄過**
rpc **從未登錄過**
haldaemon **從未登錄過**
ntp **從未登錄過**
saslauth **從未登錄過**
postfix **從未登錄過**
abrt **從未登錄過**
rpcuser **從未登錄過**
nfsnobody **從未登錄過**
sshd **從未登錄過**
tcpdump **從未登錄過**
oprofile **從未登錄過**

列出所有用戶,並顯示他們的狀態

---------------------------------------------

果然沒睡好是不行的,回去休息了。明天還要改報告和綜述,不知道有沒機會學習了。bye

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved