·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> 还是不想改报告,伊阿忆啊哟-Linux基础继续

还是不想改报告,伊阿忆啊哟-Linux基础继续

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23

  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