Home > Article > Backend Development > I still don't want to change the report, Yi A Yi Ah Yo-Linux Basics Continue, Ah Yo-linux_PHP Tutorial
hi
Although today is the most wonderful Saturday (there is no working day before or after), I still want to change the report, but I just don’t want to change it. What can you do to me? . .
Strive to complete the basics of Linux
1. Common Linux commands (3)
4. Help command
4.1 Help command man
man command
--Example
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
:
Learn some English, these things seem to be no problem.
Enter what you want to see on the command line, such as /-g to jump, and the n key is the next matching search.
qExit.
--
man is the official help method.
man man can check the usage of 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
There are man levels here, such as the ls just now, which is ls(1).
View the man level of the command, man -f command
man number (level) command
[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
Use whereis again
[root@localhost ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/ passwd.1.gz
Can also be seen.
Try using whatis again
[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
Give me another chestnut
[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
You can see that the level of ifconfig is 8 - look at the level description, that is, the command can only be used by the root user. At the same time, you can see that the ifconfig command is in the sbin directory, which means that it is verified that all the commands in the sbin directory are available. It is a command that can only be used by root users
--
View command-related help
man -k command or apropos command
[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 format
It is possible to decompress in windows
--Compression
gzip source file
After compression, a .gz file is directly generated, and then the source file is deleted. Of course, the source file can be saved.
Compressed directory: 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
You will find that there is no change. In fact, the gzip command to compress a directory compresses all sub-files in the directory. So it's very troublesome. . .
--Unzip
gzip -d compressed file
gunzip compressed file
5.4 .bz2 format
Directories cannot be compressed
--Compression
bzip2 source file
The source file is also not retained
--Unzip
bzip2 -d compressed file
bunzip2 compressed file
-k keep source files
5.5 Packaging command tar&.tar.bz2&tar.gz
--
tar -cvf package file name source file
-c package;-v display process;-f specify package name
Give me a chestnut
[root@localhost ~]# tar -cvf japan.tar japan
japan/
japan/japan.tar
Then use the relevant compression commands
[root@localhost ~]# bzip2 japan.tar
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog japan japan2 japan.tar.bz2
To summarize, it is to package first and then compress - a perfect solution to the problem of being unable to compress the directory - but troublesome (will be discussed later)
--Unzip
The same goes for chestnuts
[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
Unzip->Unpack-tar -xvf tar file
--Direct implementation
tar -zcvf compressed file .tar.gz source file
tar -jcvf compressed file.tar.bz2 source file
[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
--
When decompressing, you can also select the decompression location
[root@localhost ~]# tar -jxvf jp.tar.bz2 -C /tmp/
japan/
japan/japan.tar
Pay attention to where the position option is written
--Advanced Compression
tar -jcvf /tmp/jp.tar.bz2 japan japan2
Here, the compressed file is saved to the specified directory, and the files in two directories are compressed
5.6 Summary
The most commonly used ones are the last two .tar.gz and .tar.bz2
6. Shutdown and restart (server)
6.1 shutdown
shutdown [] time
-c Cancel
-h shutdown
-r restart
Give me a chestnut
[root@localhost ~]# date
Wednesday, November 25, 2015 08:37:52 CST
[root@localhost ~]# shutdown -r 12:20
Broadcast message from root@localhost.localdomain
(/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 canceled
[root@localhost ~] # shutdown -r 12:20 &
[1] 25959
[root@localhost ~]#
Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 8: 39...
The system is going down for reboot in 221 minutes!
This example is: display the current time, then set the shutdown time, then ctrl c to exit, then add & to the same command so that this command does not affect future use, enter twice to return
Note that the time of the virtual machine is uncertain
[root@localhost ~]# shutdown -c
shutdown: Shutdown canceled
[1] Done shutdown -r 12:20
Then shutdown -c cancels the previous shutdown command
The standard shutdown command is shutdown -r now
Note, generally do not shut down, but use -r to restart - the server is remote
Furthermore, in view of the security and date preservation of this command, Generally, shutdown command is used to shut down and restart
6.2 Other shutdown commands
halt, poweroff, init 0
Not very safe, generally don’t use it
6.3 Other restart commands
Reboot can be used
init 6
6.4 Logout command
logout
After using the remote tool, it is best not to close it directly - otherwise the user will get stuck and cause unnecessary problems
Logout here means logging out
7. Other commonly used commands
7.1 Mount command
A simple understanding is to assign a drive letter
7.1.1 Query and automatic mounting
--
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)
It’s very simple, it’s directory type permissions. Just understand the root partition, home and boot.
--
mount -a implements automatic mounting, based on the configuration of the /etc/fstab file
Use vi command to take a look
#
# /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-1f84d6a 98ce7 /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
Just take a look and don’t touch it for now.
Suppose you want to automatically mount the USB flash drive. This is not recommended because the system has to mount it automatically every time. If the device is not found, the system will crash.
7.1.2 Mount command format
mount [-t file system] [-o special option] device file name mount point
File system-ext4, if not written, defaults to iso9660
There are many special options, but each one has a default value
[root@localhost ~]# cd /home
[root@localhost home]# vi hello.sh
[root@localhost home]# chmod 755 hello.sh
[root@localhost home ]# ll
Total usage 20
-rwxr-xr-x. 1 root root 36 November 25 09:19 hello.sh
drwx------. 2 root root 16384 September 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!!!
You can use this file to experiment with permissions etc.
7.1.3 Mounting the CD
Step one: Place an iso image in the virtual machine, which is equivalent to placing a CD first. Remember to check Connected in the virtual machine.
Step 2: Create a mount point (drive letter)
Any empty directory can be used as a drive letter
[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
The mnt here is often used as a mount point for USB disks, CDs, etc.
[root@localhost ~]# mkdir /mnt/cdrom
Step 3: Execute the mount command
[root@localhost ~]# mount -t iso9660 /dev/sr0 /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
This is actually ok
--Read
[root@localhost ~]# cd /mnt/cdrom
[root@localhost cdrom]# ls
AUTHORS ChangeLog COPYING isolinux user_guide.html user_guide.tex
7.1.4 Uninstall command
For ejecting discs
umount device name or mount point
[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))
The device was found to be busy. . . Because the current user is in the current directory. . . . . . .
[root@localhost cdrom]# cd
[root@localhost ~]# umount /mnt/cdrom/
Note that the uninstall command is required.
7.1.5 Mounting USB flash drive
The CD device is always in /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 loop fb 3 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 tty S2 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 tty 60 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
The USB flash drive is regarded as a hard drive. After insertion, it is considered a new hard drive. Check it out
[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/sda5 409 1306 7206912 83 Linux
fdisk -l Take a look at the identified hard drives.
Generally speaking, the USB flash drive is sdb1
Mount
mount -t vfat /dev/sdb1 /mnt/usb/Note that the vfat type is fat32, and the Linux system does not support ntfs by default. Therefore, mobile hard disks and ntfs U disks cannot be mounted directly. Fortunately, most USB flash drives have a fat32 file system.
The solution is to install the driver - NTFS 3G, but it can only be read-only. If you want to write, you can only modify the kernel.
In fact, it is all directly transmitted over the Internet.
7.2 User login to view commands
--w
View user’s login information
[root@localhost ~]# w
10:04:45 up 1:10, 1 user, load average: 0.00, 0.00, 0.00USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.2.111 08:59 0.00s 0.56s 0.21s w
They are system time, usage time, logged in user, and average load at three time points.
Then, user name, login location (/0 is remote),
--who
[root@localhost ~]# who
root pts/0 2015-11-25 08:59 (192.168.2.111)
No need to explain, it’s just that you need to pay more attention to the load
--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