From cb7448079f5ca97e294efd210dc8c3ec651be6e5 Mon Sep 17 00:00:00 2001 From: Black-Gold Date: Thu, 14 Feb 2019 15:27:24 +0800 Subject: [PATCH] --- .vscode/settings.json | 40 +- LinuxCommands/git.md | 117 - {LinuxCommands => Linux_man_cn}/ab.md | 2 +- {LinuxCommands => Linux_man_cn}/accept.md | 0 {LinuxCommands => Linux_man_cn}/alias.md | 224 +- {LinuxCommands => Linux_man_cn}/apachectl.md | 2 +- {LinuxCommands => Linux_man_cn}/apropos.md | 2 +- {LinuxCommands => Linux_man_cn}/apt-get.md | 2 +- {LinuxCommands => Linux_man_cn}/apt-key.md | 2 +- .../apt-sortpkgs.md | 2 +- {LinuxCommands => Linux_man_cn}/aptitude.md | 2 +- {LinuxCommands => Linux_man_cn}/ar.md | 0 {LinuxCommands => Linux_man_cn}/arch.md | 0 {LinuxCommands => Linux_man_cn}/arj.md | 0 {LinuxCommands => Linux_man_cn}/arp.md | 2 +- {LinuxCommands => Linux_man_cn}/arpd.md | 2 +- {LinuxCommands => Linux_man_cn}/arping.md | 2 +- {LinuxCommands => Linux_man_cn}/arptables.md | 2 +- {LinuxCommands => Linux_man_cn}/arpwatch.md | 2 +- {LinuxCommands => Linux_man_cn}/as.md | 0 {LinuxCommands => Linux_man_cn}/at.md | 0 {LinuxCommands => Linux_man_cn}/atop.md | 0 {LinuxCommands => Linux_man_cn}/atq.md | 0 {LinuxCommands => Linux_man_cn}/atrm.md | 0 {LinuxCommands => Linux_man_cn}/awk.md | 2626 ++++++++--------- {LinuxCommands => Linux_man_cn}/axel.md | 0 {LinuxCommands => Linux_man_cn}/badblocks.md | 0 {LinuxCommands => Linux_man_cn}/basename.md | 2 +- {LinuxCommands => Linux_man_cn}/batch.md | 0 {LinuxCommands => Linux_man_cn}/bc.md | 0 {LinuxCommands => Linux_man_cn}/bg.md | 0 {LinuxCommands => Linux_man_cn}/bind.md | 2 +- {LinuxCommands => Linux_man_cn}/blkid.md | 2 +- {LinuxCommands => Linux_man_cn}/blockdev.md | 0 {LinuxCommands => Linux_man_cn}/bmodinfo.md | 0 {LinuxCommands => Linux_man_cn}/builtin.md | 0 {LinuxCommands => Linux_man_cn}/bunzip2.md | 0 {LinuxCommands => Linux_man_cn}/bye.md | 0 {LinuxCommands => Linux_man_cn}/bzcat.md | 0 {LinuxCommands => Linux_man_cn}/bzcmp.md | 0 {LinuxCommands => Linux_man_cn}/bzdiff.md | 0 {LinuxCommands => Linux_man_cn}/bzgrep.md | 0 {LinuxCommands => Linux_man_cn}/bzip2.md | 0 .../bzip2recover.md | 0 {LinuxCommands => Linux_man_cn}/bzless.md | 0 {LinuxCommands => Linux_man_cn}/bzmore.md | 0 {LinuxCommands => Linux_man_cn}/cal.md | 2 +- {LinuxCommands => Linux_man_cn}/cancel.md | 0 {LinuxCommands => Linux_man_cn}/cat.md | 2 +- {LinuxCommands => Linux_man_cn}/cd.md | 2 +- {LinuxCommands => Linux_man_cn}/cdrecord.md | 0 {LinuxCommands => Linux_man_cn}/chage.md | 0 {LinuxCommands => Linux_man_cn}/chattr.md | 2 +- {LinuxCommands => Linux_man_cn}/chcon.md | 0 {LinuxCommands => Linux_man_cn}/chfn.md | 0 {LinuxCommands => Linux_man_cn}/chgrp.md | 104 +- {LinuxCommands => Linux_man_cn}/chkconfig.md | 158 +- {LinuxCommands => Linux_man_cn}/chmod.md | 182 +- {LinuxCommands => Linux_man_cn}/chown.md | 2 +- {LinuxCommands => Linux_man_cn}/chpasswd.md | 0 {LinuxCommands => Linux_man_cn}/chroot.md | 0 {LinuxCommands => Linux_man_cn}/chsh.md | 0 {LinuxCommands => Linux_man_cn}/cksum.md | 0 {LinuxCommands => Linux_man_cn}/clear.md | 2 +- {LinuxCommands => Linux_man_cn}/clock.md | 0 {LinuxCommands => Linux_man_cn}/clockdiff.md | 0 {LinuxCommands => Linux_man_cn}/cmp.md | 0 {LinuxCommands => Linux_man_cn}/col.md | 0 {LinuxCommands => Linux_man_cn}/colrm.md | 0 {LinuxCommands => Linux_man_cn}/comm.md | 0 {LinuxCommands => Linux_man_cn}/command.md | 0 {LinuxCommands => Linux_man_cn}/compress.md | 0 .../consoletype.md | 0 .../convertquota.md | 0 {LinuxCommands => Linux_man_cn}/cp.md | 304 +- {LinuxCommands => Linux_man_cn}/cpio.md | 0 {LinuxCommands => Linux_man_cn}/crontab.md | 0 {LinuxCommands => Linux_man_cn}/csplit.md | 0 {LinuxCommands => Linux_man_cn}/cu.md | 0 .../cupsdisable.md | 0 {LinuxCommands => Linux_man_cn}/cupsenable.md | 0 {LinuxCommands => Linux_man_cn}/curl.md | 0 {LinuxCommands => Linux_man_cn}/cut.md | 2 +- {LinuxCommands => Linux_man_cn}/date.md | 340 +-- {LinuxCommands => Linux_man_cn}/dd.md | 0 {LinuxCommands => Linux_man_cn}/declare.md | 0 {LinuxCommands => Linux_man_cn}/depmod.md | 0 {LinuxCommands => Linux_man_cn}/df.md | 2 +- {LinuxCommands => Linux_man_cn}/dhclient.md | 0 {LinuxCommands => Linux_man_cn}/dhcpd.md | 0 {LinuxCommands => Linux_man_cn}/dhcrelay.md | 0 {LinuxCommands => Linux_man_cn}/diff.md | 0 {LinuxCommands => Linux_man_cn}/diff3.md | 0 {LinuxCommands => Linux_man_cn}/diffstat.md | 0 {LinuxCommands => Linux_man_cn}/dig.md | 0 {LinuxCommands => Linux_man_cn}/dircolors.md | 0 {LinuxCommands => Linux_man_cn}/dirname.md | 2 +- {LinuxCommands => Linux_man_cn}/dirs.md | 0 {LinuxCommands => Linux_man_cn}/dmesg.md | 106 +- {LinuxCommands => Linux_man_cn}/dmidecode.md | 0 {LinuxCommands => Linux_man_cn}/dnf.md | 0 .../dnsdomainname.md | 0 {LinuxCommands => Linux_man_cn}/domainname.md | 0 {LinuxCommands => Linux_man_cn}/dos2unix.md | 2 +- {LinuxCommands => Linux_man_cn}/dpkg-deb.md | 2 +- .../dpkg-divert.md | 2 +- .../dpkg-preconfigure.md | 2 +- {LinuxCommands => Linux_man_cn}/dpkg-query.md | 2 +- .../dpkg-reconfigure.md | 2 +- {LinuxCommands => Linux_man_cn}/dpkg-split.md | 2 +- .../dpkg-statoverride.md | 2 +- .../dpkg-trigger.md | 2 +- {LinuxCommands => Linux_man_cn}/dpkg.md | 2 +- {LinuxCommands => Linux_man_cn}/dris.md | 0 {LinuxCommands => Linux_man_cn}/dstat.md | 0 {LinuxCommands => Linux_man_cn}/du.md | 2 +- {LinuxCommands => Linux_man_cn}/dump.md | 2 +- {LinuxCommands => Linux_man_cn}/dumpe2fs.md | 0 {LinuxCommands => Linux_man_cn}/e2fsck.md | 0 {LinuxCommands => Linux_man_cn}/e2label.md | 0 {LinuxCommands => Linux_man_cn}/echo.md | 0 {LinuxCommands => Linux_man_cn}/ed.md | 0 {LinuxCommands => Linux_man_cn}/edquota.md | 0 {LinuxCommands => Linux_man_cn}/egrep.md | 0 {LinuxCommands => Linux_man_cn}/eject.md | 0 {LinuxCommands => Linux_man_cn}/elinks.md | 0 {LinuxCommands => Linux_man_cn}/elm.md | 0 {LinuxCommands => Linux_man_cn}/emacs.md | 0 {LinuxCommands => Linux_man_cn}/enable.md | 0 {LinuxCommands => Linux_man_cn}/env.md | 0 {LinuxCommands => Linux_man_cn}/ethtool.md | 0 {LinuxCommands => Linux_man_cn}/ex.md | 0 {LinuxCommands => Linux_man_cn}/exec.md | 0 {LinuxCommands => Linux_man_cn}/exit.md | 0 {LinuxCommands => Linux_man_cn}/expand.md | 0 {LinuxCommands => Linux_man_cn}/export.md | 2 +- {LinuxCommands => Linux_man_cn}/exportfs.md | 0 {LinuxCommands => Linux_man_cn}/expr.md | 0 {LinuxCommands => Linux_man_cn}/fc.md | 0 {LinuxCommands => Linux_man_cn}/fdisk.md | 642 ++-- {LinuxCommands => Linux_man_cn}/fg.md | 0 {LinuxCommands => Linux_man_cn}/fgrep.md | 0 {LinuxCommands => Linux_man_cn}/file.md | 2 +- {LinuxCommands => Linux_man_cn}/find.md | 2500 ++++++++-------- {LinuxCommands => Linux_man_cn}/findfs.md | 0 {LinuxCommands => Linux_man_cn}/finger.md | 0 .../firewall-cmd.md | 0 {LinuxCommands => Linux_man_cn}/fmt.md | 0 {LinuxCommands => Linux_man_cn}/fold.md | 0 {LinuxCommands => Linux_man_cn}/free.md | 318 +- {LinuxCommands => Linux_man_cn}/fsck.ext4.md | 0 {LinuxCommands => Linux_man_cn}/fsck.md | 2 +- {LinuxCommands => Linux_man_cn}/ftp.md | 0 {LinuxCommands => Linux_man_cn}/ftpcount.md | 0 {LinuxCommands => Linux_man_cn}/ftpshut.md | 0 {LinuxCommands => Linux_man_cn}/ftptop.md | 0 {LinuxCommands => Linux_man_cn}/ftpwho.md | 0 {LinuxCommands => Linux_man_cn}/fuser.md | 0 {LinuxCommands => Linux_man_cn}/gcc.md | 0 {LinuxCommands => Linux_man_cn}/gcov.md | 0 {LinuxCommands => Linux_man_cn}/gdb.md | 0 {LinuxCommands => Linux_man_cn}/get_module.md | 0 {LinuxCommands => Linux_man_cn}/getenforce.md | 0 {LinuxCommands => Linux_man_cn}/getsebool.md | 0 {LinuxCommands => Linux_man_cn}/gpasswd.md | 0 {LinuxCommands => Linux_man_cn}/gpm.md | 0 {LinuxCommands => Linux_man_cn}/grep.md | 0 {LinuxCommands => Linux_man_cn}/groupadd.md | 2 +- {LinuxCommands => Linux_man_cn}/groupdel.md | 2 +- {LinuxCommands => Linux_man_cn}/groupmod.md | 2 +- {LinuxCommands => Linux_man_cn}/groups.md | 0 {LinuxCommands => Linux_man_cn}/grpck.md | 0 {LinuxCommands => Linux_man_cn}/grpconv.md | 0 {LinuxCommands => Linux_man_cn}/grpunconv.md | 0 {LinuxCommands => Linux_man_cn}/grub.md | 0 {LinuxCommands => Linux_man_cn}/gunzip.md | 0 {LinuxCommands => Linux_man_cn}/gzexe.md | 0 {LinuxCommands => Linux_man_cn}/gzip.md | 0 {LinuxCommands => Linux_man_cn}/halt.md | 0 {LinuxCommands => Linux_man_cn}/hdparm.md | 0 {LinuxCommands => Linux_man_cn}/head.md | 0 {LinuxCommands => Linux_man_cn}/help.md | 0 {LinuxCommands => Linux_man_cn}/hexdump.md | 0 {LinuxCommands => Linux_man_cn}/history.md | 0 {LinuxCommands => Linux_man_cn}/host.md | 0 {LinuxCommands => Linux_man_cn}/hostid.md | 0 {LinuxCommands => Linux_man_cn}/hostname.md | 0 {LinuxCommands => Linux_man_cn}/hping3.md | 0 {LinuxCommands => Linux_man_cn}/htdigest.md | 0 {LinuxCommands => Linux_man_cn}/htop.md | 0 {LinuxCommands => Linux_man_cn}/htpasswd.md | 0 {LinuxCommands => Linux_man_cn}/hwclock.md | 0 {LinuxCommands => Linux_man_cn}/iconv.md | 0 {LinuxCommands => Linux_man_cn}/id.md | 0 {LinuxCommands => Linux_man_cn}/ifcfg.md | 0 {LinuxCommands => Linux_man_cn}/ifconfig.md | 0 {LinuxCommands => Linux_man_cn}/ifdown.md | 0 {LinuxCommands => Linux_man_cn}/ifstat.md | 0 {LinuxCommands => Linux_man_cn}/iftop.md | 0 {LinuxCommands => Linux_man_cn}/ifup.md | 0 {LinuxCommands => Linux_man_cn}/indent.md | 0 {LinuxCommands => Linux_man_cn}/info.md | 2 +- {LinuxCommands => Linux_man_cn}/init.md | 0 .../inotifywait.md | 2 +- {LinuxCommands => Linux_man_cn}/insmod.md | 0 {LinuxCommands => Linux_man_cn}/install.md | 0 {LinuxCommands => Linux_man_cn}/iostat.md | 2 +- {LinuxCommands => Linux_man_cn}/iotop.md | 2 +- {LinuxCommands => Linux_man_cn}/ip.md | 212 +- .../ip6tables-restore.md | 2 +- .../ip6tables-save.md | 2 +- {LinuxCommands => Linux_man_cn}/ip6tables.md | 2 +- {LinuxCommands => Linux_man_cn}/ipcalc.md | 2 +- {LinuxCommands => Linux_man_cn}/ipcrm.md | 2 +- {LinuxCommands => Linux_man_cn}/ipcs.md | 2 +- {LinuxCommands => Linux_man_cn}/iperf.md | 2 +- .../iptables-restore.md | 2 +- .../iptables-save.md | 2 +- {LinuxCommands => Linux_man_cn}/iptables.md | 0 {LinuxCommands => Linux_man_cn}/iptraf.md | 2 +- {LinuxCommands => Linux_man_cn}/iptstate.md | 2 +- {LinuxCommands => Linux_man_cn}/ispell.md | 0 {LinuxCommands => Linux_man_cn}/jed.md | 0 {LinuxCommands => Linux_man_cn}/jobs.md | 0 {LinuxCommands => Linux_man_cn}/joe.md | 0 {LinuxCommands => Linux_man_cn}/join.md | 0 {LinuxCommands => Linux_man_cn}/jwhois.md | 0 .../kernelversion.md | 0 {LinuxCommands => Linux_man_cn}/kexec.md | 0 {LinuxCommands => Linux_man_cn}/kill.md | 0 {LinuxCommands => Linux_man_cn}/killall.md | 0 {LinuxCommands => Linux_man_cn}/last.md | 2 +- {LinuxCommands => Linux_man_cn}/lastb.md | 0 {LinuxCommands => Linux_man_cn}/lastlog.md | 0 {LinuxCommands => Linux_man_cn}/ld.md | 0 {LinuxCommands => Linux_man_cn}/ldconfig.md | 0 {LinuxCommands => Linux_man_cn}/ldd.md | 0 {LinuxCommands => Linux_man_cn}/less.md | 2 +- {LinuxCommands => Linux_man_cn}/let.md | 0 {LinuxCommands => Linux_man_cn}/lftp.md | 0 {LinuxCommands => Linux_man_cn}/lftpget.md | 0 {LinuxCommands => Linux_man_cn}/lha.md | 0 {LinuxCommands => Linux_man_cn}/lilo.md | 0 {LinuxCommands => Linux_man_cn}/ln.md | 240 +- {LinuxCommands => Linux_man_cn}/lnstat.md | 0 {LinuxCommands => Linux_man_cn}/locale.md | 52 +- {LinuxCommands => Linux_man_cn}/locate.md | 0 {LinuxCommands => Linux_man_cn}/logger.md | 0 {LinuxCommands => Linux_man_cn}/login.md | 0 {LinuxCommands => Linux_man_cn}/logname.md | 0 {LinuxCommands => Linux_man_cn}/logout.md | 0 {LinuxCommands => Linux_man_cn}/logrotate.md | 0 {LinuxCommands => Linux_man_cn}/logsave.md | 0 {LinuxCommands => Linux_man_cn}/logwatch.md | 0 {LinuxCommands => Linux_man_cn}/look.md | 0 {LinuxCommands => Linux_man_cn}/losetup.md | 0 {LinuxCommands => Linux_man_cn}/lp.md | 0 {LinuxCommands => Linux_man_cn}/lpadmin.md | 0 {LinuxCommands => Linux_man_cn}/lpc.md | 0 {LinuxCommands => Linux_man_cn}/lpq.md | 0 {LinuxCommands => Linux_man_cn}/lpr.md | 0 {LinuxCommands => Linux_man_cn}/lprm.md | 0 {LinuxCommands => Linux_man_cn}/lpstat.md | 0 {LinuxCommands => Linux_man_cn}/ls.md | 0 {LinuxCommands => Linux_man_cn}/lsattr.md | 0 .../lsb_release.md | 0 {LinuxCommands => Linux_man_cn}/lsblk.md | 2 +- {LinuxCommands => Linux_man_cn}/lscpu.md | 0 {LinuxCommands => Linux_man_cn}/lsmod.md | 0 {LinuxCommands => Linux_man_cn}/lsof.md | 2 +- {LinuxCommands => Linux_man_cn}/lspci.md | 0 {LinuxCommands => Linux_man_cn}/lsusb.md | 0 {LinuxCommands => Linux_man_cn}/ltrace.md | 0 {LinuxCommands => Linux_man_cn}/lvcreate.md | 0 {LinuxCommands => Linux_man_cn}/lvdisplay.md | 0 {LinuxCommands => Linux_man_cn}/lvextend.md | 0 {LinuxCommands => Linux_man_cn}/lvreduce.md | 0 {LinuxCommands => Linux_man_cn}/lvremove.md | 0 {LinuxCommands => Linux_man_cn}/lvresize.md | 0 {LinuxCommands => Linux_man_cn}/lvscan.md | 0 {LinuxCommands => Linux_man_cn}/lynx.md | 0 {LinuxCommands => Linux_man_cn}/mail.md | 0 {LinuxCommands => Linux_man_cn}/mailq.md | 0 {LinuxCommands => Linux_man_cn}/mailstat.md | 0 {LinuxCommands => Linux_man_cn}/make.md | 0 {LinuxCommands => Linux_man_cn}/man.md | 280 +- {LinuxCommands => Linux_man_cn}/md5sum.md | 0 {LinuxCommands => Linux_man_cn}/mesg.md | 0 {LinuxCommands => Linux_man_cn}/mii-tool.md | 0 {LinuxCommands => Linux_man_cn}/mkbootdisk.md | 0 {LinuxCommands => Linux_man_cn}/mkdir.md | 2 +- {LinuxCommands => Linux_man_cn}/mke2fs.md | 0 {LinuxCommands => Linux_man_cn}/mkfs.md | 2 +- {LinuxCommands => Linux_man_cn}/mkfs.xfs.md | 0 {LinuxCommands => Linux_man_cn}/mkinitrd.md | 0 {LinuxCommands => Linux_man_cn}/mkisofs.md | 0 {LinuxCommands => Linux_man_cn}/mknod.md | 2 +- {LinuxCommands => Linux_man_cn}/mkswap.md | 2 +- {LinuxCommands => Linux_man_cn}/mktemp.md | 0 {LinuxCommands => Linux_man_cn}/modprobe.md | 0 {LinuxCommands => Linux_man_cn}/more.md | 2 +- {LinuxCommands => Linux_man_cn}/mount.md | 0 {LinuxCommands => Linux_man_cn}/mpstat.md | 0 {LinuxCommands => Linux_man_cn}/mtools.md | 0 {LinuxCommands => Linux_man_cn}/mv.md | 2 +- {LinuxCommands => Linux_man_cn}/mysql.md | 0 {LinuxCommands => Linux_man_cn}/mysqladmin.md | 0 {LinuxCommands => Linux_man_cn}/mysqldump.md | 0 .../mysqlimport.md | 0 {LinuxCommands => Linux_man_cn}/mysqlshow.md | 0 .../named-checkzone.md | 0 {LinuxCommands => Linux_man_cn}/nano.md | 2 +- {LinuxCommands => Linux_man_cn}/nc.md | 0 {LinuxCommands => Linux_man_cn}/ncftp.md | 0 {LinuxCommands => Linux_man_cn}/nethogs.md | 0 {LinuxCommands => Linux_man_cn}/netstat.md | 0 {LinuxCommands => Linux_man_cn}/newusers.md | 0 {LinuxCommands => Linux_man_cn}/nfsstat.md | 0 {LinuxCommands => Linux_man_cn}/ngrep.md | 0 {LinuxCommands => Linux_man_cn}/nice.md | 0 .../nisdomainname.md | 0 {LinuxCommands => Linux_man_cn}/nl.md | 2 +- {LinuxCommands => Linux_man_cn}/nm.md | 0 {LinuxCommands => Linux_man_cn}/nmap.md | 2 +- {LinuxCommands => Linux_man_cn}/nmcli.md | 0 {LinuxCommands => Linux_man_cn}/nohup.md | 0 {LinuxCommands => Linux_man_cn}/nologin.md | 0 {LinuxCommands => Linux_man_cn}/nslookup.md | 2 +- {LinuxCommands => Linux_man_cn}/ntpdate.md | 2 +- {LinuxCommands => Linux_man_cn}/ntsysv.md | 0 {LinuxCommands => Linux_man_cn}/objdump.md | 0 {LinuxCommands => Linux_man_cn}/od.md | 0 {LinuxCommands => Linux_man_cn}/openssl.md | 2 +- {LinuxCommands => Linux_man_cn}/parted.md | 2 +- {LinuxCommands => Linux_man_cn}/partprobe.md | 0 {LinuxCommands => Linux_man_cn}/passwd.md | 2 +- {LinuxCommands => Linux_man_cn}/paste.md | 0 {LinuxCommands => Linux_man_cn}/patch.md | 2 +- {LinuxCommands => Linux_man_cn}/pathchk.md | 0 {LinuxCommands => Linux_man_cn}/perl.md | 0 {LinuxCommands => Linux_man_cn}/pfctl.md | 0 {LinuxCommands => Linux_man_cn}/pgrep.md | 0 {LinuxCommands => Linux_man_cn}/php.md | 0 {LinuxCommands => Linux_man_cn}/pico.md | 0 {LinuxCommands => Linux_man_cn}/pidof.md | 0 {LinuxCommands => Linux_man_cn}/ping.md | 2 +- {LinuxCommands => Linux_man_cn}/pkill.md | 0 {LinuxCommands => Linux_man_cn}/pmap.md | 0 {LinuxCommands => Linux_man_cn}/popd.md | 0 {LinuxCommands => Linux_man_cn}/poweroff.md | 0 {LinuxCommands => Linux_man_cn}/ppp-off.md | 0 {LinuxCommands => Linux_man_cn}/pr.md | 0 {LinuxCommands => Linux_man_cn}/printf.md | 0 {LinuxCommands => Linux_man_cn}/protoize.md | 0 {LinuxCommands => Linux_man_cn}/ps.md | 208 +- {LinuxCommands => Linux_man_cn}/pssh.md | 0 {LinuxCommands => Linux_man_cn}/pstack.md | 0 {LinuxCommands => Linux_man_cn}/pstree.md | 116 +- {LinuxCommands => Linux_man_cn}/pushd.md | 0 {LinuxCommands => Linux_man_cn}/pv.md | 0 {LinuxCommands => Linux_man_cn}/pvchange.md | 0 {LinuxCommands => Linux_man_cn}/pvck.md | 0 {LinuxCommands => Linux_man_cn}/pvcreate.md | 0 {LinuxCommands => Linux_man_cn}/pvdisplay.md | 0 {LinuxCommands => Linux_man_cn}/pvremove.md | 0 {LinuxCommands => Linux_man_cn}/pvs.md | 0 {LinuxCommands => Linux_man_cn}/pvscan.md | 0 {LinuxCommands => Linux_man_cn}/pwck.md | 0 {LinuxCommands => Linux_man_cn}/pwconv.md | 0 {LinuxCommands => Linux_man_cn}/pwd.md | 2 +- {LinuxCommands => Linux_man_cn}/pwunconv.md | 0 {LinuxCommands => Linux_man_cn}/quota.md | 0 {LinuxCommands => Linux_man_cn}/quotacheck.md | 0 {LinuxCommands => Linux_man_cn}/quotaoff.md | 0 {LinuxCommands => Linux_man_cn}/quotaon.md | 0 {LinuxCommands => Linux_man_cn}/rcconf.md | 0 {LinuxCommands => Linux_man_cn}/rcp.md | 0 {LinuxCommands => Linux_man_cn}/read.md | 0 {LinuxCommands => Linux_man_cn}/readelf.md | 0 {LinuxCommands => Linux_man_cn}/readonly.md | 0 {LinuxCommands => Linux_man_cn}/reboot.md | 0 {LinuxCommands => Linux_man_cn}/reject.md | 0 {LinuxCommands => Linux_man_cn}/rename.md | 0 {LinuxCommands => Linux_man_cn}/renamemd.sh | 0 {LinuxCommands => Linux_man_cn}/renice.md | 2 +- {LinuxCommands => Linux_man_cn}/repquota.md | 0 {LinuxCommands => Linux_man_cn}/resize.md | 0 {LinuxCommands => Linux_man_cn}/restore.md | 0 {LinuxCommands => Linux_man_cn}/restorecon.md | 0 {LinuxCommands => Linux_man_cn}/rev.md | 0 {LinuxCommands => Linux_man_cn}/rexec.md | 0 {LinuxCommands => Linux_man_cn}/rlogin.md | 0 {LinuxCommands => Linux_man_cn}/rm.md | 2 +- {LinuxCommands => Linux_man_cn}/rmdir.md | 0 {LinuxCommands => Linux_man_cn}/rmmod.md | 0 {LinuxCommands => Linux_man_cn}/route.md | 0 {LinuxCommands => Linux_man_cn}/rpm.md | 2 +- {LinuxCommands => Linux_man_cn}/rpm2cpio.md | 0 {LinuxCommands => Linux_man_cn}/rpmbuild.md | 0 {LinuxCommands => Linux_man_cn}/rpmdb.md | 0 {LinuxCommands => Linux_man_cn}/rpmquery.md | 0 {LinuxCommands => Linux_man_cn}/rpmsign.md | 0 {LinuxCommands => Linux_man_cn}/rpmverify.md | 0 {LinuxCommands => Linux_man_cn}/rsh.md | 0 {LinuxCommands => Linux_man_cn}/rsync.md | 0 {LinuxCommands => Linux_man_cn}/runlevel.md | 0 {LinuxCommands => Linux_man_cn}/sar.md | 0 {LinuxCommands => Linux_man_cn}/scp.md | 0 {LinuxCommands => Linux_man_cn}/screen.md | 0 {LinuxCommands => Linux_man_cn}/sed.md | 0 {LinuxCommands => Linux_man_cn}/seinfo.md | 0 {LinuxCommands => Linux_man_cn}/semanage.md | 0 {LinuxCommands => Linux_man_cn}/sendmail.md | 2 +- {LinuxCommands => Linux_man_cn}/seq.md | 2 +- {LinuxCommands => Linux_man_cn}/service.md | 2 +- {LinuxCommands => Linux_man_cn}/sesearch.md | 0 {LinuxCommands => Linux_man_cn}/set.md | 2 +- {LinuxCommands => Linux_man_cn}/setfacl.md | 0 {LinuxCommands => Linux_man_cn}/setpci.md | 0 {LinuxCommands => Linux_man_cn}/setsebool.md | 0 .../sftp-server.md | 0 {LinuxCommands => Linux_man_cn}/sftp.md | 0 {LinuxCommands => Linux_man_cn}/sh.md | 2 +- {LinuxCommands => Linux_man_cn}/shopt.md | 0 {LinuxCommands => Linux_man_cn}/showmount.md | 0 {LinuxCommands => Linux_man_cn}/shutdown.md | 2 +- {LinuxCommands => Linux_man_cn}/skill.md | 0 {LinuxCommands => Linux_man_cn}/slabtop.md | 0 {LinuxCommands => Linux_man_cn}/sleep.md | 0 {LinuxCommands => Linux_man_cn}/slocate.md | 0 {LinuxCommands => Linux_man_cn}/smbclient.md | 0 {LinuxCommands => Linux_man_cn}/smbpasswd.md | 0 {LinuxCommands => Linux_man_cn}/sort.md | 0 {LinuxCommands => Linux_man_cn}/source.md | 0 .../speedtest-cli.md | 0 {LinuxCommands => Linux_man_cn}/spell.md | 0 {LinuxCommands => Linux_man_cn}/split.md | 0 {LinuxCommands => Linux_man_cn}/squid.md | 0 .../squidclient.md | 0 {LinuxCommands => Linux_man_cn}/ss.md | 0 {LinuxCommands => Linux_man_cn}/ssh-add.md | 2 +- {LinuxCommands => Linux_man_cn}/ssh-agent.md | 2 +- .../ssh-copy-id.md | 2 +- {LinuxCommands => Linux_man_cn}/ssh-keygen.md | 0 .../ssh-keyscan.md | 2 +- {LinuxCommands => Linux_man_cn}/ssh.md | 318 +- {LinuxCommands => Linux_man_cn}/sshd.md | 2 +- {LinuxCommands => Linux_man_cn}/startx.md | 0 {LinuxCommands => Linux_man_cn}/stat.md | 0 {LinuxCommands => Linux_man_cn}/strace.md | 0 {LinuxCommands => Linux_man_cn}/strings.md | 0 {LinuxCommands => Linux_man_cn}/stty.md | 0 {LinuxCommands => Linux_man_cn}/su.md | 2 +- {LinuxCommands => Linux_man_cn}/sudo.md | 2 +- {LinuxCommands => Linux_man_cn}/sum.md | 0 {LinuxCommands => Linux_man_cn}/swapoff.md | 0 {LinuxCommands => Linux_man_cn}/swapon.md | 2 +- {LinuxCommands => Linux_man_cn}/sync.md | 2 +- {LinuxCommands => Linux_man_cn}/sysctl.md | 0 {LinuxCommands => Linux_man_cn}/syslog.md | 0 {LinuxCommands => Linux_man_cn}/systemctl.md | 0 {LinuxCommands => Linux_man_cn}/systool.md | 0 {LinuxCommands => Linux_man_cn}/tac.md | 2 +- {LinuxCommands => Linux_man_cn}/tail.md | 94 +- {LinuxCommands => Linux_man_cn}/tailf.md | 0 {LinuxCommands => Linux_man_cn}/talk.md | 0 {LinuxCommands => Linux_man_cn}/tar.md | 454 +-- {LinuxCommands => Linux_man_cn}/tcpdump.md | 330 +-- {LinuxCommands => Linux_man_cn}/tcpreplay.md | 2 +- {LinuxCommands => Linux_man_cn}/tee.md | 0 {LinuxCommands => Linux_man_cn}/telint.md | 0 {LinuxCommands => Linux_man_cn}/telnet.md | 274 +- {LinuxCommands => Linux_man_cn}/tempfile.md | 0 {LinuxCommands => Linux_man_cn}/test.md | 0 {LinuxCommands => Linux_man_cn}/tftp.md | 0 {LinuxCommands => Linux_man_cn}/time.md | 2 +- {LinuxCommands => Linux_man_cn}/tload.md | 0 {LinuxCommands => Linux_man_cn}/top.md | 0 {LinuxCommands => Linux_man_cn}/touch.md | 2 +- {LinuxCommands => Linux_man_cn}/tput.md | 0 {LinuxCommands => Linux_man_cn}/tr.md | 0 {LinuxCommands => Linux_man_cn}/tracepath.md | 0 {LinuxCommands => Linux_man_cn}/traceroute.md | 0 {LinuxCommands => Linux_man_cn}/trap.md | 0 {LinuxCommands => Linux_man_cn}/tree.md | 0 {LinuxCommands => Linux_man_cn}/tty.md | 0 {LinuxCommands => Linux_man_cn}/tune2fs.md | 0 {LinuxCommands => Linux_man_cn}/type.md | 0 {LinuxCommands => Linux_man_cn}/ulimit.md | 2 +- {LinuxCommands => Linux_man_cn}/umask.md | 0 {LinuxCommands => Linux_man_cn}/umount.md | 2 +- {LinuxCommands => Linux_man_cn}/unalias.md | 0 {LinuxCommands => Linux_man_cn}/uname.md | 2 +- {LinuxCommands => Linux_man_cn}/unarj.md | 0 {LinuxCommands => Linux_man_cn}/uncompress.md | 0 {LinuxCommands => Linux_man_cn}/unexpand.md | 0 {LinuxCommands => Linux_man_cn}/uniq.md | 2 +- {LinuxCommands => Linux_man_cn}/unlink.md | 0 {LinuxCommands => Linux_man_cn}/unprotoize.md | 0 {LinuxCommands => Linux_man_cn}/unset.md | 0 {LinuxCommands => Linux_man_cn}/unzip.md | 2 +- {LinuxCommands => Linux_man_cn}/updatedb.md | 0 {LinuxCommands => Linux_man_cn}/uptime.md | 2 +- {LinuxCommands => Linux_man_cn}/useradd.md | 2 +- {LinuxCommands => Linux_man_cn}/userdel.md | 2 +- {LinuxCommands => Linux_man_cn}/usermod.md | 2 +- {LinuxCommands => Linux_man_cn}/usernetctl.md | 0 {LinuxCommands => Linux_man_cn}/users.md | 2 +- {LinuxCommands => Linux_man_cn}/uucico.md | 0 {LinuxCommands => Linux_man_cn}/uupick.md | 0 {LinuxCommands => Linux_man_cn}/vdfuse.md | 0 {LinuxCommands => Linux_man_cn}/vgchange.md | 0 {LinuxCommands => Linux_man_cn}/vgconvert.md | 0 {LinuxCommands => Linux_man_cn}/vgcreate.md | 0 {LinuxCommands => Linux_man_cn}/vgdisplay.md | 0 {LinuxCommands => Linux_man_cn}/vgextend.md | 0 {LinuxCommands => Linux_man_cn}/vgreduce.md | 0 {LinuxCommands => Linux_man_cn}/vgremove.md | 0 {LinuxCommands => Linux_man_cn}/vgrename.md | 0 {LinuxCommands => Linux_man_cn}/vgscan.md | 0 {LinuxCommands => Linux_man_cn}/vi.md | 2 +- {LinuxCommands => Linux_man_cn}/vmstat.md | 0 {LinuxCommands => Linux_man_cn}/volname.md | 0 {LinuxCommands => Linux_man_cn}/w.md | 2 +- {LinuxCommands => Linux_man_cn}/wait.md | 0 {LinuxCommands => Linux_man_cn}/wall.md | 0 {LinuxCommands => Linux_man_cn}/watch.md | 98 +- {LinuxCommands => Linux_man_cn}/wc.md | 132 +- {LinuxCommands => Linux_man_cn}/wget.md | 0 {LinuxCommands => Linux_man_cn}/whatis.md | 2 +- {LinuxCommands => Linux_man_cn}/whereis.md | 2 +- {LinuxCommands => Linux_man_cn}/which.md | 102 +- {LinuxCommands => Linux_man_cn}/who.md | 2 +- {LinuxCommands => Linux_man_cn}/whoami.md | 2 +- {LinuxCommands => Linux_man_cn}/write.md | 0 {LinuxCommands => Linux_man_cn}/xargs.md | 434 +-- {LinuxCommands => Linux_man_cn}/xauth.md | 0 {LinuxCommands => Linux_man_cn}/xclip.md | 0 {LinuxCommands => Linux_man_cn}/xfs_admin.md | 0 {LinuxCommands => Linux_man_cn}/xfs_info.md | 0 {LinuxCommands => Linux_man_cn}/xfs_repair.md | 0 {LinuxCommands => Linux_man_cn}/xfsdump.md | 0 {LinuxCommands => Linux_man_cn}/xfsrestore.md | 0 {LinuxCommands => Linux_man_cn}/xhost.md | 0 {LinuxCommands => Linux_man_cn}/xinit.md | 0 {LinuxCommands => Linux_man_cn}/xlsatoms.md | 0 {LinuxCommands => Linux_man_cn}/xlsclients.md | 0 {LinuxCommands => Linux_man_cn}/xlsfonts.md | 0 {LinuxCommands => Linux_man_cn}/xset.md | 0 {LinuxCommands => Linux_man_cn}/xz.md | 0 {LinuxCommands => Linux_man_cn}/yes.md | 0 .../ypdomainname.md | 0 {LinuxCommands => Linux_man_cn}/yum.md | 212 +- {LinuxCommands => Linux_man_cn}/zcat.md | 2 +- {LinuxCommands => Linux_man_cn}/zfore.md | 0 {LinuxCommands => Linux_man_cn}/zip.md | 188 +- {LinuxCommands => Linux_man_cn}/zipinfo.md | 2 +- {LinuxCommands => Linux_man_cn}/zipsplit.md | 0 {LinuxCommands => Linux_man_cn}/znew.md | 0 559 files changed, 5745 insertions(+), 5896 deletions(-) delete mode 100755 LinuxCommands/git.md rename {LinuxCommands => Linux_man_cn}/ab.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/accept.md (100%) rename {LinuxCommands => Linux_man_cn}/alias.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/apachectl.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/apropos.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/apt-get.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/apt-key.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/apt-sortpkgs.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/aptitude.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ar.md (100%) rename {LinuxCommands => Linux_man_cn}/arch.md (100%) rename {LinuxCommands => Linux_man_cn}/arj.md (100%) rename {LinuxCommands => Linux_man_cn}/arp.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/arpd.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/arping.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/arptables.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/arpwatch.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/as.md (100%) rename {LinuxCommands => Linux_man_cn}/at.md (100%) rename {LinuxCommands => Linux_man_cn}/atop.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/atq.md (100%) rename {LinuxCommands => Linux_man_cn}/atrm.md (100%) rename {LinuxCommands => Linux_man_cn}/awk.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/axel.md (100%) rename {LinuxCommands => Linux_man_cn}/badblocks.md (100%) rename {LinuxCommands => Linux_man_cn}/basename.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/batch.md (100%) rename {LinuxCommands => Linux_man_cn}/bc.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/bg.md (100%) rename {LinuxCommands => Linux_man_cn}/bind.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/blkid.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/blockdev.md (100%) rename {LinuxCommands => Linux_man_cn}/bmodinfo.md (100%) rename {LinuxCommands => Linux_man_cn}/builtin.md (100%) rename {LinuxCommands => Linux_man_cn}/bunzip2.md (100%) rename {LinuxCommands => Linux_man_cn}/bye.md (100%) rename {LinuxCommands => Linux_man_cn}/bzcat.md (100%) rename {LinuxCommands => Linux_man_cn}/bzcmp.md (100%) rename {LinuxCommands => Linux_man_cn}/bzdiff.md (100%) rename {LinuxCommands => Linux_man_cn}/bzgrep.md (100%) rename {LinuxCommands => Linux_man_cn}/bzip2.md (100%) rename {LinuxCommands => Linux_man_cn}/bzip2recover.md (100%) rename {LinuxCommands => Linux_man_cn}/bzless.md (100%) rename {LinuxCommands => Linux_man_cn}/bzmore.md (100%) rename {LinuxCommands => Linux_man_cn}/cal.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/cancel.md (100%) rename {LinuxCommands => Linux_man_cn}/cat.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/cd.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/cdrecord.md (100%) rename {LinuxCommands => Linux_man_cn}/chage.md (100%) rename {LinuxCommands => Linux_man_cn}/chattr.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/chcon.md (100%) rename {LinuxCommands => Linux_man_cn}/chfn.md (100%) rename {LinuxCommands => Linux_man_cn}/chgrp.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/chkconfig.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/chmod.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/chown.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/chpasswd.md (100%) rename {LinuxCommands => Linux_man_cn}/chroot.md (100%) rename {LinuxCommands => Linux_man_cn}/chsh.md (100%) rename {LinuxCommands => Linux_man_cn}/cksum.md (100%) rename {LinuxCommands => Linux_man_cn}/clear.md (94%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/clock.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/clockdiff.md (100%) rename {LinuxCommands => Linux_man_cn}/cmp.md (100%) rename {LinuxCommands => Linux_man_cn}/col.md (100%) rename {LinuxCommands => Linux_man_cn}/colrm.md (100%) rename {LinuxCommands => Linux_man_cn}/comm.md (100%) rename {LinuxCommands => Linux_man_cn}/command.md (100%) rename {LinuxCommands => Linux_man_cn}/compress.md (100%) rename {LinuxCommands => Linux_man_cn}/consoletype.md (100%) rename {LinuxCommands => Linux_man_cn}/convertquota.md (100%) rename {LinuxCommands => Linux_man_cn}/cp.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/cpio.md (100%) rename {LinuxCommands => Linux_man_cn}/crontab.md (100%) rename {LinuxCommands => Linux_man_cn}/csplit.md (100%) rename {LinuxCommands => Linux_man_cn}/cu.md (100%) rename {LinuxCommands => Linux_man_cn}/cupsdisable.md (100%) rename {LinuxCommands => Linux_man_cn}/cupsenable.md (100%) rename {LinuxCommands => Linux_man_cn}/curl.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/cut.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/date.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dd.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/declare.md (100%) rename {LinuxCommands => Linux_man_cn}/depmod.md (100%) rename {LinuxCommands => Linux_man_cn}/df.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dhclient.md (100%) rename {LinuxCommands => Linux_man_cn}/dhcpd.md (100%) rename {LinuxCommands => Linux_man_cn}/dhcrelay.md (100%) rename {LinuxCommands => Linux_man_cn}/diff.md (100%) rename {LinuxCommands => Linux_man_cn}/diff3.md (100%) rename {LinuxCommands => Linux_man_cn}/diffstat.md (100%) rename {LinuxCommands => Linux_man_cn}/dig.md (100%) rename {LinuxCommands => Linux_man_cn}/dircolors.md (100%) rename {LinuxCommands => Linux_man_cn}/dirname.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dirs.md (100%) rename {LinuxCommands => Linux_man_cn}/dmesg.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dmidecode.md (100%) rename {LinuxCommands => Linux_man_cn}/dnf.md (100%) rename {LinuxCommands => Linux_man_cn}/dnsdomainname.md (100%) rename {LinuxCommands => Linux_man_cn}/domainname.md (100%) rename {LinuxCommands => Linux_man_cn}/dos2unix.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-deb.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-divert.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-preconfigure.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-query.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-reconfigure.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-split.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-statoverride.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg-trigger.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dpkg.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dris.md (100%) rename {LinuxCommands => Linux_man_cn}/dstat.md (100%) rename {LinuxCommands => Linux_man_cn}/du.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dump.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/dumpe2fs.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/e2fsck.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/e2label.md (100%) rename {LinuxCommands => Linux_man_cn}/echo.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ed.md (100%) rename {LinuxCommands => Linux_man_cn}/edquota.md (100%) rename {LinuxCommands => Linux_man_cn}/egrep.md (100%) rename {LinuxCommands => Linux_man_cn}/eject.md (100%) rename {LinuxCommands => Linux_man_cn}/elinks.md (100%) rename {LinuxCommands => Linux_man_cn}/elm.md (100%) rename {LinuxCommands => Linux_man_cn}/emacs.md (100%) rename {LinuxCommands => Linux_man_cn}/enable.md (100%) rename {LinuxCommands => Linux_man_cn}/env.md (100%) rename {LinuxCommands => Linux_man_cn}/ethtool.md (100%) rename {LinuxCommands => Linux_man_cn}/ex.md (100%) rename {LinuxCommands => Linux_man_cn}/exec.md (100%) rename {LinuxCommands => Linux_man_cn}/exit.md (100%) rename {LinuxCommands => Linux_man_cn}/expand.md (100%) rename {LinuxCommands => Linux_man_cn}/export.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/exportfs.md (100%) rename {LinuxCommands => Linux_man_cn}/expr.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/fc.md (100%) rename {LinuxCommands => Linux_man_cn}/fdisk.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/fg.md (100%) rename {LinuxCommands => Linux_man_cn}/fgrep.md (100%) rename {LinuxCommands => Linux_man_cn}/file.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/find.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/findfs.md (100%) rename {LinuxCommands => Linux_man_cn}/finger.md (100%) rename {LinuxCommands => Linux_man_cn}/firewall-cmd.md (100%) rename {LinuxCommands => Linux_man_cn}/fmt.md (100%) rename {LinuxCommands => Linux_man_cn}/fold.md (100%) rename {LinuxCommands => Linux_man_cn}/free.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/fsck.ext4.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/fsck.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ftp.md (100%) rename {LinuxCommands => Linux_man_cn}/ftpcount.md (100%) rename {LinuxCommands => Linux_man_cn}/ftpshut.md (100%) rename {LinuxCommands => Linux_man_cn}/ftptop.md (100%) rename {LinuxCommands => Linux_man_cn}/ftpwho.md (100%) rename {LinuxCommands => Linux_man_cn}/fuser.md (100%) rename {LinuxCommands => Linux_man_cn}/gcc.md (100%) rename {LinuxCommands => Linux_man_cn}/gcov.md (100%) rename {LinuxCommands => Linux_man_cn}/gdb.md (100%) rename {LinuxCommands => Linux_man_cn}/get_module.md (100%) rename {LinuxCommands => Linux_man_cn}/getenforce.md (100%) rename {LinuxCommands => Linux_man_cn}/getsebool.md (100%) rename {LinuxCommands => Linux_man_cn}/gpasswd.md (100%) rename {LinuxCommands => Linux_man_cn}/gpm.md (100%) rename {LinuxCommands => Linux_man_cn}/grep.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/groupadd.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/groupdel.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/groupmod.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/groups.md (100%) rename {LinuxCommands => Linux_man_cn}/grpck.md (100%) rename {LinuxCommands => Linux_man_cn}/grpconv.md (100%) rename {LinuxCommands => Linux_man_cn}/grpunconv.md (100%) rename {LinuxCommands => Linux_man_cn}/grub.md (100%) rename {LinuxCommands => Linux_man_cn}/gunzip.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/gzexe.md (100%) rename {LinuxCommands => Linux_man_cn}/gzip.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/halt.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/hdparm.md (100%) rename {LinuxCommands => Linux_man_cn}/head.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/help.md (100%) rename {LinuxCommands => Linux_man_cn}/hexdump.md (100%) rename {LinuxCommands => Linux_man_cn}/history.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/host.md (100%) rename {LinuxCommands => Linux_man_cn}/hostid.md (100%) rename {LinuxCommands => Linux_man_cn}/hostname.md (100%) rename {LinuxCommands => Linux_man_cn}/hping3.md (100%) rename {LinuxCommands => Linux_man_cn}/htdigest.md (100%) rename {LinuxCommands => Linux_man_cn}/htop.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/htpasswd.md (100%) rename {LinuxCommands => Linux_man_cn}/hwclock.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iconv.md (100%) rename {LinuxCommands => Linux_man_cn}/id.md (100%) rename {LinuxCommands => Linux_man_cn}/ifcfg.md (100%) rename {LinuxCommands => Linux_man_cn}/ifconfig.md (100%) rename {LinuxCommands => Linux_man_cn}/ifdown.md (100%) rename {LinuxCommands => Linux_man_cn}/ifstat.md (100%) rename {LinuxCommands => Linux_man_cn}/iftop.md (100%) rename {LinuxCommands => Linux_man_cn}/ifup.md (100%) rename {LinuxCommands => Linux_man_cn}/indent.md (100%) rename {LinuxCommands => Linux_man_cn}/info.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/init.md (100%) rename {LinuxCommands => Linux_man_cn}/inotifywait.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/insmod.md (100%) rename {LinuxCommands => Linux_man_cn}/install.md (100%) rename {LinuxCommands => Linux_man_cn}/iostat.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iotop.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ip.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ip6tables-restore.md (95%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ip6tables-save.md (95%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ip6tables.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ipcalc.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ipcrm.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ipcs.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iperf.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iptables-restore.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iptables-save.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iptables.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iptraf.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/iptstate.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ispell.md (100%) rename {LinuxCommands => Linux_man_cn}/jed.md (100%) rename {LinuxCommands => Linux_man_cn}/jobs.md (100%) rename {LinuxCommands => Linux_man_cn}/joe.md (100%) rename {LinuxCommands => Linux_man_cn}/join.md (100%) rename {LinuxCommands => Linux_man_cn}/jwhois.md (100%) rename {LinuxCommands => Linux_man_cn}/kernelversion.md (100%) rename {LinuxCommands => Linux_man_cn}/kexec.md (100%) rename {LinuxCommands => Linux_man_cn}/kill.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/killall.md (100%) rename {LinuxCommands => Linux_man_cn}/last.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/lastb.md (100%) rename {LinuxCommands => Linux_man_cn}/lastlog.md (100%) rename {LinuxCommands => Linux_man_cn}/ld.md (100%) rename {LinuxCommands => Linux_man_cn}/ldconfig.md (100%) rename {LinuxCommands => Linux_man_cn}/ldd.md (100%) rename {LinuxCommands => Linux_man_cn}/less.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/let.md (100%) rename {LinuxCommands => Linux_man_cn}/lftp.md (100%) rename {LinuxCommands => Linux_man_cn}/lftpget.md (100%) rename {LinuxCommands => Linux_man_cn}/lha.md (100%) rename {LinuxCommands => Linux_man_cn}/lilo.md (100%) rename {LinuxCommands => Linux_man_cn}/ln.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/lnstat.md (100%) rename {LinuxCommands => Linux_man_cn}/locale.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/locate.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/logger.md (100%) rename {LinuxCommands => Linux_man_cn}/login.md (100%) rename {LinuxCommands => Linux_man_cn}/logname.md (100%) rename {LinuxCommands => Linux_man_cn}/logout.md (100%) rename {LinuxCommands => Linux_man_cn}/logrotate.md (100%) rename {LinuxCommands => Linux_man_cn}/logsave.md (100%) rename {LinuxCommands => Linux_man_cn}/logwatch.md (100%) rename {LinuxCommands => Linux_man_cn}/look.md (100%) rename {LinuxCommands => Linux_man_cn}/losetup.md (100%) rename {LinuxCommands => Linux_man_cn}/lp.md (100%) rename {LinuxCommands => Linux_man_cn}/lpadmin.md (100%) rename {LinuxCommands => Linux_man_cn}/lpc.md (100%) rename {LinuxCommands => Linux_man_cn}/lpq.md (100%) rename {LinuxCommands => Linux_man_cn}/lpr.md (100%) rename {LinuxCommands => Linux_man_cn}/lprm.md (100%) rename {LinuxCommands => Linux_man_cn}/lpstat.md (100%) rename {LinuxCommands => Linux_man_cn}/ls.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/lsattr.md (100%) rename {LinuxCommands => Linux_man_cn}/lsb_release.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/lsblk.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/lscpu.md (100%) rename {LinuxCommands => Linux_man_cn}/lsmod.md (100%) rename {LinuxCommands => Linux_man_cn}/lsof.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/lspci.md (100%) rename {LinuxCommands => Linux_man_cn}/lsusb.md (100%) rename {LinuxCommands => Linux_man_cn}/ltrace.md (100%) rename {LinuxCommands => Linux_man_cn}/lvcreate.md (100%) rename {LinuxCommands => Linux_man_cn}/lvdisplay.md (100%) rename {LinuxCommands => Linux_man_cn}/lvextend.md (100%) rename {LinuxCommands => Linux_man_cn}/lvreduce.md (100%) rename {LinuxCommands => Linux_man_cn}/lvremove.md (100%) rename {LinuxCommands => Linux_man_cn}/lvresize.md (100%) rename {LinuxCommands => Linux_man_cn}/lvscan.md (100%) rename {LinuxCommands => Linux_man_cn}/lynx.md (100%) rename {LinuxCommands => Linux_man_cn}/mail.md (100%) rename {LinuxCommands => Linux_man_cn}/mailq.md (100%) rename {LinuxCommands => Linux_man_cn}/mailstat.md (100%) rename {LinuxCommands => Linux_man_cn}/make.md (100%) rename {LinuxCommands => Linux_man_cn}/man.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/md5sum.md (100%) rename {LinuxCommands => Linux_man_cn}/mesg.md (100%) rename {LinuxCommands => Linux_man_cn}/mii-tool.md (100%) rename {LinuxCommands => Linux_man_cn}/mkbootdisk.md (100%) rename {LinuxCommands => Linux_man_cn}/mkdir.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mke2fs.md (100%) rename {LinuxCommands => Linux_man_cn}/mkfs.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mkfs.xfs.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mkinitrd.md (100%) rename {LinuxCommands => Linux_man_cn}/mkisofs.md (100%) rename {LinuxCommands => Linux_man_cn}/mknod.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mkswap.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mktemp.md (100%) rename {LinuxCommands => Linux_man_cn}/modprobe.md (100%) rename {LinuxCommands => Linux_man_cn}/more.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mount.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mpstat.md (100%) rename {LinuxCommands => Linux_man_cn}/mtools.md (100%) rename {LinuxCommands => Linux_man_cn}/mv.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/mysql.md (100%) rename {LinuxCommands => Linux_man_cn}/mysqladmin.md (100%) rename {LinuxCommands => Linux_man_cn}/mysqldump.md (100%) rename {LinuxCommands => Linux_man_cn}/mysqlimport.md (100%) rename {LinuxCommands => Linux_man_cn}/mysqlshow.md (100%) rename {LinuxCommands => Linux_man_cn}/named-checkzone.md (100%) rename {LinuxCommands => Linux_man_cn}/nano.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/nc.md (100%) rename {LinuxCommands => Linux_man_cn}/ncftp.md (100%) rename {LinuxCommands => Linux_man_cn}/nethogs.md (100%) rename {LinuxCommands => Linux_man_cn}/netstat.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/newusers.md (100%) rename {LinuxCommands => Linux_man_cn}/nfsstat.md (100%) rename {LinuxCommands => Linux_man_cn}/ngrep.md (100%) rename {LinuxCommands => Linux_man_cn}/nice.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/nisdomainname.md (100%) rename {LinuxCommands => Linux_man_cn}/nl.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/nm.md (100%) rename {LinuxCommands => Linux_man_cn}/nmap.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/nmcli.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/nohup.md (100%) rename {LinuxCommands => Linux_man_cn}/nologin.md (100%) rename {LinuxCommands => Linux_man_cn}/nslookup.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ntpdate.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ntsysv.md (100%) rename {LinuxCommands => Linux_man_cn}/objdump.md (100%) rename {LinuxCommands => Linux_man_cn}/od.md (100%) rename {LinuxCommands => Linux_man_cn}/openssl.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/parted.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/partprobe.md (100%) rename {LinuxCommands => Linux_man_cn}/passwd.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/paste.md (100%) rename {LinuxCommands => Linux_man_cn}/patch.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/pathchk.md (100%) rename {LinuxCommands => Linux_man_cn}/perl.md (100%) rename {LinuxCommands => Linux_man_cn}/pfctl.md (100%) rename {LinuxCommands => Linux_man_cn}/pgrep.md (100%) rename {LinuxCommands => Linux_man_cn}/php.md (100%) rename {LinuxCommands => Linux_man_cn}/pico.md (100%) rename {LinuxCommands => Linux_man_cn}/pidof.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ping.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/pkill.md (100%) rename {LinuxCommands => Linux_man_cn}/pmap.md (100%) rename {LinuxCommands => Linux_man_cn}/popd.md (100%) rename {LinuxCommands => Linux_man_cn}/poweroff.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ppp-off.md (100%) rename {LinuxCommands => Linux_man_cn}/pr.md (100%) rename {LinuxCommands => Linux_man_cn}/printf.md (100%) rename {LinuxCommands => Linux_man_cn}/protoize.md (100%) rename {LinuxCommands => Linux_man_cn}/ps.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/pssh.md (100%) rename {LinuxCommands => Linux_man_cn}/pstack.md (100%) rename {LinuxCommands => Linux_man_cn}/pstree.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/pushd.md (100%) rename {LinuxCommands => Linux_man_cn}/pv.md (100%) rename {LinuxCommands => Linux_man_cn}/pvchange.md (100%) rename {LinuxCommands => Linux_man_cn}/pvck.md (100%) rename {LinuxCommands => Linux_man_cn}/pvcreate.md (100%) rename {LinuxCommands => Linux_man_cn}/pvdisplay.md (100%) rename {LinuxCommands => Linux_man_cn}/pvremove.md (100%) rename {LinuxCommands => Linux_man_cn}/pvs.md (100%) rename {LinuxCommands => Linux_man_cn}/pvscan.md (100%) rename {LinuxCommands => Linux_man_cn}/pwck.md (100%) rename {LinuxCommands => Linux_man_cn}/pwconv.md (100%) rename {LinuxCommands => Linux_man_cn}/pwd.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/pwunconv.md (100%) rename {LinuxCommands => Linux_man_cn}/quota.md (100%) rename {LinuxCommands => Linux_man_cn}/quotacheck.md (100%) rename {LinuxCommands => Linux_man_cn}/quotaoff.md (100%) rename {LinuxCommands => Linux_man_cn}/quotaon.md (100%) rename {LinuxCommands => Linux_man_cn}/rcconf.md (100%) rename {LinuxCommands => Linux_man_cn}/rcp.md (100%) rename {LinuxCommands => Linux_man_cn}/read.md (100%) rename {LinuxCommands => Linux_man_cn}/readelf.md (100%) rename {LinuxCommands => Linux_man_cn}/readonly.md (100%) rename {LinuxCommands => Linux_man_cn}/reboot.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/reject.md (100%) rename {LinuxCommands => Linux_man_cn}/rename.md (100%) rename {LinuxCommands => Linux_man_cn}/renamemd.sh (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/renice.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/repquota.md (100%) rename {LinuxCommands => Linux_man_cn}/resize.md (100%) rename {LinuxCommands => Linux_man_cn}/restore.md (100%) rename {LinuxCommands => Linux_man_cn}/restorecon.md (100%) rename {LinuxCommands => Linux_man_cn}/rev.md (100%) rename {LinuxCommands => Linux_man_cn}/rexec.md (100%) rename {LinuxCommands => Linux_man_cn}/rlogin.md (100%) rename {LinuxCommands => Linux_man_cn}/rm.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/rmdir.md (100%) rename {LinuxCommands => Linux_man_cn}/rmmod.md (100%) rename {LinuxCommands => Linux_man_cn}/route.md (100%) rename {LinuxCommands => Linux_man_cn}/rpm.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/rpm2cpio.md (100%) rename {LinuxCommands => Linux_man_cn}/rpmbuild.md (100%) rename {LinuxCommands => Linux_man_cn}/rpmdb.md (100%) rename {LinuxCommands => Linux_man_cn}/rpmquery.md (100%) rename {LinuxCommands => Linux_man_cn}/rpmsign.md (100%) rename {LinuxCommands => Linux_man_cn}/rpmverify.md (100%) rename {LinuxCommands => Linux_man_cn}/rsh.md (100%) rename {LinuxCommands => Linux_man_cn}/rsync.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/runlevel.md (100%) rename {LinuxCommands => Linux_man_cn}/sar.md (100%) rename {LinuxCommands => Linux_man_cn}/scp.md (100%) rename {LinuxCommands => Linux_man_cn}/screen.md (100%) rename {LinuxCommands => Linux_man_cn}/sed.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/seinfo.md (100%) rename {LinuxCommands => Linux_man_cn}/semanage.md (100%) rename {LinuxCommands => Linux_man_cn}/sendmail.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/seq.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/service.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/sesearch.md (100%) rename {LinuxCommands => Linux_man_cn}/set.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/setfacl.md (100%) rename {LinuxCommands => Linux_man_cn}/setpci.md (100%) rename {LinuxCommands => Linux_man_cn}/setsebool.md (100%) rename {LinuxCommands => Linux_man_cn}/sftp-server.md (100%) rename {LinuxCommands => Linux_man_cn}/sftp.md (100%) rename {LinuxCommands => Linux_man_cn}/sh.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/shopt.md (100%) rename {LinuxCommands => Linux_man_cn}/showmount.md (100%) rename {LinuxCommands => Linux_man_cn}/shutdown.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/skill.md (100%) rename {LinuxCommands => Linux_man_cn}/slabtop.md (100%) rename {LinuxCommands => Linux_man_cn}/sleep.md (100%) rename {LinuxCommands => Linux_man_cn}/slocate.md (100%) rename {LinuxCommands => Linux_man_cn}/smbclient.md (100%) rename {LinuxCommands => Linux_man_cn}/smbpasswd.md (100%) rename {LinuxCommands => Linux_man_cn}/sort.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/source.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/speedtest-cli.md (100%) rename {LinuxCommands => Linux_man_cn}/spell.md (100%) rename {LinuxCommands => Linux_man_cn}/split.md (100%) rename {LinuxCommands => Linux_man_cn}/squid.md (100%) rename {LinuxCommands => Linux_man_cn}/squidclient.md (100%) rename {LinuxCommands => Linux_man_cn}/ss.md (100%) rename {LinuxCommands => Linux_man_cn}/ssh-add.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ssh-agent.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ssh-copy-id.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ssh-keygen.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ssh-keyscan.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/ssh.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/sshd.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/startx.md (100%) rename {LinuxCommands => Linux_man_cn}/stat.md (100%) rename {LinuxCommands => Linux_man_cn}/strace.md (100%) rename {LinuxCommands => Linux_man_cn}/strings.md (100%) rename {LinuxCommands => Linux_man_cn}/stty.md (100%) rename {LinuxCommands => Linux_man_cn}/su.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/sudo.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/sum.md (100%) rename {LinuxCommands => Linux_man_cn}/swapoff.md (100%) rename {LinuxCommands => Linux_man_cn}/swapon.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/sync.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/sysctl.md (100%) rename {LinuxCommands => Linux_man_cn}/syslog.md (100%) rename {LinuxCommands => Linux_man_cn}/systemctl.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/systool.md (100%) rename {LinuxCommands => Linux_man_cn}/tac.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tail.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tailf.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/talk.md (100%) rename {LinuxCommands => Linux_man_cn}/tar.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tcpdump.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tcpreplay.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tee.md (100%) rename {LinuxCommands => Linux_man_cn}/telint.md (100%) rename {LinuxCommands => Linux_man_cn}/telnet.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tempfile.md (100%) rename {LinuxCommands => Linux_man_cn}/test.md (100%) rename {LinuxCommands => Linux_man_cn}/tftp.md (100%) rename {LinuxCommands => Linux_man_cn}/time.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tload.md (100%) rename {LinuxCommands => Linux_man_cn}/top.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/touch.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/tput.md (100%) rename {LinuxCommands => Linux_man_cn}/tr.md (100%) rename {LinuxCommands => Linux_man_cn}/tracepath.md (100%) rename {LinuxCommands => Linux_man_cn}/traceroute.md (100%) rename {LinuxCommands => Linux_man_cn}/trap.md (100%) rename {LinuxCommands => Linux_man_cn}/tree.md (100%) rename {LinuxCommands => Linux_man_cn}/tty.md (100%) rename {LinuxCommands => Linux_man_cn}/tune2fs.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/type.md (100%) rename {LinuxCommands => Linux_man_cn}/ulimit.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/umask.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/umount.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/unalias.md (100%) rename {LinuxCommands => Linux_man_cn}/uname.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/unarj.md (100%) rename {LinuxCommands => Linux_man_cn}/uncompress.md (100%) rename {LinuxCommands => Linux_man_cn}/unexpand.md (100%) rename {LinuxCommands => Linux_man_cn}/uniq.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/unlink.md (100%) rename {LinuxCommands => Linux_man_cn}/unprotoize.md (100%) rename {LinuxCommands => Linux_man_cn}/unset.md (100%) rename {LinuxCommands => Linux_man_cn}/unzip.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/updatedb.md (100%) rename {LinuxCommands => Linux_man_cn}/uptime.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/useradd.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/userdel.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/usermod.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/usernetctl.md (100%) rename {LinuxCommands => Linux_man_cn}/users.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/uucico.md (100%) rename {LinuxCommands => Linux_man_cn}/uupick.md (100%) rename {LinuxCommands => Linux_man_cn}/vdfuse.md (100%) rename {LinuxCommands => Linux_man_cn}/vgchange.md (100%) rename {LinuxCommands => Linux_man_cn}/vgconvert.md (100%) rename {LinuxCommands => Linux_man_cn}/vgcreate.md (100%) rename {LinuxCommands => Linux_man_cn}/vgdisplay.md (100%) rename {LinuxCommands => Linux_man_cn}/vgextend.md (100%) rename {LinuxCommands => Linux_man_cn}/vgreduce.md (100%) rename {LinuxCommands => Linux_man_cn}/vgremove.md (100%) rename {LinuxCommands => Linux_man_cn}/vgrename.md (100%) rename {LinuxCommands => Linux_man_cn}/vgscan.md (100%) rename {LinuxCommands => Linux_man_cn}/vi.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/vmstat.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/volname.md (100%) rename {LinuxCommands => Linux_man_cn}/w.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/wait.md (100%) rename {LinuxCommands => Linux_man_cn}/wall.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/watch.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/wc.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/wget.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/whatis.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/whereis.md (99%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/which.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/who.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/whoami.md (95%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/write.md (100%) rename {LinuxCommands => Linux_man_cn}/xargs.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/xauth.md (100%) rename {LinuxCommands => Linux_man_cn}/xclip.md (100%) rename {LinuxCommands => Linux_man_cn}/xfs_admin.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/xfs_info.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/xfs_repair.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/xfsdump.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/xfsrestore.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/xhost.md (100%) rename {LinuxCommands => Linux_man_cn}/xinit.md (100%) rename {LinuxCommands => Linux_man_cn}/xlsatoms.md (100%) rename {LinuxCommands => Linux_man_cn}/xlsclients.md (100%) rename {LinuxCommands => Linux_man_cn}/xlsfonts.md (100%) rename {LinuxCommands => Linux_man_cn}/xset.md (100%) rename {LinuxCommands => Linux_man_cn}/xz.md (100%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/yes.md (100%) rename {LinuxCommands => Linux_man_cn}/ypdomainname.md (100%) rename {LinuxCommands => Linux_man_cn}/yum.md (96%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/zcat.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/zfore.md (100%) rename {LinuxCommands => Linux_man_cn}/zip.md (97%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/zipinfo.md (98%) mode change 100755 => 100644 rename {LinuxCommands => Linux_man_cn}/zipsplit.md (100%) rename {LinuxCommands => Linux_man_cn}/znew.md (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 25bc26f..0495abd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,40 +1,6 @@ { - "workbench.startupEditor": "none", - "workbench.iconTheme": "vscode-icons", - "workbench.colorTheme": "Monokai", - "files.autoSave": "afterDelay", - "editor.wordWrap": "on", - "workbench.statusBar.feedback.visible": false, - "editor.smoothScrolling": true, - "editor.tabCompletion": "on", - "editor.cursorBlinking": "smooth", - "editor.cursorStyle": "line-thin", - "editor.minimap.maxColumn": 127, - "editor.minimap.renderCharacters": false, - "files.autoGuessEncoding": true, - "workbench.commandPalette.history": 40, - "workbench.enableExperiments": false, - "breadcrumbs.enabled": true, - "extensions.ignoreRecommendations": true, - "terminal.integrated.copyOnSelection": true, - "terminal.integrated.shell.linux": "/bin/bash", - "update.showReleaseNotes": false, - "telemetry.enableCrashReporter": false, - "vsicons.dontShowNewVersionMessage": true, - "telemetry.enableTelemetry": false, - "git.autofetch": true, - "git.showPushSuccessNotification": true, - "markdown.previewFrontMatter": "show", - "python.autoComplete.addBrackets": true, "python.linting.pep8Enabled": true, - "python.unitTest.debugPort": 2000, - "code-runner.saveFileBeforeRun": true, - "code-runner.runInTerminal": true, - "yaml.format.enable": true, - "python.linting.pylintEnabled": false, - "terminal.integrated.rendererType": "dom", - "git.allowForcePush": true, - "git.alwaysShowStagedChangesResourceGroup": true, - "gitlens.settings.mode": "advanced", - "python.jediEnabled": false + "python.linting.enabled": true, + "python.pythonPath": "D:\\Python37\\python.exe" + } \ No newline at end of file diff --git a/LinuxCommands/git.md b/LinuxCommands/git.md deleted file mode 100755 index 37db962..0000000 --- a/LinuxCommands/git.md +++ /dev/null @@ -1,117 +0,0 @@ -git -=== - -是目前世界上最先进的分布式版本控制系统 - -## 补充说明 - -**git命令** 很多人都知道,Linus在1991年创建了开源的Linux,从此,Linux系统不断发展,已经成为最大的服务器系统软件了。 - -Linus虽然创建了Linux,但Linux的壮大是靠全世界热心的志愿者参与的,这么多人在世界各地为Linux编写代码,那Linux的代码是如何管理的呢? - -事实是,在2002年以前,世界各地的志愿者把源代码文件通过diff的方式发给Linus,然后由Linus本人通过手工方式合并代码! - -你也许会想,为什么Linus不把Linux代码放到版本控制系统里呢?不是有CVS、SVN这些免费的版本控制系统吗?因为Linus坚定地反对CVS和SVN,这些集中式的版本控制系统不但速度慢,而且必须联网才能使用。有一些商用的版本控制系统,虽然比CVS、SVN好用,但那是付费的,和Linux的开源精神不符。 - -不过,到了2002年,Linux系统已经发展了十年了,代码库之大让Linus很难继续通过手工方式管理了,社区的弟兄们也对这种方式表达了强烈不满,于是Linus选择了一个商业的版本控制系统BitKeeper,BitKeeper的东家BitMover公司出于人道主义精神,授权Linux社区免费使用这个版本控制系统。 - -安定团结的大好局面在2005年就被打破了,原因是Linux社区牛人聚集,不免沾染了一些梁山好汉的江湖习气。开发Samba的Andrew试图破解BitKeeper的协议(这么干的其实也不只他一个),被BitMover公司发现了(监控工作做得不错!),于是BitMover公司怒了,要收回Linux社区的免费使用权。 - -Linus可以向BitMover公司道个歉,保证以后严格管教弟兄们,嗯,这是不可能的。实际情况是这样的: - -Linus花了两周时间自己用C写了一个分布式版本控制系统,这就是Git!一个月之内,Linux系统的源码已经由Git管理了!牛是怎么定义的呢?大家可以体会一下。 - -Git迅速成为最流行的分布式版本控制系统,尤其是2008年,GitHub网站上线了,它为开源项目免费提供Git存储,无数开源项目开始迁移至GitHub,包括jQuery,PHP,Ruby等等。 - -历史就是这么偶然,如果不是当年BitMover公司威胁Linux社区,可能现在我们就没有免费而超级好用的Git了。 - -[Git常用命令清单](https://github.com/jaywcjlove/handbook/blob/master/other/Git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E6%B8%85%E5%8D%95.md) - -### 语法 - -``` -git [--version] [--help] [-C ] [-c name=value] - [--exec-path[=]] [--html-path] [--man-path] [--info-path] - [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] - [--git-dir=] [--work-tree=] [--namespace=] - [] -``` - -### 选项 - -``` -add 将文件内容添加到索引 -bisect 通过二进制查找引入错误的更改 -branch 列出,创建或删除分支 -checkout 检查分支或路径到工作树 -clone 将存储库克隆到新目录中 -commit 将更改记录到存储库 -diff 显示提交,提交和工作树等之间的更改 -fetch 从另一个存储库下载对象和引用 -grep 打印匹配图案的行 -init 创建一个空的Git仓库或重新初始化一个现有的 -log 显示提交日志 -merge 加入两个或更多的开发历史 -mv 移动或重命名文件,目录或符号链接 -pull 从另一个存储库或本地分支获取并合并 -push 更新远程引用以及相关对象 -rebase 转发端口本地提交到更新的上游头 -reset 将当前HEAD复位到指定状态 -rm 从工作树和索引中删除文件 -show 显示各种类型的对象 -status 显示工作树状态 -tag 创建,列出,删除或验证使用GPG签名的标签对象 -``` - -### 例子 - -init - -`git init` #初始化 - -status - -`git status` #获取状态 - -add - -`git add file` # .或*代表全部添加 -`git rm --cached ` # 在commit之前撤销git add操作 -`git reset head` # 好像比上面`git rm --cached`更方便 - -commit - -`git commit -m "message"` #此处注意乱码 - -remote - -`git remote add origin git@github.com:JSLite/test.git` #添加源 - -push - -```bash -git push -u origin master # push同事设置默认跟踪分支 -git push origin master -git push -f origin master # 强制推送文件,缩写 -f(全写--force) -``` - -clone - -`git clone git://github.com/JSLite/JSLite.js.git ` -`git clone git://github.com/JSLite/JSLite.js.git mypro` #克隆到自定义文件夹 -`git clone [user@]example.com:path/to/repo.git/` #SSH协议还有另一种写法。 - -git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等,下面是一些例子。`git clone <版本库的网址> <本地目录名>` - -```bash -$ git clone http[s]://example.com/path/to/repo.git/ -$ git clone ssh://example.com/path/to/repo.git/ -$ git clone git://example.com/path/to/repo.git/ -$ git clone /opt/git/project.git -$ git clone file:///opt/git/project.git -$ git clone ftp[s]://example.com/path/to/repo.git/ -$ git clone rsync://example.com/path/to/repo.git/ -``` - - - \ No newline at end of file diff --git a/LinuxCommands/ab.md b/Linux_man_cn/ab.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ab.md rename to Linux_man_cn/ab.md index 816844c..898838d --- a/LinuxCommands/ab.md +++ b/Linux_man_cn/ab.md @@ -1,6 +1,6 @@ ab === - + Apache服务器的性能测试工具 ## 补充说明 diff --git a/LinuxCommands/accept.md b/Linux_man_cn/accept.md similarity index 100% rename from LinuxCommands/accept.md rename to Linux_man_cn/accept.md diff --git a/LinuxCommands/alias.md b/Linux_man_cn/alias.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/alias.md rename to Linux_man_cn/alias.md index 9786047..f0ce496 --- a/LinuxCommands/alias.md +++ b/Linux_man_cn/alias.md @@ -1,112 +1,112 @@ -alias -=== - -用来设置指令的别名 - -## 补充说明 - -**alias命令** 用来设置指令的别名。我们可以使用该命令可以将一些较长的命令进行简化。使用alias时,用户必须使用单引号`''`将原来的命令引起来,防止特殊字符导致错误。 - -alias命令的作用只局限于该次登入的操作。若要每次登入都能够使用这些命令别名,则可将相应的alias命令存放到bash的初始化文件`/etc/bashrc`中。 - -### 语法 - -``` -alias(选项)(参数) -``` - -### 选项 - -``` --p:打印已经设置的命令别名。 -``` - -### 参数 - -命令别名设置:定义命令别名,格式为“命令别名=‘实际命令’”。 - -### 实例 - - **alias 的基本使用方法为:** - -``` -alias 新的命令='原命令 -选项/参数' -``` - -例如:`alias l=‘ls -lsh'`将重新定义ls命令,现在只需输入l就可以列目录了。直接输入 alias 命令会列出当前系统中所有已经定义的命令别名。 - -要删除一个别名,可以使用 unalias 命令,如 unalias l。 - - **查看系统已经设置的别名:** - -```bash -[root@localhost ~]# -[root@localhost ~]# alias -alias cp='cp -i' -alias egrep='egrep --color=auto' -alias fgrep='fgrep --color=auto' -alias grep='grep --color=auto' -alias l.='ls -d .* --color=auto' -alias ll='ls -l --color=auto' -alias ls='ls --color=auto' -alias mv='mv -i' -alias rm='rm -i' -alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' -[root@localhost ~]# - -``` -### 命令别名永久生效 -直接在shell里设定的命令别名,在终端关闭或者系统重新启动后都会失效,如何才能永久有效呢?办法就是将别名的设置加入~/.bashrc文件,然后重新载入下文件就可以了。 -```bash -$ vim ~/.bashrc -``` -在文件最后面加入别名设置,如:alias rm=’rm -i’,保存后重新载入: -```bash -$ source ~/.bashrc -``` -这样就可以永久保存命令的别名了。因为修改的是当前用户目录下的.bashrc文件,所以这样的方式只对当前用户有用。如果要对所有用户都有效,修改/etc目录下的bashrc文件就可以了。在CentOS7下,这个文件是/etc/bash.bashrc。此外在CentOS7下,细看~/.bashrc文件,会发有这样一段代码: -```bash -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi -``` - -这个代码的意思就是加载.bash_aliases文件,CentOS7已经帮我们考虑好了,所以也可以在用户根目录下新建一个文件.bash_aliases存放命令别名设置。 - -### 小结 - -alias这个命令是shell的内建命令,可以根据自己的使用习惯设置一些别名,需要注意的就是和其他命令冲突的情况。 - - - - -#### 一、 范例演示 - -在使用和维护Linux系统过程中,我们常常希望根据自己的需要来定义一些命令,那么这样的操作是不是很难呢?其实不是,系统已经为我们设置好了相关的命令,下面小编就以CentOS6.4系统为例,为大家演示如何创建自己的命令。 - -#### 二、 自定义命令简介 - CentOS系统下的创建自定义命令其实比较简单,使用的命令就是alias,具体使用的方法就是 alias 自定义命令名=‘命令’。但是需要注意的是,在自定义之前需要查看自定义的命令名是否是系统已经使用的命令名,否则会冲突,另外一个就是定期清理不需要的自定义命令名。 - - -#### 三、 演示举例 -假定系统操作员希望进行如下操作: -1.进入目录/root -2.查看目录下文件 -3.切换回根目录 -通常这需要三条命令 cd /root;ls;cd / ,如果需要经常使用那么我们可以通过自定义命令的方式用一条命令完成全部操作。 -![](alias\01.png) - -#### 四、 操作过程 - 首先使用命令 type 自定义命令名 ,查看自定义命令名是否被系统占用。从图中可以看出test命令名已被系统占用,所以不能使用,而loo这个命令名经查询可以使用。 -![](alias\02.png) - - 使用命令alias创建自定义命令:alias loo='cd /root;ls;cd /' 。需要注意的是命令的使用格式,分号与分号之间是没有空格的。 -![](alias\03.png) - - 测试一下自定义命令,当输入命令 loo 时,发现系统依次完成了 cd /root、ls、cd / 三条命令,说明设置成功。同时也可直接使用命令 alias 查询系统中是否添加了loo这个自定义命令。 -![](alias\04.png) - - 如果希望删除这个自定义命令,可以使用命令 unalias 自定义命令名 来完成。执行之后发现,loo命令已不存在,同时自定义命令库中也没有loo命令。 -![](alias\05.png) - - +alias +=== + +用来设置指令的别名 + +## 补充说明 + +**alias命令** 用来设置指令的别名。我们可以使用该命令可以将一些较长的命令进行简化。使用alias时,用户必须使用单引号`''`将原来的命令引起来,防止特殊字符导致错误。 + +alias命令的作用只局限于该次登入的操作。若要每次登入都能够使用这些命令别名,则可将相应的alias命令存放到bash的初始化文件`/etc/bashrc`中。 + +### 语法 + +``` +alias(选项)(参数) +``` + +### 选项 + +``` +-p:打印已经设置的命令别名。 +``` + +### 参数 + +命令别名设置:定义命令别名,格式为“命令别名=‘实际命令’”。 + +### 实例 + + **alias 的基本使用方法为:** + +``` +alias 新的命令='原命令 -选项/参数' +``` + +例如:`alias l=‘ls -lsh'`将重新定义ls命令,现在只需输入l就可以列目录了。直接输入 alias 命令会列出当前系统中所有已经定义的命令别名。 + +要删除一个别名,可以使用 unalias 命令,如 unalias l。 + + **查看系统已经设置的别名:** + +```bash +[root@localhost ~]# +[root@localhost ~]# alias +alias cp='cp -i' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias grep='grep --color=auto' +alias l.='ls -d .* --color=auto' +alias ll='ls -l --color=auto' +alias ls='ls --color=auto' +alias mv='mv -i' +alias rm='rm -i' +alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' +[root@localhost ~]# + +``` +### 命令别名永久生效 +直接在shell里设定的命令别名,在终端关闭或者系统重新启动后都会失效,如何才能永久有效呢?办法就是将别名的设置加入~/.bashrc文件,然后重新载入下文件就可以了。 +```bash +$ vim ~/.bashrc +``` +在文件最后面加入别名设置,如:alias rm=’rm -i’,保存后重新载入: +```bash +$ source ~/.bashrc +``` +这样就可以永久保存命令的别名了。因为修改的是当前用户目录下的.bashrc文件,所以这样的方式只对当前用户有用。如果要对所有用户都有效,修改/etc目录下的bashrc文件就可以了。在CentOS7下,这个文件是/etc/bash.bashrc。此外在CentOS7下,细看~/.bashrc文件,会发有这样一段代码: +```bash +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi +``` + +这个代码的意思就是加载.bash_aliases文件,CentOS7已经帮我们考虑好了,所以也可以在用户根目录下新建一个文件.bash_aliases存放命令别名设置。 + +### 小结 + +alias这个命令是shell的内建命令,可以根据自己的使用习惯设置一些别名,需要注意的就是和其他命令冲突的情况。 + + + + +#### 一、 范例演示 + +在使用和维护Linux系统过程中,我们常常希望根据自己的需要来定义一些命令,那么这样的操作是不是很难呢?其实不是,系统已经为我们设置好了相关的命令,下面小编就以CentOS6.4系统为例,为大家演示如何创建自己的命令。 + +#### 二、 自定义命令简介 + CentOS系统下的创建自定义命令其实比较简单,使用的命令就是alias,具体使用的方法就是 alias 自定义命令名=‘命令’。但是需要注意的是,在自定义之前需要查看自定义的命令名是否是系统已经使用的命令名,否则会冲突,另外一个就是定期清理不需要的自定义命令名。 + + +#### 三、 演示举例 +假定系统操作员希望进行如下操作: +1.进入目录/root +2.查看目录下文件 +3.切换回根目录 +通常这需要三条命令 cd /root;ls;cd / ,如果需要经常使用那么我们可以通过自定义命令的方式用一条命令完成全部操作。 +![](alias\01.png) + +#### 四、 操作过程 + 首先使用命令 type 自定义命令名 ,查看自定义命令名是否被系统占用。从图中可以看出test命令名已被系统占用,所以不能使用,而loo这个命令名经查询可以使用。 +![](alias\02.png) + + 使用命令alias创建自定义命令:alias loo='cd /root;ls;cd /' 。需要注意的是命令的使用格式,分号与分号之间是没有空格的。 +![](alias\03.png) + + 测试一下自定义命令,当输入命令 loo 时,发现系统依次完成了 cd /root、ls、cd / 三条命令,说明设置成功。同时也可直接使用命令 alias 查询系统中是否添加了loo这个自定义命令。 +![](alias\04.png) + + 如果希望删除这个自定义命令,可以使用命令 unalias 自定义命令名 来完成。执行之后发现,loo命令已不存在,同时自定义命令库中也没有loo命令。 +![](alias\05.png) + + diff --git a/LinuxCommands/apachectl.md b/Linux_man_cn/apachectl.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/apachectl.md rename to Linux_man_cn/apachectl.md index 9656af2..bd47688 --- a/LinuxCommands/apachectl.md +++ b/Linux_man_cn/apachectl.md @@ -1,6 +1,6 @@ apachectl === - + Apache服务器前端控制工具 ## 补充说明 diff --git a/LinuxCommands/apropos.md b/Linux_man_cn/apropos.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/apropos.md rename to Linux_man_cn/apropos.md index b4bcd87..41928a8 --- a/LinuxCommands/apropos.md +++ b/Linux_man_cn/apropos.md @@ -1,6 +1,6 @@ apropos === - + 在 whatis 数据库中查找字符串 ## 补充说明 diff --git a/LinuxCommands/apt-get.md b/Linux_man_cn/apt-get.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/apt-get.md rename to Linux_man_cn/apt-get.md index 95a4e3a..9a4d9da --- a/LinuxCommands/apt-get.md +++ b/Linux_man_cn/apt-get.md @@ -1,6 +1,6 @@ apt-get === - + Debian Linux发行版中的APT软件包管理工具 ## 补充说明 diff --git a/LinuxCommands/apt-key.md b/Linux_man_cn/apt-key.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/apt-key.md rename to Linux_man_cn/apt-key.md index 64766cb..29123f3 --- a/LinuxCommands/apt-key.md +++ b/Linux_man_cn/apt-key.md @@ -1,6 +1,6 @@ apt-key === - + 管理Debian Linux系统中的软件包密钥 ## 补充说明 diff --git a/LinuxCommands/apt-sortpkgs.md b/Linux_man_cn/apt-sortpkgs.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/apt-sortpkgs.md rename to Linux_man_cn/apt-sortpkgs.md index f9d2416..e65f684 --- a/LinuxCommands/apt-sortpkgs.md +++ b/Linux_man_cn/apt-sortpkgs.md @@ -1,6 +1,6 @@ apt-sortpkgs === - + Debian Linux下对软件包索引文件进行排序的工具 ## 补充说明 diff --git a/LinuxCommands/aptitude.md b/Linux_man_cn/aptitude.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/aptitude.md rename to Linux_man_cn/aptitude.md index 378997d..f4176b1 --- a/LinuxCommands/aptitude.md +++ b/Linux_man_cn/aptitude.md @@ -1,6 +1,6 @@ aptitude === - + Debian Linux系统中软件包管理工具 ## 补充说明 diff --git a/LinuxCommands/ar.md b/Linux_man_cn/ar.md similarity index 100% rename from LinuxCommands/ar.md rename to Linux_man_cn/ar.md diff --git a/LinuxCommands/arch.md b/Linux_man_cn/arch.md similarity index 100% rename from LinuxCommands/arch.md rename to Linux_man_cn/arch.md diff --git a/LinuxCommands/arj.md b/Linux_man_cn/arj.md similarity index 100% rename from LinuxCommands/arj.md rename to Linux_man_cn/arj.md diff --git a/LinuxCommands/arp.md b/Linux_man_cn/arp.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/arp.md rename to Linux_man_cn/arp.md index 222729c..84b6fd9 --- a/LinuxCommands/arp.md +++ b/Linux_man_cn/arp.md @@ -1,6 +1,6 @@ arp === - + 显示和修改IP到MAC转换表 ## 补充说明 diff --git a/LinuxCommands/arpd.md b/Linux_man_cn/arpd.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/arpd.md rename to Linux_man_cn/arpd.md index 35e2dc5..867b866 --- a/LinuxCommands/arpd.md +++ b/Linux_man_cn/arpd.md @@ -1,6 +1,6 @@ arpd === - + 收集免费ARP信息 ## 补充说明 diff --git a/LinuxCommands/arping.md b/Linux_man_cn/arping.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/arping.md rename to Linux_man_cn/arping.md index 3494228..f933c9e --- a/LinuxCommands/arping.md +++ b/Linux_man_cn/arping.md @@ -1,6 +1,6 @@ arping === - + 通过发送ARP协议报文测试网络 ## 补充说明 diff --git a/LinuxCommands/arptables.md b/Linux_man_cn/arptables.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/arptables.md rename to Linux_man_cn/arptables.md index 56c137b..42f6ea8 --- a/LinuxCommands/arptables.md +++ b/Linux_man_cn/arptables.md @@ -1,6 +1,6 @@ arptables === - + 管理ARP包过滤规则表 ## 补充说明 diff --git a/LinuxCommands/arpwatch.md b/Linux_man_cn/arpwatch.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/arpwatch.md rename to Linux_man_cn/arpwatch.md index c3fb1a2..9b1de0f --- a/LinuxCommands/arpwatch.md +++ b/Linux_man_cn/arpwatch.md @@ -1,6 +1,6 @@ arpwatch === - + 监听网络上ARP的记录 ## 补充说明 diff --git a/LinuxCommands/as.md b/Linux_man_cn/as.md similarity index 100% rename from LinuxCommands/as.md rename to Linux_man_cn/as.md diff --git a/LinuxCommands/at.md b/Linux_man_cn/at.md similarity index 100% rename from LinuxCommands/at.md rename to Linux_man_cn/at.md diff --git a/LinuxCommands/atop.md b/Linux_man_cn/atop.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/atop.md rename to Linux_man_cn/atop.md diff --git a/LinuxCommands/atq.md b/Linux_man_cn/atq.md similarity index 100% rename from LinuxCommands/atq.md rename to Linux_man_cn/atq.md diff --git a/LinuxCommands/atrm.md b/Linux_man_cn/atrm.md similarity index 100% rename from LinuxCommands/atrm.md rename to Linux_man_cn/atrm.md diff --git a/LinuxCommands/awk.md b/Linux_man_cn/awk.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/awk.md rename to Linux_man_cn/awk.md index 881288d..1683966 --- a/LinuxCommands/awk.md +++ b/Linux_man_cn/awk.md @@ -1,1313 +1,1313 @@ -# awk - -## 说明 - -**awk** awk的基本功能是在文件中搜索包含一个或多个模式的行或其他文本单元。当一行与其中一个模式匹配时,将对该行执行特殊操作。 awk中的程序与大多数其他语言中的程序不同,因为awk程序是“数据驱动的”:您描述要使用的数据,然后在找到时执行的操作。大多数其他语言都是“程序性的”。您必须详细描述该计划要采取的每个步骤。使用过程语言时,通常很难清楚地描述程序将处理的数据。出于这个原因,awk程序通常易于读写。 - -## 语法形式 - -```sh -awk [options] 'script' var=value file(s) -awk [options] -f scriptfile var=value file(s) -``` - -## 常用命令选项 - -***-F fs   *** fs指定输入分隔符,fs可以是字符串或正则表达式,如-F: -***-v var=value   *** 赋值一个用户定义变量,将外部变量传递给awk -***-f scripfile  *** 从脚本文件中读取awk命令 -***-m[fr] val   *** 对val值设置内在限制,-mf选项限制分配给val的最大块数目;-mr选项限制记录的最大数目。这两个功能是Bell实验室版awk的扩展功能,在标准awk中不适用。 - -## 模式 - -模式可以是以下任意一个: - -* /正则表达式/:使用通配符的扩展集。 -* 关系表达式:使用运算符进行操作,可以是字符串或数字的比较测试。 -* 模式匹配表达式:用运算符`~`(匹配)和`~!`(不匹配)。 -* BEGIN语句块、pattern语句块、END语句块:参见awk的工作原理 - -## 操作 - -操作由一个或多个命令、函数、表达式组成,之间由换行符或分号隔开,并位于大括号内,主要部分是: - -* 变量或数组赋值 -* 输出命令 -* 内置函数 -* 控制流语句 - -## awk脚本基本结构 - -```sh -awk 'BEGIN{ print "start" } pattern{ commands } END{ print "end" }' file -``` - -一个awk脚本通常由:BEGIN语句块、能够使用模式匹配的通用语句块、END语句块3部分组成,这三个部分是可选的。任意一个部分都可以不出现在脚本中,脚本通常是被** 单引号** 或** 双引号** 中,例如: - -```sh -awk 'BEGIN{ i=0 } { i++ } END{ print i }' filename -awk "BEGIN{ i=0 } { i++ } END{ print i }" filename -``` - -## awk的工作原理 - -```sh -awk 'BEGIN{ commands } pattern{ commands } END{ commands }' -``` - -* 第一步:执行`BEGIN{ commands }`语句块中的语句; -* 第二步:从文件或标准输入(stdin)读取一行,然后执行`pattern{ commands }`语句块,它逐行扫描文件,从第一行到最后一行重复这个过程,直到文件全部被读取完毕。 -* 第三步:当读至输入流末尾时,执行`END{ commands }`语句块。 - -**BEGIN语句块** 在awk开始从输入流中读取行** 之前** 被执行,这是一个可选的语句块,比如变量初始化、打印输出表格的表头等语句通常可以写在BEGIN语句块中。 - -**END语句块** 在awk从输入流中读取完所有的行** 之后** 即被执行,比如打印所有行的分析结果这类信息汇总都是在END语句块中完成,它也是一个可选语句块。 - -**pattern语句块** 中的通用命令是最重要的部分,它也是可选的。如果没有提供pattern语句块,则默认执行`{ print }`,即打印每一个读取到的行,awk读取的每一行都会执行该语句块。 - -## 示例 - -```sh -echo -e "A line 1nA line 2" | awk 'BEGIN{ print "Start" } { print } END{ print "End" }' -Start -A line 1 -A line 2 -End -``` - -当使用不带参数的`print`时,它就打印当前行,当`print`的参数是以逗号进行分隔时,打印时则以空格作为定界符。在awk的print语句块中双引号是被当作拼接符使用,例如: - -```sh -echo | awk '{ var1="v1"; var2="v2"; var3="v3"; print var1,var2,var3; }' -v1 v2 v3 -``` - -双引号拼接使用: - -```sh -echo | awk '{ var1="v1"; var2="v2"; var3="v3"; print var1"="var2"="var3; }' -v1=v2=v3 -``` - -{ }类似一个循环体,会对文件中的每一行进行迭代,通常变量初始化语句(如:i=0)以及打印文件头部的语句放入BEGIN语句块中,将打印的结果等语句放在END语句块中。 - -## awk内置变量(预定义变量) - -说明:[A][N][P][G]表示第一个支持变量的工具,[A]=awk、[N]=nawk、[P]=POSIXawk、[G]=gawk -可自定义变量,变量可以是字符串或数值。输入字段的内容也可以分配给变量。为了更精确地控制输出格式而不是打印通常提供的输出格式,请使用printf。 printf命令可用于指定每个项目使用的字段宽度,以及数字的各种格式选择(例如要使用的输出基数,是否打印指数,是否打印标记以及数字位数在小数点后打印)。这是通过提供一个名为格式字符串的字符串来完成的,该字符串控制打印其他参数的方式和位置。 - -```sh -** $n**当前记录的第n个字段,比如n为1表示第一个字段,n为2表示第二个字段。 -** $0**这个变量包含执行过程中当前行的文本内容。 -[N]**ARGC**命令行参数的数目。 -[G]**ARGIND**命令行中当前文件的位置(从0开始算)。 -[N]**ARGV**包含命令行参数的数组。 -[G]**CONVFMT**数字转换格式(默认值为%.6g)。 -[P]**ENVIRON**环境变量关联数组。 -[N]**ERRNO**最后一个系统错误的描述。 -[G]**FIELDWIDTHS**字段宽度列表(用空格键分隔)。 -[A]**FILENAME**当前输入文件的名。 -[P]**FNR**同NR,但相对于当前文件。 -[A]**FS(fields separator)**字段分隔符(此变量预定义为一个或多个空格或制表符)。 -[G]**IGNORECASE**如果为真,则进行忽略大小写的匹配。 -[A]**NF**表示字段数,在执行过程中对应于当前的字段数。 -[A]**NR(number of records)**表示记录数,在执行过程中对应于当前的行号。 -[A]**OFMT**数字的输出格式(默认值是%.6g)。 -[A]**OFS(output fields separator)**输出字段分隔符(默认值是一个空格)。 -[A]**ORS(output record separator)**输出记录分隔符(默认值是一个换行符)。 -[A]**RS**记录分隔符(默认是一个换行符)。 -[N]**RSTART**由match函数所匹配的字符串的第一个位置。 -[N]**RLENGTH**由match函数所匹配的字符串的长度。 -[N]**SUBSEP**数组下标分隔符(默认值是34)。 -``` - -示例 - -FS示例 - -```sh -awk FS变量用于设置每个记录的字段分割符,其可以设置为任何单个字符或者正则表达式 -FS可以更改任意次数,会保留其值直到明确更改,如果想更改字段分割符,在阅读行之前更改,固此改变会影响阅读的内容 - -awk -F 'FS''命令'文件名 -或 -awk 'BEGIN {FS="FS";}' - -用于读取具有:作为字段分割符的/etc/passwd文件:awk -f etc_pass.awk /etc/passwd -BEGIN{ -FS = ":"; -print "\tUserID\tGroupID\tHomeDirectory"; -} -{ - print $1"\t"$3"\t"$4"\t"$6; -} -END{ - print NR,"打印记录" -#NR统计打印的数目 -} - -awk OFS是awk FS变量的输出,默认情况,awk OFS是单个空格字符 - -awk -F ':' '{print $3,$4;}' /etc/passwd - -打印语句中的:,默认情况下两个参数连接为一个空间,该空间是awk OFS的值,固其值被插入到输出中的字段之间 - -awk -F ':' 'BEGIN{OFS ="=";}{print $3,$4;}' /etc/passwd -``` - -awk RS示例:记录分割符变量 - -```sh -awk RS定义了一条线,awk默认逐行读取。将信息存储在一个文件中,每个记录由两个新行隔开,每个字段用一个新行分割 - -打印姓名和第二行数字 - -cat student.awk -BEGIN { - RS =“\ n \ n”;; - FS = “\ n”个; - -} -{ - print $ 1,$ 2; -} - -awk -f student.awk student.txt - - - -``` - -```sh -echo -e "line1 f2 f3\nline2 f4 f5\nline3 f6 f7" | awk '{print "Line No:"NR", No of fields:"NF, "$0="$0, "$1="$1, "$2="$2, "$3="$3}' -Line No:1, No of fields:3 $0=line1 f2 f3 $1=line1 $2=f2 $3=f3 -Line No:2, No of fields:3 $0=line2 f4 f5 $1=line2 $2=f4 $3=f5 -Line No:3, No of fields:3 $0=line3 f6 f7 $1=line3 $2=f6 $3=f7 -``` - -使用`print $NF`可以打印出一行中的最后一个字段,使用`$(NF-1)`则是打印倒数第二个字段,其他以此类推: - -```sh -echo -e "line1 f2 f3n line2 f4 f5" | awk '{print $NF}' -f3 -f5 -``` - -```sh -echo -e "line1 f2 f3n line2 f4 f5" | awk '{print $(NF-1)}' -f2 -f4 - -``` - -打印每一行的第二和第三个字段: - -```sh -awk '{ print $2,$3 }' filename -``` - -统计文件中的行数: - -```sh -awk 'END{ print NR }' filename -``` - -以上命令只使用了END语句块,在读入每一行的时,awk会将NR更新为对应的行号,当到达最后一行NR的值就是最后一行的行号,所以END语句块中的NR就是文件的行数。 - -一个每一行中第一个字段值累加的例子: - -```sh -seq 5 | awk 'BEGIN{ sum=0; print "总和:" } { print $1"+"; sum+=$1 } END{ print "等于"; print sum }' -总和: -1+ -2+ -3+ -4+ -5+ -等于 -15 -``` - -## 将外部变量值传递给awk - -借助** `-v`选项** ,可以将外部值(并非来自stdin)传递给awk: - -```sh -VAR=10000 -echo | awk -v VARIABLE=$VAR '{ print VARIABLE }' -``` - -另一种传递外部变量方法: - -```sh -var1="aaa" -var2="bbb" -echo | awk '{ print v1,v2 }' v1=$var1 v2=$var2 -``` - -当输入来自于文件时使用: - -```sh -awk '{ print v1,v2 }' v1=$var1 v2=$var2 filename -``` - -以上方法中,变量之间用空格分隔作为awk的命令行参数跟随在BEGIN、{}和END语句块之后。 - -## 查找进程pid - -```sh -netstat -antup | grep 7770 | awk '{ print $NF NR}' | awk '{ print $1}' -``` - -## awk运算与判断 - -作为一种程序设计语言所应具有的特点之一,awk支持多种运算,这些运算与C语言提供的基本相同。awk还提供了一系列内置的运算函数(如log、sqr、cos、sin等)和一些用于对字符串进行操作(运算)的函数(如length、substr等等)。这些函数的引用大大的提高了awk的运算功能。作为对条件转移指令的一部分,关系判断是每种程序设计语言都具备的功能,awk也不例外,awk中允许进行多种测试,作为样式匹配,还提供了模式匹配表达式~(匹配)和~!(不匹配)。作为对测试的一种扩充,awk也支持用逻辑运算符。 - -## 算术运算符 - -| 运算符 | 描述 | -| ----- | ---- | -| + - | 加,减 | -| * / & | 乘,除与求余 | -| + - ! | 一元加,减和逻辑非 | -| ^** * | 求幂 | -| ++ -- | 增加或减少,作为前缀或后缀 | - -例: - -```sh -awk 'BEGIN{a="b";print a++,++a;}' -0 2 -``` - -注意:所有用作算术运算符进行操作,操作数自动转为数值,所有非数值都变为0 - -## 赋值运算符 - -| 运算符 | 描述 | -| ----- | ---- | -| = += -= *= /= %= ^=** = | 赋值语句 | - -例: - -```sh -a+=5; 等价于:a=a+5; 其它同类 -``` - -## 逻辑运算符 - -| 运算符 | 描述 | -| ----- | ---- | -| `\|\|` | 逻辑或 | -| && | 逻辑与 | - -例: - -```sh -awk 'BEGIN{a=1;b=2;print (a>5 && b<=2),(a>5 || b<=2);}' -0 1 -``` - -## 正则运算符 - -| 运算符 | 描述 | -| ----- | ---- | -| ~ ~! | 匹配正则表达式和不匹配正则表达式 | - -例: - -```sh -awk 'BEGIN{a="100testa";if(a ~ /^100*/){print "ok";}}' -ok -``` - -## 关系运算符 - -| 运算符 | 描述 | -| ----- | ---- | -| < <= > >= != == | 关系运算符 | - -例: - -```sh -awk 'BEGIN{a=11;if(a >= 9){print "ok";}}' -ok -``` - -注意:> < 可以作为字符串比较,也可以用作数值比较,关键看操作数如果是字符串就会转换为字符串比较。两个都为数字才转为数值比较。字符串比较:按照ASCII码顺序比较。 - -## 其它运算符 - -| 运算符 | 描述 | -| ----- | ---- | -| $ | 字段引用 | -| 空格 | 字符串连接符 | -| ?: | C条件表达式 | -| in | 数组中是否存在某键值 | - -例: - -```sh -awk 'BEGIN{a="b";print a=="b"?"ok":"err";}' -ok -``` - -```sh -awk 'BEGIN{a="b";arr[0]="b";arr[1]="c";print (a in arr);}' -0 -``` - -```sh -awk 'BEGIN{a="b";arr[0]="b";arr["b"]="c";print (a in arr);}' -1 -``` - -## 运算级优先级表 - -!级别越高越优先 -级别越高越优先 - -## awk高级输入输出 - -## 读取下一条记录 - -awk中`next`语句使用:在循环逐行匹配,如果遇到next,就会跳过当前行,直接忽略下面语句。而进行下一行匹配。next语句一般用于多行合并: - -```sh -cat text.txt -a -b -c -d -e - -awk 'NR%2==1{next}{print NR,$0;}' text.txt -2 b -4 d -``` - -当记录行号除以2余1,就跳过当前行。下面的`print NR,$0`也不会执行。下一行开始,程序有开始判断`NR%2`值。这个时候记录行号是`:2` ,就会执行下面语句块:`'print NR,$0'` - -分析发现需要将包含有“web”行进行跳过,然后需要将内容与下面行合并为一行: - -```sh -cat text.txt -web01[192.168.2.100] -httpdok -tomcat ok -sendmail ok -web02[192.168.2.101] -httpdok -postfix ok -web03[192.168.2.102] -mysqldok -httpd ok -0 -awk '/^web/{T=$0;next;}{print T":t"$0;}' test.txt -web01[192.168.2.100]: httpdok -web01[192.168.2.100]: tomcat ok -web01[192.168.2.100]: sendmail ok -web02[192.168.2.101]: httpdok -web02[192.168.2.101]: postfix ok -web03[192.168.2.102]: mysqldok -web03[192.168.2.102]: httpd ok -``` - -## 简单地读取一条记录 - -`awk getline`用法:输出重定向需用到`getline函数`。getline从标准输入、管道或者当前正在处理的文件之外的其他输入文件获得输入。它负责从输入获得下一行的内容,并给NF,NR和FNR等内建变量赋值。如果得到一条记录,getline函数返回1,如果到达文件的末尾就返回0,如果出现错误,例如打开文件失败,就返回-1。 - -getline语法:getline var,变量var包含了特定行的内容。 - -awk getline从整体上来说,用法说明: - -***当其左右无重定向符`|`或`<`时:** getline作用于当前文件,读入当前文件的第一行给其后跟的变量`var`或`$0`(无变量),应该注意到,由于awk在处理getline之前已经读入了一行,所以getline得到的返回结果是隔行的。 -***当其左右有重定向符`|`或`<`时:** getline则作用于定向输入文件,由于该文件是刚打开,并没有被awk读入一行,只是getline读入,那么getline返回的是该文件的第一行,而不是隔行。 - -** 示例:** - -执行linux的`date`命令,并通过管道输出给`getline`,然后再把输出赋值给自定义变量out,并打印它: - -```sh -awk 'BEGIN{ "date" | getline out; print out }' test -``` - -执行shell的date命令,并通过管道输出给getline,然后getline从管道中读取并将输入赋值给out,split函数把变量out转化成数组mon,然后打印数组mon的第二个元素: - -```sh -awk 'BEGIN{ "date" | getline out; split(out,mon); print mon[2] }' test -``` - -命令ls的输出传递给geline作为输入,循环使getline从ls的输出中读取一行,并把它打印到屏幕。这里没有输入文件,因为BEGIN块在打开输入文件前执行,所以可以忽略输入文件。 - -```sh -awk 'BEGIN{ while( "ls" | getline) print }' -``` - -## 关闭文件 - -awk中允许在程序中关闭一个输入或输出文件,方法是使用awk的close语句。 - -```sh -close("filename") -``` - -filename可以是getline打开的文件,也可以是stdin,包含文件名的变量或者getline使用的确切命令。或一个输出文件,可以是stdout,包含文件名的变量或使用管道的确切命令。 - -## 输出到一个文件 - -awk中允许用如下方式将结果输出到一个文件: - -```sh -echo | awk '{printf("hello word!n") > "datafile"}' -或 -echo | awk '{printf("hello word!n") >> "datafile"}' -``` - -## 设置字段定界符 - -默认的字段定界符是空格,可以使用`-F "定界符"`明确指定一个定界符: - -```sh -awk -F: '{ print $NF }' /etc/passwd -或 -awk 'BEGIN{ FS=":" } { print $NF }' /etc/passwd -``` - -在`BEGIN语句块`中则可以用`OFS=“定界符”`设置输出字段的定界符。 - -## 流程控制语句 - -在linux awk的while、do-while和for语句中允许使用break,continue语句来控制流程走向,也允许使用exit这样的语句来退出。break中断当前正在执行的循环并跳到循环外执行下一条语句。if 是流程选择用法。awk中,流程控制语句,语法结构,与c语言类型。有了这些语句,其实很多shell程序都可以交给awk,而且性能是非常快的。下面是各个语句用法。 - -## 条件判断语句 - -```sh -if(表达式) -语句1 -else -语句2 -``` - -格式中语句1可以是多个语句,为了方便判断和阅读,最好将多个语句用{}括起来。awk分枝结构允许嵌套,其格式为: - -```sh -if(表达式) -{语句1} -else if(表达式) -{语句2} -else -{语句3} -``` - -示例: - -```sh -awk 'BEGIN{ -test=100; -if(test>90){ -print "very good"; -} -else if(test>60){ -print "good"; -} -else{ -print "no pass"; -} -}' - -very good -``` - -每条命令语句后面可以用`;`** 分号** 结尾。 - -## 循环语句 - -### while语句 - -```sh -while(表达式) -{语句} -``` - -示例: - -```sh -awk 'BEGIN{ -test=100; -total=0; -while(i<=test){ -total+=i; -i++; -} -print total; -}' -5050 -``` - -### for循环 - -for循环有两种格式: - -格式1: - -```sh -for(变量 in 数组) -{语句} -``` - -示例: - -```sh -awk 'BEGIN{ -for(k in ENVIRON){ -print k"="ENVIRON[k]; -} - -}' -TERM=linux -G_BROKEN_FILENAMES=1 -SHLVL=1 -pwd=/root/text -... -logname=root -HOME=/root -SSH_CLIENT=192.168.1.21 53087 22 -``` - -注:ENVIRON是awk常量,是子典型数组。 - -格式2: - -```sh -for(变量;条件;表达式) -{语句} -``` - -示例: - -```sh -awk 'BEGIN{ -total=0; -for(i=0;i<=100;i++){ -total+=i; -} -print total; -}' -5050 -``` - -### do循环 - -```sh -do -{语句} while(条件) -``` - -例子: - -```sh -awk 'BEGIN{ -total=0; -i=0; -do {total+=i;i++;} while(i<=100) -print total; -}' -5050 -``` - -## 其他语句 - -***break**当 break 语句用于 while 或 for 语句时,导致退出程序循环。 -***continue**当 continue 语句用于 while 或 for 语句时,使程序循环移动到下一个迭代。 -***next**能能够导致读入下一个输入行,并返回到脚本的顶部。这可以避免对当前输入行执行其他的操作过程。 -***exit**语句使主输入循环退出并将控制转移到END,如果END存在的话。如果没有定义END规则,或在END中应用exit语句,则终止脚本的执行。 - -## 数组应用 - -数组是awk的灵魂,处理文本中最不能少的就是它的数组处理。因为数组索引(下标)可以是数字和字符串在awk中数组叫做关联数组(associative arrays)。awk 中的数组不必提前声明,也不必声明大小。数组元素用0或空字符串来初始化,这根据上下文而定。 - -## 数组的定义 - -数字做数组索引(下标): - -```sh -Array[1]="sun" -Array[2]="kai" -``` - -字符串做数组索引(下标): - -```sh -Array["first"]="www" -Array"[last"]="name" -Array["birth"]="1987" -``` - -使用中`print Array[1]`会打印出sun;使用`print Array[2]`会打印出kai;使用`print["birth"]`会得到1987。 - -** 读取数组的值** - -```sh -{ for(item in array) {print array[item]}; } #输出的顺序是随机的 -{ for(i=1;i<=len;i++) {print array[i]}; } #Len是数组的长度 -``` - -## 数组相关函数 - -** 得到数组长度:** - -```sh -awk 'BEGIN{info="it is a test";lens=split(info,tA," ");print length(tA),lens;}' -4 4 -``` - -length返回字符串以及数组长度,split进行分割字符串为数组,也会返回分割得到数组长度。 - -```sh -awk 'BEGIN{info="it is a test";split(info,tA," ");print asort(tA);}' -4 -``` - -asort对数组进行排序,返回数组长度。 - -** 输出数组内容(无序,有序输出):** - -```sh -awk 'BEGIN{info="it is a test";split(info,tA," ");for(k in tA){print k,tA[k];}}' -4 test -1 it -2 is -3 a -``` - -`for…in`输出,因为数组是关联数组,默认是无序的。所以通过`for…in`得到是无序的数组。如果需要得到有序数组,需要通过下标获得。 - -```sh -awk 'BEGIN{info="it is a test";tlen=split(info,tA," ");for(k=1;k<=tlen;k++){print k,tA[k];}}' -1 it -2 is -3 a -4 test -``` - -注意:数组下标是从1开始,与C数组不一样。 - -** 判断键值存在以及删除键值:** - -```sh -#错误的判断方法: -awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";if(tB["c"]!="1"){print "no found";};for(k in tB){print k,tB[k];}}' -no found -a a1 -b b1 -c -``` - -以上出现奇怪问题,`tB[“c”]`没有定义,但是循环时候,发现已经存在该键值,它的值为空,这里需要注意,awk数组是关联数组,只要通过数组引用它的key,就会自动创建改序列。 - -```bash -#正确判断方法: -awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";if( "c" in tB){print "ok";};for(k in tB){print k,tB[k];}}' -a a1 -b b1 -``` - -`if(key in array)`通过这种方法判断数组中是否包含`key`键值。 - -```bash -#删除键值: -awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";delete tB["a"];for(k in tB){print k,tB[k];}}' -b b1 -``` - -`delete array[key]`可以删除,对应数组`key`的,序列值。 - -## 二维、多维数组使用 - -awk的多维数组在本质上是一维数组,更确切一点,awk在存储上并不支持多维数组。awk提供了逻辑上模拟二维数组的访问方式。例如,`array[2,4]=1`这样的访问是允许的。awk使用一个特殊的字符串`SUBSEP(�34)`作为分割字段,在上面的例子中,关联数组array存储的键值实际上是2�344。 - -类似一维数组的成员测试,多维数组可以使用`if ( (i,j) in array)`这样的语法,但是下标必须放置在圆括号中。类似一维数组的循环访问,多维数组使用`for ( item in array )`这样的语法遍历数组。与一维数组不同的是,多维数组必须使用`split()`函数来访问单独的下标分量。 - -```bash -awk 'BEGIN{ -for(i=1;i<=9;i++){ -for(j=1;j<=9;j++){ -tarr[i,j]=i*j; print i,"*",j,"=",tarr[i,j]; -} -} -}' -1 * 1 = 1 -1 * 2 = 2 -1 * 3 = 3 -1 * 4 = 4 -1 * 5 = 5 -1 * 6 = 6 -... -9 * 6 = 54 -9 * 7 = 63 -9 * 8 = 72 -9 * 9 = 81 -``` - -可以通过`array[k,k2]`引用获得数组内容。 - -另一种方法: - -```bash -awk 'BEGIN{ -for(i=1;i<=9;i++){ -for(j=1;j<=9;j++){ -tarr[i,j]=i*j; -} -} -for(m in tarr){ -split(m,tarr2,SUBSEP); print tarr2[1],"*",tarr2[2],"=",tarr[m]; -} -}' -``` - -## 内置函数 - -awk内置函数,主要分以下3种类似:算数函数、字符串函数、其它一般函数、时间函数。 - -## 算术函数 - -| 格式 | 描述 | -| ---- | ---- | -| atan2( y, x ) | 返回 y/x 的反正切。 | -| cos( x ) | 返回 x 的余弦;x 是弧度。 | -| sin( x ) | 返回 x 的正弦;x 是弧度。 | -| exp( x ) | 返回 x 幂函数。 | -| log( x ) | 返回 x 的自然对数。 | -| sqrt( x ) | 返回 x 平方根。 | -| int( x ) | 返回 x 的截断至整数的值。 | -| rand( ) | 返回任意数字 n,其中 0 <= n < 1。 | -| srand( [expr] ) | 将 rand 函数的种子值设置为 Expr 参数的值,或如果省略 Expr 参数则使用某天的时间。返回先前的种子值。 | - -举例说明: - -```sh -awk 'BEGIN{OFMT="%.3f";fs=sin(1);fe=exp(10);fl=log(10);fi=int(3.1415);print fs,fe,fl,fi;}' -0.841 22026.466 2.303 3 - -``` - -OFMT 设置输出数据格式是保留3位小数。 - -获得随机数: - -```sh -awk 'BEGIN{srand();fr=int(100*rand());print fr;}' -78 -awk 'BEGIN{srand();fr=int(100*rand());print fr;}' -31 -awk 'BEGIN{srand();fr=int(100*rand());print fr;}' -41 -``` - -## 字符串函数 - -| 格式 | 描述 | -| ---- | ---- | -| gsub( Ere, Repl, [ In ] ) | 除了正则表达式所有具体值被替代这点,它和 sub 函数完全一样地执行。 | -| sub( Ere, Repl, [ In ] ) | 用 Repl 参数指定的字符串替换 In 参数指定的字符串中的由 Ere 参数指定的扩展正则表达式的第一个具体值。sub 函数返回替换的数量。出现在 Repl 参数指定的字符串中的 &(和符号)由 In 参数指定的与 Ere 参数的指定的扩展正则表达式匹配的字符串替换。如果未指定 In 参数,缺省值是整个记录($0 记录变量)。 | -| index( String1, String2 ) | 在由 String1 参数指定的字符串(其中有出现 String2 指定的参数)中,返回位置,从 1 开始编号。如果 String2 参数不在 String1 参数中出现,则返回 0(零)。 | -| length [(String)] | 返回 String 参数指定的字符串的长度(字符形式)。如果未给出 String 参数,则返回整个记录的长度($0 记录变量)。 | -| blength [(String)] | 返回 String 参数指定的字符串的长度(以字节为单位)。如果未给出 String 参数,则返回整个记录的长度($0 记录变量)。 | -| substr( String, M, [ N ] ) | 返回具有 N 参数指定的字符数量子串。子串从 String 参数指定的字符串取得,其字符以 M 参数指定的位置开始。M 参数指定为将 String 参数中的第一个字符作为编号 1。如果未指定 N 参数,则子串的长度将是 M 参数指定的位置到 String 参数的末尾 的长度。 | -| match( String, Ere ) | 在 String 参数指定的字符串(Ere 参数指定的扩展正则表达式出现在其中)中返回位置(字符形式),从 1 开始编号,或如果 Ere 参数不出现,则返回 0(零)。RSTART 特殊变量设置为返回值。RLENGTH 特殊变量设置为匹配的字符串的长度,或如果未找到任何匹配,则设置为 -1(负一)。| -| split( String, A, [Ere] ) | 将 String 参数指定的参数分割为数组元素 A[1], A[2], . . ., A[n],并返回 n 变量的值。此分隔可以通过 Ere 参数指定的扩展正则表达式进行,或用当前字段分隔符(FS 特殊变量)来进行(如果没有给出 Ere 参数)。除非上下文指明特定的元素还应具有一个数字值,否则 A 数组中的元素用字符串值来创建。 | -| tolower( String ) | 返回 String 参数指定的字符串,字符串中每个大写字符将更改为小写。大写和小写的映射由当前语言环境的 LC_CTYPE 范畴定义。 | -| toupper( String ) | 返回 String 参数指定的字符串,字符串中每个小写字符将更改为大写。大写和小写的映射由当前语言环境的 LC_CTYPE 范畴定义。 | -| sprintf(Format, Expr, Expr, . . . ) | 根据 Format 参数指定的 printf 子例程格式字符串来格式化 Expr 参数指定的表达式并返回最后生成的字符串。 | - -注:Ere都可以是正则表达式。 - -** gsub,sub使用** - -```sh -awk 'BEGIN{info="this is a test2010test!";gsub(/[0-9]+/,"!",info);print info}' -this is a test!test! -``` - -在 info中查找满足正则表达式,`/[0-9]+/` 用`””`替换,并且替换后的值,赋值给info 未给info值,默认是`$0` - -** 查找字符串(index使用)** - -```sh -awk 'BEGIN{info="this is a test2010test!";print index(info,"test")?"ok":"no found";}' -ok -``` - -未找到,返回0 - -** 正则表达式匹配查找(match使用)** - -```sh -awk 'BEGIN{info="this is a test2010test!";print match(info,/[0-9]+/)?"ok":"no found";}' -ok -``` - -** 截取字符串(substr使用)** - -```sh -[wangsl@centos5 ~]$ awk 'BEGIN{info="this is a test2010test!";print substr(info,4,10);}' -s is a tes -``` - -从第 4个 字符开始,截取10个长度字符串 - -** 字符串分割(split使用)** - -```sh -awk 'BEGIN{info="this is a test";split(info,tA," ");print length(tA);for(k in tA){print k,tA[k];}}' -4 -4 test -1 this -2 is -3 a -``` - -分割info,动态创建数组tA,这里比较有意思,`awk for …in`循环,是一个无序的循环。 并不是从数组下标1…n ,因此使用时候需要注意。 - -** 格式化字符串输出(sprintf使用)** - -格式化字符串格式: - -其中格式化字符串包括两部分内容:一部分是正常字符,这些字符将按原样输出; 另一部分是格式化规定字符,以`"%"`开始,后跟一个或几个规定字符,用来确定输出内容格式。 - -| 格式 | 描述 | 格式 | 描述 | -| ---- | ---- | ---- | ---- | -| %d | 十进制有符号整数 | %u | 十进制无符号整数 | -| %f | 浮点数 | %s | 字符串 | -| %c | 单个字符 | %p | 指针的值 | -| %e | 指数形式的浮点数 | %x | %X 无符号以十六进制表示的整数 | -| %o | 无符号以八进制表示的整数 | %g | 自动选择合适的表示法 | - -```sh -awk 'BEGIN{n1=124.113;n2=-1.224;n3=1.2345; printf("%.2f,%.2u,%.2g,%X,%on",n1,n2,n3,n1,n1);}' -124.11,18446744073709551615,1.2,7C,174 -``` - -## 一般函数 - -| 格式 | 描述| -| ---- | ---- | -| close( Expression ) | 用同一个带字符串值的 Expression 参数来关闭由 print 或 printf 语句打开的或调用 getline 函数打开的文件或管道。如果文件或管道成功关闭,则返回 0;其它情况下返回非零值。如果打算写一个文件,并稍后在同一个程序中读取文件,则 close 语句是必需的。 | -| system(command ) | 执行 Command 参数指定的命令,并返回退出状态。等同于 system 子例程。| -| Expression `\|` getline [ Variable ] | 从来自 Expression 参数指定的命令的输出中通过管道传送的流中读取一个输入记录,并将该记录的值指定给 Variable 参数指定的变量。如果当前未打开将 Expression 参数的值作为其命令名称的流,则创建流。创建的流等同于调用 popen 子例程,此时 Command 参数取 Expression 参数的值且 Mode 参数设置为一个是 r 的值。只要流保留打开且 Expression 参数求得同一个字符串,则对 getline 函数的每次后续调用读取另一个记录。如果未指定 Variable 参数,则 $0 记录变量和 NF 特殊变量设置为从流读取的记录。| -| getline [ Variable ] < Expression | 从 Expression 参数指定的文件读取输入的下一个记录,并将 Variable 参数指定的变量设置为该记录的值。只要流保留打开且 Expression 参数对同一个字符串求值,则对 getline 函数的每次后续调用读取另一个记录。如果未指定 Variable 参数,则 $0 记录变量和 NF 特殊变量设置为从流读取的记录。 | -| getline [ Variable ] | 将 Variable 参数指定的变量设置为从当前输入文件读取的下一个输入记录。如果未指定 Variable 参数,则 $0 记录变量设置为该记录的值,还将设置 NF、NR 和 FNR 特殊变量。 | - -** 打开外部文件(close用法)** - -```sh -awk 'BEGIN{while("cat /etc/passwd"|getline){print $0;};close("/etc/passwd");}' -root:x:0:0:root:/root:/bin/bash -bin:x:1:1:bin:/bin:/sbin/nologin -daemon:x:2:2:daemon:/sbin:/sbin/nologin -``` - -** 逐行读取外部文件(getline使用方法)** - -```sh -awk 'BEGIN{while(getline < "/etc/passwd"){print $0;};close("/etc/passwd");}' -root:x:0:0:root:/root:/bin/bash -bin:x:1:1:bin:/bin:/sbin/nologin -daemon:x:2:2:daemon:/sbin:/sbin/nologin -``` - -```sh -awk 'BEGIN{print "Enter your name:";getline name;print name;}' -Enter your name: -chengmo -chengmo -``` - -** 调用外部应用程序(system使用方法)** - -```sh -awk 'BEGIN{b=system("ls -al");print b;}' -total 42092 -drwxr-xr-x 14 chengmo chengmo 4096 09-30 17:47 . -drwxr-xr-x 95 root root 4096 10-08 14:01 .. -``` - -b返回值,是执行结果。 - -## 时间函数 - -| 格式 | 描述| -| ---- | ---- | -| 函数名 | 说明 | -| mktime( YYYY MM dd HH MM ss[ DST]) | 生成时间格式 | -| strftime([format [, timestamp]]) | 格式化时间输出,将时间戳转为时间字符串具体格式,见下表。 | -| systime() | 得到时间戳,返回从1970年1月1日开始到当前时间(不计闰年)的整秒数 | - -** 建指定时间(mktime使用)** - -```sh -awk 'BEGIN{tstamp=mktime("2001 01 01 12 12 12");print strftime("%c",tstamp);}' -2001年01月01日 星期一 12时12分12秒 -``` - -```sh -awk 'BEGIN{tstamp1=mktime("2001 01 01 12 12 12");tstamp2=mktime("2001 02 01 0 0 0");print tstamp2-tstamp1;}' -2634468 -``` - -求2个时间段中间时间差,介绍了strftime使用方法 - -```sh -awk 'BEGIN{tstamp1=mktime("2001 01 01 12 12 12");tstamp2=systime();print tstamp2-tstamp1;}' -308201392 -``` - -** strftime日期和时间格式说明符** - -| 格式 | 描述| -| ---- | ---- | -| %a | 星期几的缩写(Sun) | -| %A | 星期几的完整写法(Sunday) | -| %b | 月名的缩写(Oct) | -| %B | 月名的完整写法(October) | -| %c | 本地日期和时间 | -| %d | 十进制日期 | -| %D | 日期 08/20/99 | -| %e | 日期,如果只有一位会补上一个空格 | -| %H | 用十进制表示24小时格式的小时 | -| %I | 用十进制表示12小时格式的小时 | -| %j | 从1月1日起一年中的第几天 | -| %m | 十进制表示的月份 | -| %M | 十进制表示的分钟 | -| %p | 12小时表示法(AM/PM) | -| %S | 十进制表示的秒 | -| %U | 十进制表示的一年中的第几个星期(星期天作为一个星期的开始) | -| %w | 十进制表示的星期几(星期天是0) | -| %W | 十进制表示的一年中的第几个星期(星期一作为一个星期的开始) | -| %x | 重新设置本地日期(08/20/99) | -| %X | 重新设置本地时间(12:00:00) | -| %y | 两位数字表示的年(99) | -| %Y | 当前月份 | -| %% | 百分号(%) | - -## 文件间隔 - -```sh -#双空间文件 -awk'1; {print“”}' -awk'BEGIN {ORS =“\ n \ n”}; 1' - -#双空间的文件已经有空行。输出文件 -#在文本行之间应该包含不超过一个空白行。 -#注意:在Unix系统上,只有CRLF(\ r \ n)的DOS行是 -#经常被视为非空白,因此仅'NF'将返回TRUE。 -awk'NF {print $ 0“\ n”}' - -#三重空间文件 -awk'1; {print“\ n”}' -``` - -## 编号和计算: - -#在每行的前面加上行号为该文件(左对齐)。 -#使用选项卡(\ t)而不是空格将保留页边距。 -awk'{print FNR'\ t“$ 0}'文件* - -#在每行的前面加上行号FOR ALL FILES TOGETHER,并带有制表符。 -awk'{print NR'\ t“$ 0}'文件* - -#编号文件的每一行(左边的数字,右对齐) -#如果从DOS命令提示符处键入,则将符号加倍。 -awk'{printf(“%5d:%s \ n”,NR,$ 0)}' - -#为文件的每一行编号,但如果行不是空白,则只打印数字 -#记住关于\ r的Unix处理的注意事项(如上所述) -awk'NF {$ 0 = ++ a“:”$ 0}; 1' -awk'{print(NF?++ a“:”:“”)$ 0}' - -#计数行(模拟“wc -l”) -awk'END {print NR}' - -#打印每行的字段总和 -awk'{s = 0; 对于(i = 1; i <= NF; i ++)s = s + $ i; 打印s}' - -#添加所有行中的所有字段并打印总和 -awk'{for(i = 1; i <= NF; i ++)s = s + $ i}; END {print s}' - -#在用绝对值替换每个字段后,每行打印一行 -awk'{for(i = 1; i <= NF; i ++)if($ i <0)$ i =-$ i; 打印}' -awk'{for(i = 1; i <= NF; i ++)$ i =($ i <0)? -$ i:$ i; 打印}' - -#在所有行中打印字段总数(“字数”) -awk'{total = total + NF}; END {打印总计}'文件 - -#打印包含“Beth”的总行数 -awk'/ Beth / {n ++}; END {print n + 0}'文件 - -#打印最大的第一个字段和包含它的行 -#旨在查找字段#1中最长的字符串 -awk'$ 1> max {max = $ 1; MAXLINE = $ 0}; END {print max,maxline}' - -#打印每行中的字段数,然后是行 -awk'{print NF':“$ 0}' - -#打印每行的最后一个字段 -awk'{print $ NF}' - -#打印最后一行的最后一个字段 -awk'{field = $ NF}; END {打印字段}' - -#打印每行超过4个字段 -awk'NF> 4' - -#打印最后一个字段值大于4的每一行 -awk'$ NF> 4' - -创建字符串: - -#创建一个特定长度的字符串(例如,生成513个空格) -awk'BEGIN {while(a ++ <513)s = s“”; 打印s}' - -#在特定字符位置插入特定长度的字符串 -#示例:在每个输入行的#6列之后插入49个空格。 -gawk --re-interval'BEGIN {while(a ++ <49)s = s“”}; {sub(/ ^。{6} /,“&”s)}; 1' - -```sh - -## 阵列创作 - -```sh - -#接下来的2个条目不是单行脚本,而是技术 -#非常方便,因此在这里值得一试。 - -#创建一个名为“月”的数组,索引数字,以便该月[1] -#是'Jan',月份[2]是'Feb',月份[3]是'Mar'等等。 -拆分(“1月2月3月4月5月6月7月8月9月10月11月12月”,月,“”) - -#创建一个名为“mdigit”的数组,用字符串索引,这样 -#mdigit [“Jan”]是1,mdigit [“Feb”]是2等等。需要“月”数组 -for(i = 1; i <= 12; i ++)mdigit [month [i]] = i - -``` - -## 文本转换和替换: - -```sh - -#在UNIX环境中:将DOS换行符(CR / LF)转换为Unix格式 -awk'{sub(/ \ r $ /,“”)}; 1'#假设每行都以Ctrl-M结尾 - -#在UNIX环境中:将Unix换行符(LF)转换为DOS格式 -awk'{sub(/ $ /,“\ r”)}; 1' - -#在DOS环境下:将Unix换行符(LF)转换为DOS格式 -awk 1 - -#在DOS环境下:将DOS换行符(CR / LF)转换为Unix格式 -#不能用DOS版本的awk完成,除了gawk: -gawk -v BINMODE =“w”'1'infile> outfile - -#使用“tr”代替。 -tr -d \ r outfile#GNU tr版本1.22或更高 - -#从每行前面删除前导空格(空格,制表符) -#左对齐所有文本 -awk'{sub(/ ^ [\ t] + /,“”)}; 1' - -#从每行末尾删除尾随空格(空格,制表符) -awk'{sub(/ [\ t] + $ /,“”)}; 1' - -#删除每行的前导和尾随空白 -awk'{gsub(/ ^ [\ t] + | [\ t] + $ /,“”)}; 1' -awk'{$ 1 = $ 1}; 1'#也会删除字段之间的额外空间 - -#在每行的开头插入5个空格(使页面偏移) -awk'{sub(/ ^ /,“”)}; 1' - -#将所有文本均匀对齐到79列宽度 -awk'{printf'%79s \ n“,$ 0}'文件* - -#将所有文字放在79个字符的宽度上 -awk'{l = length(); s = int((79-1)/ 2); printf“%”(s + l)“s \ n”,$ 0}'文件* - -#在每行上用“bar”代替(查找并替换)“foo” -awk'{sub(/ foo /,“bar”)}; 1'#只替换第一个实例 -gawk'{$ 0 = gensub(/ foo /,“bar”,4)}; 1'#只替换第四个实例 -awk'{gsub(/ foo /,“bar”)}; 1'#将所有实例替换成一行 - -#将“foo”替换为“bar”,仅用于包含“baz” -awk'/ baz / {gsub(/ foo /,“bar”)}; 1' - -#将“foo”替换为“bar”除了包含“baz”的行以外 -awk'!/ baz / {gsub(/ foo /,“bar”)}; 1' - -#将“猩红”或“红宝石”或“puce”改为“红色” -awk'{gsub(/ scarlet | ruby​​ | puce /,“red”)}; 1' - -#行的反向顺序(模拟“tac”) -awk'{a [i ++] = $ 0} END {for(j = i-1; j> = 0;)print a [j--]}'file * - -#如果一行以反斜杠结尾,则将下一行追加到它(如果失败,则失败 -#有多行以反斜杠结尾......) -awk'/ \\ $ / {sub(/ \\ $ /,“”); getline t; 打印$ 0 t; 下一个}; 1'文件* - -#打印并排序所有用户的登录名 -awk -F“:”'{print $ 1 | “sort”}'/ etc / passwd - -#按每行的相反顺序打印前两个字段 -awk'{print $ 2,$ 1}'文件 - -#切换每行的前两个字段 -awk'{temp = $ 1; $ 1 = $ 2; $ 2 = temp}'文件 - -#打印每一行,删除该行的第二个字段 -awk'{$ 2 =“”; 打印}' - -#按相反顺序打印每行的字段 -awk'{for(i = NF; i> 0; i--)printf(“%s”,$ i); print“”}'file - -#使用逗号分隔符连接每5行输入 -#字段之间 -awk'ORS = NR%5?“,”:“\ n”'文件 - -``` - -## 选择性印刷某些线条 - -```sh - -#打印前10行文件(模拟“head”的行为) -awk'NR <11' - -#打印文件的第一行(模拟“head -1”) -awk'NR> 1 {exit}; 1' - - #打印文件的最后两行(模拟“tail -2”) -awk'{y = x“\ n”$ 0; x = $ 0}; END {print y}' - -#打印文件的最后一行(模拟“tail -1”) -awk'END {print}' - -#只打印符合正则表达式的行(模拟“grep”) -awk'/ regex /' - -#只打印与正则表达式不匹配的行(模拟“grep -v”) -awk'!/ regex /' - -#打印字段#5等于“abc123”的任何行 -awk'$ 5 ==“abc123”' - -#仅打印字段#5不等于“abc123”的行 -#这也将打印少于5个字段的行。 -awk'$ 5!=“abc123”' -awk'!($ 5 ==“abc123”)' - -#将字段与正则表达式匹配 -awk'$ 7〜/ ^ [af] /'#print line if field#7 matches regex -awk'$ 7!〜/ ^ [af] /'#print line if field#7 does not match regex - -#在正则表达式之前立即打印行,但不是行 -#包含正则表达式 -awk'/ regex / {print x}; {x = $ 0}' -awk'/ regex / {print(NR == 1?“match line 1:x)}; {x = $ 0}' - -#在正则表达式之后立即打印行,但不是行 -#包含正则表达式 -awk'/ regex / {getline; print}' - -#grep for AAA和BBB和CCC(在同一行上以任意顺序) -awk'/ AAA / && / BBB / && / CCC /' - -#grep用于AAA和BBB和CCC(按此顺序) -awk'/AAA.*BBB.*CCC/' - -#只能打印65个字符或更长的行 -awk'长度> 64' - -#仅打印少于65个字符的行 -awk'长度<64' - -#从正则表达式到文件结束的文件的打印部分 -awk'/ regex /,0' -awk'/ regex /,EOF' - -#根据行号打印文件部分(第8-12行,含) -awk'NR == 8,NR == 12' - -#打印行号52 -awk'NR == 52' -awk'NR == 52 {print; exit}'#在大文件上效率更高 - -#打印两个正则表达式之间的文件部分(含) -awk'/爱荷华州/,/蒙大拿州/'#区分大小写 - -``` - -## 选择性删除某些行 - -```sh - -# 删除文件中的所有空白行(与“grep”。'相同) -awk NF -awk'/./' - -# 删除重复的连续行(模拟“uniq”) -awk'a!〜$ 0; {A = $ 0}” - -# 删除重复的,不连续的行 -awk'!a [$ 0] ++'#最简洁的脚本 -awk'!($ a中){a [$ 0]; print}'#最高效的脚本 - -# 删除重复的行 -awk '!($0 in array) { array[$0]; print }' temp - -``` - -## 统计apache日志单ip访问请求数排名(常用,解答方法10多种) - -```sh - -方法一: -awk '{++S[$1]} END {for (variable in S) print variable ,S[variable]}' access.log |sort -rn -k2 -$1为第一个域的内容。-k2 为对第二个字段排序,即对数量排序。 - -方法二: -awk '{print $1}' access.log|sort|uniq -c |sort -rn -k1 - -方法三: -sed's/- -.*$//g' access.log|sort|uniq -c|sort -rn -k1 - -``` - -## 打印行号和内容: - -```sh - -awk '{print NR":"$0}' - -输出:偶数行和奇数行到文件 - -awk '{print $0.txt > NR%2.txt}' file - -打印出奇数行内容:(三者等价) - -awk 'NR%2==1' file - -awk 'NR%2' all_file.txt - -awk 'i=!i' file - -打印出偶数行的内容:(三者等价) - -awk 'NR%2==0' file - -awk '!(NR%2)' file - -awk '!(i=!i)' file - -``` - - +# awk + +## 说明 + +**awk** awk的基本功能是在文件中搜索包含一个或多个模式的行或其他文本单元。当一行与其中一个模式匹配时,将对该行执行特殊操作。 awk中的程序与大多数其他语言中的程序不同,因为awk程序是“数据驱动的”:您描述要使用的数据,然后在找到时执行的操作。大多数其他语言都是“程序性的”。您必须详细描述该计划要采取的每个步骤。使用过程语言时,通常很难清楚地描述程序将处理的数据。出于这个原因,awk程序通常易于读写。 + +## 语法形式 + +```sh +awk [options] 'script' var=value file(s) +awk [options] -f scriptfile var=value file(s) +``` + +## 常用命令选项 + +***-F fs   *** fs指定输入分隔符,fs可以是字符串或正则表达式,如-F: +***-v var=value   *** 赋值一个用户定义变量,将外部变量传递给awk +***-f scripfile  *** 从脚本文件中读取awk命令 +***-m[fr] val   *** 对val值设置内在限制,-mf选项限制分配给val的最大块数目;-mr选项限制记录的最大数目。这两个功能是Bell实验室版awk的扩展功能,在标准awk中不适用。 + +## 模式 + +模式可以是以下任意一个: + +* /正则表达式/:使用通配符的扩展集。 +* 关系表达式:使用运算符进行操作,可以是字符串或数字的比较测试。 +* 模式匹配表达式:用运算符`~`(匹配)和`~!`(不匹配)。 +* BEGIN语句块、pattern语句块、END语句块:参见awk的工作原理 + +## 操作 + +操作由一个或多个命令、函数、表达式组成,之间由换行符或分号隔开,并位于大括号内,主要部分是: + +* 变量或数组赋值 +* 输出命令 +* 内置函数 +* 控制流语句 + +## awk脚本基本结构 + +```sh +awk 'BEGIN{ print "start" } pattern{ commands } END{ print "end" }' file +``` + +一个awk脚本通常由:BEGIN语句块、能够使用模式匹配的通用语句块、END语句块3部分组成,这三个部分是可选的。任意一个部分都可以不出现在脚本中,脚本通常是被** 单引号** 或** 双引号** 中,例如: + +```sh +awk 'BEGIN{ i=0 } { i++ } END{ print i }' filename +awk "BEGIN{ i=0 } { i++ } END{ print i }" filename +``` + +## awk的工作原理 + +```sh +awk 'BEGIN{ commands } pattern{ commands } END{ commands }' +``` + +* 第一步:执行`BEGIN{ commands }`语句块中的语句; +* 第二步:从文件或标准输入(stdin)读取一行,然后执行`pattern{ commands }`语句块,它逐行扫描文件,从第一行到最后一行重复这个过程,直到文件全部被读取完毕。 +* 第三步:当读至输入流末尾时,执行`END{ commands }`语句块。 + +**BEGIN语句块** 在awk开始从输入流中读取行** 之前** 被执行,这是一个可选的语句块,比如变量初始化、打印输出表格的表头等语句通常可以写在BEGIN语句块中。 + +**END语句块** 在awk从输入流中读取完所有的行** 之后** 即被执行,比如打印所有行的分析结果这类信息汇总都是在END语句块中完成,它也是一个可选语句块。 + +**pattern语句块** 中的通用命令是最重要的部分,它也是可选的。如果没有提供pattern语句块,则默认执行`{ print }`,即打印每一个读取到的行,awk读取的每一行都会执行该语句块。 + +## 示例 + +```sh +echo -e "A line 1nA line 2" | awk 'BEGIN{ print "Start" } { print } END{ print "End" }' +Start +A line 1 +A line 2 +End +``` + +当使用不带参数的`print`时,它就打印当前行,当`print`的参数是以逗号进行分隔时,打印时则以空格作为定界符。在awk的print语句块中双引号是被当作拼接符使用,例如: + +```sh +echo | awk '{ var1="v1"; var2="v2"; var3="v3"; print var1,var2,var3; }' +v1 v2 v3 +``` + +双引号拼接使用: + +```sh +echo | awk '{ var1="v1"; var2="v2"; var3="v3"; print var1"="var2"="var3; }' +v1=v2=v3 +``` + +{ }类似一个循环体,会对文件中的每一行进行迭代,通常变量初始化语句(如:i=0)以及打印文件头部的语句放入BEGIN语句块中,将打印的结果等语句放在END语句块中。 + +## awk内置变量(预定义变量) + +说明:[A][N][P][G]表示第一个支持变量的工具,[A]=awk、[N]=nawk、[P]=POSIXawk、[G]=gawk +可自定义变量,变量可以是字符串或数值。输入字段的内容也可以分配给变量。为了更精确地控制输出格式而不是打印通常提供的输出格式,请使用printf。 printf命令可用于指定每个项目使用的字段宽度,以及数字的各种格式选择(例如要使用的输出基数,是否打印指数,是否打印标记以及数字位数在小数点后打印)。这是通过提供一个名为格式字符串的字符串来完成的,该字符串控制打印其他参数的方式和位置。 + +```sh +** $n**当前记录的第n个字段,比如n为1表示第一个字段,n为2表示第二个字段。 +** $0**这个变量包含执行过程中当前行的文本内容。 +[N]**ARGC**命令行参数的数目。 +[G]**ARGIND**命令行中当前文件的位置(从0开始算)。 +[N]**ARGV**包含命令行参数的数组。 +[G]**CONVFMT**数字转换格式(默认值为%.6g)。 +[P]**ENVIRON**环境变量关联数组。 +[N]**ERRNO**最后一个系统错误的描述。 +[G]**FIELDWIDTHS**字段宽度列表(用空格键分隔)。 +[A]**FILENAME**当前输入文件的名。 +[P]**FNR**同NR,但相对于当前文件。 +[A]**FS(fields separator)**字段分隔符(此变量预定义为一个或多个空格或制表符)。 +[G]**IGNORECASE**如果为真,则进行忽略大小写的匹配。 +[A]**NF**表示字段数,在执行过程中对应于当前的字段数。 +[A]**NR(number of records)**表示记录数,在执行过程中对应于当前的行号。 +[A]**OFMT**数字的输出格式(默认值是%.6g)。 +[A]**OFS(output fields separator)**输出字段分隔符(默认值是一个空格)。 +[A]**ORS(output record separator)**输出记录分隔符(默认值是一个换行符)。 +[A]**RS**记录分隔符(默认是一个换行符)。 +[N]**RSTART**由match函数所匹配的字符串的第一个位置。 +[N]**RLENGTH**由match函数所匹配的字符串的长度。 +[N]**SUBSEP**数组下标分隔符(默认值是34)。 +``` + +示例 + +FS示例 + +```sh +awk FS变量用于设置每个记录的字段分割符,其可以设置为任何单个字符或者正则表达式 +FS可以更改任意次数,会保留其值直到明确更改,如果想更改字段分割符,在阅读行之前更改,固此改变会影响阅读的内容 + +awk -F 'FS''命令'文件名 +或 +awk 'BEGIN {FS="FS";}' + +用于读取具有:作为字段分割符的/etc/passwd文件:awk -f etc_pass.awk /etc/passwd +BEGIN{ +FS = ":"; +print "\tUserID\tGroupID\tHomeDirectory"; +} +{ + print $1"\t"$3"\t"$4"\t"$6; +} +END{ + print NR,"打印记录" +#NR统计打印的数目 +} + +awk OFS是awk FS变量的输出,默认情况,awk OFS是单个空格字符 + +awk -F ':' '{print $3,$4;}' /etc/passwd + +打印语句中的:,默认情况下两个参数连接为一个空间,该空间是awk OFS的值,固其值被插入到输出中的字段之间 + +awk -F ':' 'BEGIN{OFS ="=";}{print $3,$4;}' /etc/passwd +``` + +awk RS示例:记录分割符变量 + +```sh +awk RS定义了一条线,awk默认逐行读取。将信息存储在一个文件中,每个记录由两个新行隔开,每个字段用一个新行分割 + +打印姓名和第二行数字 + +cat student.awk +BEGIN { + RS =“\ n \ n”;; + FS = “\ n”个; + +} +{ + print $ 1,$ 2; +} + +awk -f student.awk student.txt + + + +``` + +```sh +echo -e "line1 f2 f3\nline2 f4 f5\nline3 f6 f7" | awk '{print "Line No:"NR", No of fields:"NF, "$0="$0, "$1="$1, "$2="$2, "$3="$3}' +Line No:1, No of fields:3 $0=line1 f2 f3 $1=line1 $2=f2 $3=f3 +Line No:2, No of fields:3 $0=line2 f4 f5 $1=line2 $2=f4 $3=f5 +Line No:3, No of fields:3 $0=line3 f6 f7 $1=line3 $2=f6 $3=f7 +``` + +使用`print $NF`可以打印出一行中的最后一个字段,使用`$(NF-1)`则是打印倒数第二个字段,其他以此类推: + +```sh +echo -e "line1 f2 f3n line2 f4 f5" | awk '{print $NF}' +f3 +f5 +``` + +```sh +echo -e "line1 f2 f3n line2 f4 f5" | awk '{print $(NF-1)}' +f2 +f4 + +``` + +打印每一行的第二和第三个字段: + +```sh +awk '{ print $2,$3 }' filename +``` + +统计文件中的行数: + +```sh +awk 'END{ print NR }' filename +``` + +以上命令只使用了END语句块,在读入每一行的时,awk会将NR更新为对应的行号,当到达最后一行NR的值就是最后一行的行号,所以END语句块中的NR就是文件的行数。 + +一个每一行中第一个字段值累加的例子: + +```sh +seq 5 | awk 'BEGIN{ sum=0; print "总和:" } { print $1"+"; sum+=$1 } END{ print "等于"; print sum }' +总和: +1+ +2+ +3+ +4+ +5+ +等于 +15 +``` + +## 将外部变量值传递给awk + +借助** `-v`选项** ,可以将外部值(并非来自stdin)传递给awk: + +```sh +VAR=10000 +echo | awk -v VARIABLE=$VAR '{ print VARIABLE }' +``` + +另一种传递外部变量方法: + +```sh +var1="aaa" +var2="bbb" +echo | awk '{ print v1,v2 }' v1=$var1 v2=$var2 +``` + +当输入来自于文件时使用: + +```sh +awk '{ print v1,v2 }' v1=$var1 v2=$var2 filename +``` + +以上方法中,变量之间用空格分隔作为awk的命令行参数跟随在BEGIN、{}和END语句块之后。 + +## 查找进程pid + +```sh +netstat -antup | grep 7770 | awk '{ print $NF NR}' | awk '{ print $1}' +``` + +## awk运算与判断 + +作为一种程序设计语言所应具有的特点之一,awk支持多种运算,这些运算与C语言提供的基本相同。awk还提供了一系列内置的运算函数(如log、sqr、cos、sin等)和一些用于对字符串进行操作(运算)的函数(如length、substr等等)。这些函数的引用大大的提高了awk的运算功能。作为对条件转移指令的一部分,关系判断是每种程序设计语言都具备的功能,awk也不例外,awk中允许进行多种测试,作为样式匹配,还提供了模式匹配表达式~(匹配)和~!(不匹配)。作为对测试的一种扩充,awk也支持用逻辑运算符。 + +## 算术运算符 + +| 运算符 | 描述 | +| ----- | ---- | +| + - | 加,减 | +| * / & | 乘,除与求余 | +| + - ! | 一元加,减和逻辑非 | +| ^** * | 求幂 | +| ++ -- | 增加或减少,作为前缀或后缀 | + +例: + +```sh +awk 'BEGIN{a="b";print a++,++a;}' +0 2 +``` + +注意:所有用作算术运算符进行操作,操作数自动转为数值,所有非数值都变为0 + +## 赋值运算符 + +| 运算符 | 描述 | +| ----- | ---- | +| = += -= *= /= %= ^=** = | 赋值语句 | + +例: + +```sh +a+=5; 等价于:a=a+5; 其它同类 +``` + +## 逻辑运算符 + +| 运算符 | 描述 | +| ----- | ---- | +| `\|\|` | 逻辑或 | +| && | 逻辑与 | + +例: + +```sh +awk 'BEGIN{a=1;b=2;print (a>5 && b<=2),(a>5 || b<=2);}' +0 1 +``` + +## 正则运算符 + +| 运算符 | 描述 | +| ----- | ---- | +| ~ ~! | 匹配正则表达式和不匹配正则表达式 | + +例: + +```sh +awk 'BEGIN{a="100testa";if(a ~ /^100*/){print "ok";}}' +ok +``` + +## 关系运算符 + +| 运算符 | 描述 | +| ----- | ---- | +| < <= > >= != == | 关系运算符 | + +例: + +```sh +awk 'BEGIN{a=11;if(a >= 9){print "ok";}}' +ok +``` + +注意:> < 可以作为字符串比较,也可以用作数值比较,关键看操作数如果是字符串就会转换为字符串比较。两个都为数字才转为数值比较。字符串比较:按照ASCII码顺序比较。 + +## 其它运算符 + +| 运算符 | 描述 | +| ----- | ---- | +| $ | 字段引用 | +| 空格 | 字符串连接符 | +| ?: | C条件表达式 | +| in | 数组中是否存在某键值 | + +例: + +```sh +awk 'BEGIN{a="b";print a=="b"?"ok":"err";}' +ok +``` + +```sh +awk 'BEGIN{a="b";arr[0]="b";arr[1]="c";print (a in arr);}' +0 +``` + +```sh +awk 'BEGIN{a="b";arr[0]="b";arr["b"]="c";print (a in arr);}' +1 +``` + +## 运算级优先级表 + +!级别越高越优先 +级别越高越优先 + +## awk高级输入输出 + +## 读取下一条记录 + +awk中`next`语句使用:在循环逐行匹配,如果遇到next,就会跳过当前行,直接忽略下面语句。而进行下一行匹配。next语句一般用于多行合并: + +```sh +cat text.txt +a +b +c +d +e + +awk 'NR%2==1{next}{print NR,$0;}' text.txt +2 b +4 d +``` + +当记录行号除以2余1,就跳过当前行。下面的`print NR,$0`也不会执行。下一行开始,程序有开始判断`NR%2`值。这个时候记录行号是`:2` ,就会执行下面语句块:`'print NR,$0'` + +分析发现需要将包含有“web”行进行跳过,然后需要将内容与下面行合并为一行: + +```sh +cat text.txt +web01[192.168.2.100] +httpdok +tomcat ok +sendmail ok +web02[192.168.2.101] +httpdok +postfix ok +web03[192.168.2.102] +mysqldok +httpd ok +0 +awk '/^web/{T=$0;next;}{print T":t"$0;}' test.txt +web01[192.168.2.100]: httpdok +web01[192.168.2.100]: tomcat ok +web01[192.168.2.100]: sendmail ok +web02[192.168.2.101]: httpdok +web02[192.168.2.101]: postfix ok +web03[192.168.2.102]: mysqldok +web03[192.168.2.102]: httpd ok +``` + +## 简单地读取一条记录 + +`awk getline`用法:输出重定向需用到`getline函数`。getline从标准输入、管道或者当前正在处理的文件之外的其他输入文件获得输入。它负责从输入获得下一行的内容,并给NF,NR和FNR等内建变量赋值。如果得到一条记录,getline函数返回1,如果到达文件的末尾就返回0,如果出现错误,例如打开文件失败,就返回-1。 + +getline语法:getline var,变量var包含了特定行的内容。 + +awk getline从整体上来说,用法说明: + +***当其左右无重定向符`|`或`<`时:** getline作用于当前文件,读入当前文件的第一行给其后跟的变量`var`或`$0`(无变量),应该注意到,由于awk在处理getline之前已经读入了一行,所以getline得到的返回结果是隔行的。 +***当其左右有重定向符`|`或`<`时:** getline则作用于定向输入文件,由于该文件是刚打开,并没有被awk读入一行,只是getline读入,那么getline返回的是该文件的第一行,而不是隔行。 + +** 示例:** + +执行linux的`date`命令,并通过管道输出给`getline`,然后再把输出赋值给自定义变量out,并打印它: + +```sh +awk 'BEGIN{ "date" | getline out; print out }' test +``` + +执行shell的date命令,并通过管道输出给getline,然后getline从管道中读取并将输入赋值给out,split函数把变量out转化成数组mon,然后打印数组mon的第二个元素: + +```sh +awk 'BEGIN{ "date" | getline out; split(out,mon); print mon[2] }' test +``` + +命令ls的输出传递给geline作为输入,循环使getline从ls的输出中读取一行,并把它打印到屏幕。这里没有输入文件,因为BEGIN块在打开输入文件前执行,所以可以忽略输入文件。 + +```sh +awk 'BEGIN{ while( "ls" | getline) print }' +``` + +## 关闭文件 + +awk中允许在程序中关闭一个输入或输出文件,方法是使用awk的close语句。 + +```sh +close("filename") +``` + +filename可以是getline打开的文件,也可以是stdin,包含文件名的变量或者getline使用的确切命令。或一个输出文件,可以是stdout,包含文件名的变量或使用管道的确切命令。 + +## 输出到一个文件 + +awk中允许用如下方式将结果输出到一个文件: + +```sh +echo | awk '{printf("hello word!n") > "datafile"}' +或 +echo | awk '{printf("hello word!n") >> "datafile"}' +``` + +## 设置字段定界符 + +默认的字段定界符是空格,可以使用`-F "定界符"`明确指定一个定界符: + +```sh +awk -F: '{ print $NF }' /etc/passwd +或 +awk 'BEGIN{ FS=":" } { print $NF }' /etc/passwd +``` + +在`BEGIN语句块`中则可以用`OFS=“定界符”`设置输出字段的定界符。 + +## 流程控制语句 + +在linux awk的while、do-while和for语句中允许使用break,continue语句来控制流程走向,也允许使用exit这样的语句来退出。break中断当前正在执行的循环并跳到循环外执行下一条语句。if 是流程选择用法。awk中,流程控制语句,语法结构,与c语言类型。有了这些语句,其实很多shell程序都可以交给awk,而且性能是非常快的。下面是各个语句用法。 + +## 条件判断语句 + +```sh +if(表达式) +语句1 +else +语句2 +``` + +格式中语句1可以是多个语句,为了方便判断和阅读,最好将多个语句用{}括起来。awk分枝结构允许嵌套,其格式为: + +```sh +if(表达式) +{语句1} +else if(表达式) +{语句2} +else +{语句3} +``` + +示例: + +```sh +awk 'BEGIN{ +test=100; +if(test>90){ +print "very good"; +} +else if(test>60){ +print "good"; +} +else{ +print "no pass"; +} +}' + +very good +``` + +每条命令语句后面可以用`;`** 分号** 结尾。 + +## 循环语句 + +### while语句 + +```sh +while(表达式) +{语句} +``` + +示例: + +```sh +awk 'BEGIN{ +test=100; +total=0; +while(i<=test){ +total+=i; +i++; +} +print total; +}' +5050 +``` + +### for循环 + +for循环有两种格式: + +格式1: + +```sh +for(变量 in 数组) +{语句} +``` + +示例: + +```sh +awk 'BEGIN{ +for(k in ENVIRON){ +print k"="ENVIRON[k]; +} + +}' +TERM=linux +G_BROKEN_FILENAMES=1 +SHLVL=1 +pwd=/root/text +... +logname=root +HOME=/root +SSH_CLIENT=192.168.1.21 53087 22 +``` + +注:ENVIRON是awk常量,是子典型数组。 + +格式2: + +```sh +for(变量;条件;表达式) +{语句} +``` + +示例: + +```sh +awk 'BEGIN{ +total=0; +for(i=0;i<=100;i++){ +total+=i; +} +print total; +}' +5050 +``` + +### do循环 + +```sh +do +{语句} while(条件) +``` + +例子: + +```sh +awk 'BEGIN{ +total=0; +i=0; +do {total+=i;i++;} while(i<=100) +print total; +}' +5050 +``` + +## 其他语句 + +***break**当 break 语句用于 while 或 for 语句时,导致退出程序循环。 +***continue**当 continue 语句用于 while 或 for 语句时,使程序循环移动到下一个迭代。 +***next**能能够导致读入下一个输入行,并返回到脚本的顶部。这可以避免对当前输入行执行其他的操作过程。 +***exit**语句使主输入循环退出并将控制转移到END,如果END存在的话。如果没有定义END规则,或在END中应用exit语句,则终止脚本的执行。 + +## 数组应用 + +数组是awk的灵魂,处理文本中最不能少的就是它的数组处理。因为数组索引(下标)可以是数字和字符串在awk中数组叫做关联数组(associative arrays)。awk 中的数组不必提前声明,也不必声明大小。数组元素用0或空字符串来初始化,这根据上下文而定。 + +## 数组的定义 + +数字做数组索引(下标): + +```sh +Array[1]="sun" +Array[2]="kai" +``` + +字符串做数组索引(下标): + +```sh +Array["first"]="www" +Array"[last"]="name" +Array["birth"]="1987" +``` + +使用中`print Array[1]`会打印出sun;使用`print Array[2]`会打印出kai;使用`print["birth"]`会得到1987。 + +** 读取数组的值** + +```sh +{ for(item in array) {print array[item]}; } #输出的顺序是随机的 +{ for(i=1;i<=len;i++) {print array[i]}; } #Len是数组的长度 +``` + +## 数组相关函数 + +** 得到数组长度:** + +```sh +awk 'BEGIN{info="it is a test";lens=split(info,tA," ");print length(tA),lens;}' +4 4 +``` + +length返回字符串以及数组长度,split进行分割字符串为数组,也会返回分割得到数组长度。 + +```sh +awk 'BEGIN{info="it is a test";split(info,tA," ");print asort(tA);}' +4 +``` + +asort对数组进行排序,返回数组长度。 + +** 输出数组内容(无序,有序输出):** + +```sh +awk 'BEGIN{info="it is a test";split(info,tA," ");for(k in tA){print k,tA[k];}}' +4 test +1 it +2 is +3 a +``` + +`for…in`输出,因为数组是关联数组,默认是无序的。所以通过`for…in`得到是无序的数组。如果需要得到有序数组,需要通过下标获得。 + +```sh +awk 'BEGIN{info="it is a test";tlen=split(info,tA," ");for(k=1;k<=tlen;k++){print k,tA[k];}}' +1 it +2 is +3 a +4 test +``` + +注意:数组下标是从1开始,与C数组不一样。 + +** 判断键值存在以及删除键值:** + +```sh +#错误的判断方法: +awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";if(tB["c"]!="1"){print "no found";};for(k in tB){print k,tB[k];}}' +no found +a a1 +b b1 +c +``` + +以上出现奇怪问题,`tB[“c”]`没有定义,但是循环时候,发现已经存在该键值,它的值为空,这里需要注意,awk数组是关联数组,只要通过数组引用它的key,就会自动创建改序列。 + +```bash +#正确判断方法: +awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";if( "c" in tB){print "ok";};for(k in tB){print k,tB[k];}}' +a a1 +b b1 +``` + +`if(key in array)`通过这种方法判断数组中是否包含`key`键值。 + +```bash +#删除键值: +awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";delete tB["a"];for(k in tB){print k,tB[k];}}' +b b1 +``` + +`delete array[key]`可以删除,对应数组`key`的,序列值。 + +## 二维、多维数组使用 + +awk的多维数组在本质上是一维数组,更确切一点,awk在存储上并不支持多维数组。awk提供了逻辑上模拟二维数组的访问方式。例如,`array[2,4]=1`这样的访问是允许的。awk使用一个特殊的字符串`SUBSEP(�34)`作为分割字段,在上面的例子中,关联数组array存储的键值实际上是2�344。 + +类似一维数组的成员测试,多维数组可以使用`if ( (i,j) in array)`这样的语法,但是下标必须放置在圆括号中。类似一维数组的循环访问,多维数组使用`for ( item in array )`这样的语法遍历数组。与一维数组不同的是,多维数组必须使用`split()`函数来访问单独的下标分量。 + +```bash +awk 'BEGIN{ +for(i=1;i<=9;i++){ +for(j=1;j<=9;j++){ +tarr[i,j]=i*j; print i,"*",j,"=",tarr[i,j]; +} +} +}' +1 * 1 = 1 +1 * 2 = 2 +1 * 3 = 3 +1 * 4 = 4 +1 * 5 = 5 +1 * 6 = 6 +... +9 * 6 = 54 +9 * 7 = 63 +9 * 8 = 72 +9 * 9 = 81 +``` + +可以通过`array[k,k2]`引用获得数组内容。 + +另一种方法: + +```bash +awk 'BEGIN{ +for(i=1;i<=9;i++){ +for(j=1;j<=9;j++){ +tarr[i,j]=i*j; +} +} +for(m in tarr){ +split(m,tarr2,SUBSEP); print tarr2[1],"*",tarr2[2],"=",tarr[m]; +} +}' +``` + +## 内置函数 + +awk内置函数,主要分以下3种类似:算数函数、字符串函数、其它一般函数、时间函数。 + +## 算术函数 + +| 格式 | 描述 | +| ---- | ---- | +| atan2( y, x ) | 返回 y/x 的反正切。 | +| cos( x ) | 返回 x 的余弦;x 是弧度。 | +| sin( x ) | 返回 x 的正弦;x 是弧度。 | +| exp( x ) | 返回 x 幂函数。 | +| log( x ) | 返回 x 的自然对数。 | +| sqrt( x ) | 返回 x 平方根。 | +| int( x ) | 返回 x 的截断至整数的值。 | +| rand( ) | 返回任意数字 n,其中 0 <= n < 1。 | +| srand( [expr] ) | 将 rand 函数的种子值设置为 Expr 参数的值,或如果省略 Expr 参数则使用某天的时间。返回先前的种子值。 | + +举例说明: + +```sh +awk 'BEGIN{OFMT="%.3f";fs=sin(1);fe=exp(10);fl=log(10);fi=int(3.1415);print fs,fe,fl,fi;}' +0.841 22026.466 2.303 3 + +``` + +OFMT 设置输出数据格式是保留3位小数。 + +获得随机数: + +```sh +awk 'BEGIN{srand();fr=int(100*rand());print fr;}' +78 +awk 'BEGIN{srand();fr=int(100*rand());print fr;}' +31 +awk 'BEGIN{srand();fr=int(100*rand());print fr;}' +41 +``` + +## 字符串函数 + +| 格式 | 描述 | +| ---- | ---- | +| gsub( Ere, Repl, [ In ] ) | 除了正则表达式所有具体值被替代这点,它和 sub 函数完全一样地执行。 | +| sub( Ere, Repl, [ In ] ) | 用 Repl 参数指定的字符串替换 In 参数指定的字符串中的由 Ere 参数指定的扩展正则表达式的第一个具体值。sub 函数返回替换的数量。出现在 Repl 参数指定的字符串中的 &(和符号)由 In 参数指定的与 Ere 参数的指定的扩展正则表达式匹配的字符串替换。如果未指定 In 参数,缺省值是整个记录($0 记录变量)。 | +| index( String1, String2 ) | 在由 String1 参数指定的字符串(其中有出现 String2 指定的参数)中,返回位置,从 1 开始编号。如果 String2 参数不在 String1 参数中出现,则返回 0(零)。 | +| length [(String)] | 返回 String 参数指定的字符串的长度(字符形式)。如果未给出 String 参数,则返回整个记录的长度($0 记录变量)。 | +| blength [(String)] | 返回 String 参数指定的字符串的长度(以字节为单位)。如果未给出 String 参数,则返回整个记录的长度($0 记录变量)。 | +| substr( String, M, [ N ] ) | 返回具有 N 参数指定的字符数量子串。子串从 String 参数指定的字符串取得,其字符以 M 参数指定的位置开始。M 参数指定为将 String 参数中的第一个字符作为编号 1。如果未指定 N 参数,则子串的长度将是 M 参数指定的位置到 String 参数的末尾 的长度。 | +| match( String, Ere ) | 在 String 参数指定的字符串(Ere 参数指定的扩展正则表达式出现在其中)中返回位置(字符形式),从 1 开始编号,或如果 Ere 参数不出现,则返回 0(零)。RSTART 特殊变量设置为返回值。RLENGTH 特殊变量设置为匹配的字符串的长度,或如果未找到任何匹配,则设置为 -1(负一)。| +| split( String, A, [Ere] ) | 将 String 参数指定的参数分割为数组元素 A[1], A[2], . . ., A[n],并返回 n 变量的值。此分隔可以通过 Ere 参数指定的扩展正则表达式进行,或用当前字段分隔符(FS 特殊变量)来进行(如果没有给出 Ere 参数)。除非上下文指明特定的元素还应具有一个数字值,否则 A 数组中的元素用字符串值来创建。 | +| tolower( String ) | 返回 String 参数指定的字符串,字符串中每个大写字符将更改为小写。大写和小写的映射由当前语言环境的 LC_CTYPE 范畴定义。 | +| toupper( String ) | 返回 String 参数指定的字符串,字符串中每个小写字符将更改为大写。大写和小写的映射由当前语言环境的 LC_CTYPE 范畴定义。 | +| sprintf(Format, Expr, Expr, . . . ) | 根据 Format 参数指定的 printf 子例程格式字符串来格式化 Expr 参数指定的表达式并返回最后生成的字符串。 | + +注:Ere都可以是正则表达式。 + +** gsub,sub使用** + +```sh +awk 'BEGIN{info="this is a test2010test!";gsub(/[0-9]+/,"!",info);print info}' +this is a test!test! +``` + +在 info中查找满足正则表达式,`/[0-9]+/` 用`””`替换,并且替换后的值,赋值给info 未给info值,默认是`$0` + +** 查找字符串(index使用)** + +```sh +awk 'BEGIN{info="this is a test2010test!";print index(info,"test")?"ok":"no found";}' +ok +``` + +未找到,返回0 + +** 正则表达式匹配查找(match使用)** + +```sh +awk 'BEGIN{info="this is a test2010test!";print match(info,/[0-9]+/)?"ok":"no found";}' +ok +``` + +** 截取字符串(substr使用)** + +```sh +[wangsl@centos5 ~]$ awk 'BEGIN{info="this is a test2010test!";print substr(info,4,10);}' +s is a tes +``` + +从第 4个 字符开始,截取10个长度字符串 + +** 字符串分割(split使用)** + +```sh +awk 'BEGIN{info="this is a test";split(info,tA," ");print length(tA);for(k in tA){print k,tA[k];}}' +4 +4 test +1 this +2 is +3 a +``` + +分割info,动态创建数组tA,这里比较有意思,`awk for …in`循环,是一个无序的循环。 并不是从数组下标1…n ,因此使用时候需要注意。 + +** 格式化字符串输出(sprintf使用)** + +格式化字符串格式: + +其中格式化字符串包括两部分内容:一部分是正常字符,这些字符将按原样输出; 另一部分是格式化规定字符,以`"%"`开始,后跟一个或几个规定字符,用来确定输出内容格式。 + +| 格式 | 描述 | 格式 | 描述 | +| ---- | ---- | ---- | ---- | +| %d | 十进制有符号整数 | %u | 十进制无符号整数 | +| %f | 浮点数 | %s | 字符串 | +| %c | 单个字符 | %p | 指针的值 | +| %e | 指数形式的浮点数 | %x | %X 无符号以十六进制表示的整数 | +| %o | 无符号以八进制表示的整数 | %g | 自动选择合适的表示法 | + +```sh +awk 'BEGIN{n1=124.113;n2=-1.224;n3=1.2345; printf("%.2f,%.2u,%.2g,%X,%on",n1,n2,n3,n1,n1);}' +124.11,18446744073709551615,1.2,7C,174 +``` + +## 一般函数 + +| 格式 | 描述| +| ---- | ---- | +| close( Expression ) | 用同一个带字符串值的 Expression 参数来关闭由 print 或 printf 语句打开的或调用 getline 函数打开的文件或管道。如果文件或管道成功关闭,则返回 0;其它情况下返回非零值。如果打算写一个文件,并稍后在同一个程序中读取文件,则 close 语句是必需的。 | +| system(command ) | 执行 Command 参数指定的命令,并返回退出状态。等同于 system 子例程。| +| Expression `\|` getline [ Variable ] | 从来自 Expression 参数指定的命令的输出中通过管道传送的流中读取一个输入记录,并将该记录的值指定给 Variable 参数指定的变量。如果当前未打开将 Expression 参数的值作为其命令名称的流,则创建流。创建的流等同于调用 popen 子例程,此时 Command 参数取 Expression 参数的值且 Mode 参数设置为一个是 r 的值。只要流保留打开且 Expression 参数求得同一个字符串,则对 getline 函数的每次后续调用读取另一个记录。如果未指定 Variable 参数,则 $0 记录变量和 NF 特殊变量设置为从流读取的记录。| +| getline [ Variable ] < Expression | 从 Expression 参数指定的文件读取输入的下一个记录,并将 Variable 参数指定的变量设置为该记录的值。只要流保留打开且 Expression 参数对同一个字符串求值,则对 getline 函数的每次后续调用读取另一个记录。如果未指定 Variable 参数,则 $0 记录变量和 NF 特殊变量设置为从流读取的记录。 | +| getline [ Variable ] | 将 Variable 参数指定的变量设置为从当前输入文件读取的下一个输入记录。如果未指定 Variable 参数,则 $0 记录变量设置为该记录的值,还将设置 NF、NR 和 FNR 特殊变量。 | + +** 打开外部文件(close用法)** + +```sh +awk 'BEGIN{while("cat /etc/passwd"|getline){print $0;};close("/etc/passwd");}' +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +``` + +** 逐行读取外部文件(getline使用方法)** + +```sh +awk 'BEGIN{while(getline < "/etc/passwd"){print $0;};close("/etc/passwd");}' +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +``` + +```sh +awk 'BEGIN{print "Enter your name:";getline name;print name;}' +Enter your name: +chengmo +chengmo +``` + +** 调用外部应用程序(system使用方法)** + +```sh +awk 'BEGIN{b=system("ls -al");print b;}' +total 42092 +drwxr-xr-x 14 chengmo chengmo 4096 09-30 17:47 . +drwxr-xr-x 95 root root 4096 10-08 14:01 .. +``` + +b返回值,是执行结果。 + +## 时间函数 + +| 格式 | 描述| +| ---- | ---- | +| 函数名 | 说明 | +| mktime( YYYY MM dd HH MM ss[ DST]) | 生成时间格式 | +| strftime([format [, timestamp]]) | 格式化时间输出,将时间戳转为时间字符串具体格式,见下表。 | +| systime() | 得到时间戳,返回从1970年1月1日开始到当前时间(不计闰年)的整秒数 | + +** 建指定时间(mktime使用)** + +```sh +awk 'BEGIN{tstamp=mktime("2001 01 01 12 12 12");print strftime("%c",tstamp);}' +2001年01月01日 星期一 12时12分12秒 +``` + +```sh +awk 'BEGIN{tstamp1=mktime("2001 01 01 12 12 12");tstamp2=mktime("2001 02 01 0 0 0");print tstamp2-tstamp1;}' +2634468 +``` + +求2个时间段中间时间差,介绍了strftime使用方法 + +```sh +awk 'BEGIN{tstamp1=mktime("2001 01 01 12 12 12");tstamp2=systime();print tstamp2-tstamp1;}' +308201392 +``` + +** strftime日期和时间格式说明符** + +| 格式 | 描述| +| ---- | ---- | +| %a | 星期几的缩写(Sun) | +| %A | 星期几的完整写法(Sunday) | +| %b | 月名的缩写(Oct) | +| %B | 月名的完整写法(October) | +| %c | 本地日期和时间 | +| %d | 十进制日期 | +| %D | 日期 08/20/99 | +| %e | 日期,如果只有一位会补上一个空格 | +| %H | 用十进制表示24小时格式的小时 | +| %I | 用十进制表示12小时格式的小时 | +| %j | 从1月1日起一年中的第几天 | +| %m | 十进制表示的月份 | +| %M | 十进制表示的分钟 | +| %p | 12小时表示法(AM/PM) | +| %S | 十进制表示的秒 | +| %U | 十进制表示的一年中的第几个星期(星期天作为一个星期的开始) | +| %w | 十进制表示的星期几(星期天是0) | +| %W | 十进制表示的一年中的第几个星期(星期一作为一个星期的开始) | +| %x | 重新设置本地日期(08/20/99) | +| %X | 重新设置本地时间(12:00:00) | +| %y | 两位数字表示的年(99) | +| %Y | 当前月份 | +| %% | 百分号(%) | + +## 文件间隔 + +```sh +#双空间文件 +awk'1; {print“”}' +awk'BEGIN {ORS =“\ n \ n”}; 1' + +#双空间的文件已经有空行。输出文件 +#在文本行之间应该包含不超过一个空白行。 +#注意:在Unix系统上,只有CRLF(\ r \ n)的DOS行是 +#经常被视为非空白,因此仅'NF'将返回TRUE。 +awk'NF {print $ 0“\ n”}' + +#三重空间文件 +awk'1; {print“\ n”}' +``` + +## 编号和计算: + +#在每行的前面加上行号为该文件(左对齐)。 +#使用选项卡(\ t)而不是空格将保留页边距。 +awk'{print FNR'\ t“$ 0}'文件* + +#在每行的前面加上行号FOR ALL FILES TOGETHER,并带有制表符。 +awk'{print NR'\ t“$ 0}'文件* + +#编号文件的每一行(左边的数字,右对齐) +#如果从DOS命令提示符处键入,则将符号加倍。 +awk'{printf(“%5d:%s \ n”,NR,$ 0)}' + +#为文件的每一行编号,但如果行不是空白,则只打印数字 +#记住关于\ r的Unix处理的注意事项(如上所述) +awk'NF {$ 0 = ++ a“:”$ 0}; 1' +awk'{print(NF?++ a“:”:“”)$ 0}' + +#计数行(模拟“wc -l”) +awk'END {print NR}' + +#打印每行的字段总和 +awk'{s = 0; 对于(i = 1; i <= NF; i ++)s = s + $ i; 打印s}' + +#添加所有行中的所有字段并打印总和 +awk'{for(i = 1; i <= NF; i ++)s = s + $ i}; END {print s}' + +#在用绝对值替换每个字段后,每行打印一行 +awk'{for(i = 1; i <= NF; i ++)if($ i <0)$ i =-$ i; 打印}' +awk'{for(i = 1; i <= NF; i ++)$ i =($ i <0)? -$ i:$ i; 打印}' + +#在所有行中打印字段总数(“字数”) +awk'{total = total + NF}; END {打印总计}'文件 + +#打印包含“Beth”的总行数 +awk'/ Beth / {n ++}; END {print n + 0}'文件 + +#打印最大的第一个字段和包含它的行 +#旨在查找字段#1中最长的字符串 +awk'$ 1> max {max = $ 1; MAXLINE = $ 0}; END {print max,maxline}' + +#打印每行中的字段数,然后是行 +awk'{print NF':“$ 0}' + +#打印每行的最后一个字段 +awk'{print $ NF}' + +#打印最后一行的最后一个字段 +awk'{field = $ NF}; END {打印字段}' + +#打印每行超过4个字段 +awk'NF> 4' + +#打印最后一个字段值大于4的每一行 +awk'$ NF> 4' + +创建字符串: + +#创建一个特定长度的字符串(例如,生成513个空格) +awk'BEGIN {while(a ++ <513)s = s“”; 打印s}' + +#在特定字符位置插入特定长度的字符串 +#示例:在每个输入行的#6列之后插入49个空格。 +gawk --re-interval'BEGIN {while(a ++ <49)s = s“”}; {sub(/ ^。{6} /,“&”s)}; 1' + +```sh + +## 阵列创作 + +```sh + +#接下来的2个条目不是单行脚本,而是技术 +#非常方便,因此在这里值得一试。 + +#创建一个名为“月”的数组,索引数字,以便该月[1] +#是'Jan',月份[2]是'Feb',月份[3]是'Mar'等等。 +拆分(“1月2月3月4月5月6月7月8月9月10月11月12月”,月,“”) + +#创建一个名为“mdigit”的数组,用字符串索引,这样 +#mdigit [“Jan”]是1,mdigit [“Feb”]是2等等。需要“月”数组 +for(i = 1; i <= 12; i ++)mdigit [month [i]] = i + +``` + +## 文本转换和替换: + +```sh + +#在UNIX环境中:将DOS换行符(CR / LF)转换为Unix格式 +awk'{sub(/ \ r $ /,“”)}; 1'#假设每行都以Ctrl-M结尾 + +#在UNIX环境中:将Unix换行符(LF)转换为DOS格式 +awk'{sub(/ $ /,“\ r”)}; 1' + +#在DOS环境下:将Unix换行符(LF)转换为DOS格式 +awk 1 + +#在DOS环境下:将DOS换行符(CR / LF)转换为Unix格式 +#不能用DOS版本的awk完成,除了gawk: +gawk -v BINMODE =“w”'1'infile> outfile + +#使用“tr”代替。 +tr -d \ r outfile#GNU tr版本1.22或更高 + +#从每行前面删除前导空格(空格,制表符) +#左对齐所有文本 +awk'{sub(/ ^ [\ t] + /,“”)}; 1' + +#从每行末尾删除尾随空格(空格,制表符) +awk'{sub(/ [\ t] + $ /,“”)}; 1' + +#删除每行的前导和尾随空白 +awk'{gsub(/ ^ [\ t] + | [\ t] + $ /,“”)}; 1' +awk'{$ 1 = $ 1}; 1'#也会删除字段之间的额外空间 + +#在每行的开头插入5个空格(使页面偏移) +awk'{sub(/ ^ /,“”)}; 1' + +#将所有文本均匀对齐到79列宽度 +awk'{printf'%79s \ n“,$ 0}'文件* + +#将所有文字放在79个字符的宽度上 +awk'{l = length(); s = int((79-1)/ 2); printf“%”(s + l)“s \ n”,$ 0}'文件* + +#在每行上用“bar”代替(查找并替换)“foo” +awk'{sub(/ foo /,“bar”)}; 1'#只替换第一个实例 +gawk'{$ 0 = gensub(/ foo /,“bar”,4)}; 1'#只替换第四个实例 +awk'{gsub(/ foo /,“bar”)}; 1'#将所有实例替换成一行 + +#将“foo”替换为“bar”,仅用于包含“baz” +awk'/ baz / {gsub(/ foo /,“bar”)}; 1' + +#将“foo”替换为“bar”除了包含“baz”的行以外 +awk'!/ baz / {gsub(/ foo /,“bar”)}; 1' + +#将“猩红”或“红宝石”或“puce”改为“红色” +awk'{gsub(/ scarlet | ruby​​ | puce /,“red”)}; 1' + +#行的反向顺序(模拟“tac”) +awk'{a [i ++] = $ 0} END {for(j = i-1; j> = 0;)print a [j--]}'file * + +#如果一行以反斜杠结尾,则将下一行追加到它(如果失败,则失败 +#有多行以反斜杠结尾......) +awk'/ \\ $ / {sub(/ \\ $ /,“”); getline t; 打印$ 0 t; 下一个}; 1'文件* + +#打印并排序所有用户的登录名 +awk -F“:”'{print $ 1 | “sort”}'/ etc / passwd + +#按每行的相反顺序打印前两个字段 +awk'{print $ 2,$ 1}'文件 + +#切换每行的前两个字段 +awk'{temp = $ 1; $ 1 = $ 2; $ 2 = temp}'文件 + +#打印每一行,删除该行的第二个字段 +awk'{$ 2 =“”; 打印}' + +#按相反顺序打印每行的字段 +awk'{for(i = NF; i> 0; i--)printf(“%s”,$ i); print“”}'file + +#使用逗号分隔符连接每5行输入 +#字段之间 +awk'ORS = NR%5?“,”:“\ n”'文件 + +``` + +## 选择性印刷某些线条 + +```sh + +#打印前10行文件(模拟“head”的行为) +awk'NR <11' + +#打印文件的第一行(模拟“head -1”) +awk'NR> 1 {exit}; 1' + + #打印文件的最后两行(模拟“tail -2”) +awk'{y = x“\ n”$ 0; x = $ 0}; END {print y}' + +#打印文件的最后一行(模拟“tail -1”) +awk'END {print}' + +#只打印符合正则表达式的行(模拟“grep”) +awk'/ regex /' + +#只打印与正则表达式不匹配的行(模拟“grep -v”) +awk'!/ regex /' + +#打印字段#5等于“abc123”的任何行 +awk'$ 5 ==“abc123”' + +#仅打印字段#5不等于“abc123”的行 +#这也将打印少于5个字段的行。 +awk'$ 5!=“abc123”' +awk'!($ 5 ==“abc123”)' + +#将字段与正则表达式匹配 +awk'$ 7〜/ ^ [af] /'#print line if field#7 matches regex +awk'$ 7!〜/ ^ [af] /'#print line if field#7 does not match regex + +#在正则表达式之前立即打印行,但不是行 +#包含正则表达式 +awk'/ regex / {print x}; {x = $ 0}' +awk'/ regex / {print(NR == 1?“match line 1:x)}; {x = $ 0}' + +#在正则表达式之后立即打印行,但不是行 +#包含正则表达式 +awk'/ regex / {getline; print}' + +#grep for AAA和BBB和CCC(在同一行上以任意顺序) +awk'/ AAA / && / BBB / && / CCC /' + +#grep用于AAA和BBB和CCC(按此顺序) +awk'/AAA.*BBB.*CCC/' + +#只能打印65个字符或更长的行 +awk'长度> 64' + +#仅打印少于65个字符的行 +awk'长度<64' + +#从正则表达式到文件结束的文件的打印部分 +awk'/ regex /,0' +awk'/ regex /,EOF' + +#根据行号打印文件部分(第8-12行,含) +awk'NR == 8,NR == 12' + +#打印行号52 +awk'NR == 52' +awk'NR == 52 {print; exit}'#在大文件上效率更高 + +#打印两个正则表达式之间的文件部分(含) +awk'/爱荷华州/,/蒙大拿州/'#区分大小写 + +``` + +## 选择性删除某些行 + +```sh + +# 删除文件中的所有空白行(与“grep”。'相同) +awk NF +awk'/./' + +# 删除重复的连续行(模拟“uniq”) +awk'a!〜$ 0; {A = $ 0}” + +# 删除重复的,不连续的行 +awk'!a [$ 0] ++'#最简洁的脚本 +awk'!($ a中){a [$ 0]; print}'#最高效的脚本 + +# 删除重复的行 +awk '!($0 in array) { array[$0]; print }' temp + +``` + +## 统计apache日志单ip访问请求数排名(常用,解答方法10多种) + +```sh + +方法一: +awk '{++S[$1]} END {for (variable in S) print variable ,S[variable]}' access.log |sort -rn -k2 +$1为第一个域的内容。-k2 为对第二个字段排序,即对数量排序。 + +方法二: +awk '{print $1}' access.log|sort|uniq -c |sort -rn -k1 + +方法三: +sed's/- -.*$//g' access.log|sort|uniq -c|sort -rn -k1 + +``` + +## 打印行号和内容: + +```sh + +awk '{print NR":"$0}' + +输出:偶数行和奇数行到文件 + +awk '{print $0.txt > NR%2.txt}' file + +打印出奇数行内容:(三者等价) + +awk 'NR%2==1' file + +awk 'NR%2' all_file.txt + +awk 'i=!i' file + +打印出偶数行的内容:(三者等价) + +awk 'NR%2==0' file + +awk '!(NR%2)' file + +awk '!(i=!i)' file + +``` + + diff --git a/LinuxCommands/axel.md b/Linux_man_cn/axel.md similarity index 100% rename from LinuxCommands/axel.md rename to Linux_man_cn/axel.md diff --git a/LinuxCommands/badblocks.md b/Linux_man_cn/badblocks.md similarity index 100% rename from LinuxCommands/badblocks.md rename to Linux_man_cn/badblocks.md diff --git a/LinuxCommands/basename.md b/Linux_man_cn/basename.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/basename.md rename to Linux_man_cn/basename.md index 0205575..610c746 --- a/LinuxCommands/basename.md +++ b/Linux_man_cn/basename.md @@ -1,6 +1,6 @@ basename === - + 打印目录或者文件的基本名称 ## 补充说明 diff --git a/LinuxCommands/batch.md b/Linux_man_cn/batch.md similarity index 100% rename from LinuxCommands/batch.md rename to Linux_man_cn/batch.md diff --git a/LinuxCommands/bc.md b/Linux_man_cn/bc.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/bc.md rename to Linux_man_cn/bc.md diff --git a/LinuxCommands/bg.md b/Linux_man_cn/bg.md similarity index 100% rename from LinuxCommands/bg.md rename to Linux_man_cn/bg.md diff --git a/LinuxCommands/bind.md b/Linux_man_cn/bind.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/bind.md rename to Linux_man_cn/bind.md index fa48bec..2949d85 --- a/LinuxCommands/bind.md +++ b/Linux_man_cn/bind.md @@ -1,6 +1,6 @@ bind === - + 显示或设置键盘按键与其相关的功能 ## 补充说明 diff --git a/LinuxCommands/blkid.md b/Linux_man_cn/blkid.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/blkid.md rename to Linux_man_cn/blkid.md index 9d93c77..91055ff --- a/LinuxCommands/blkid.md +++ b/Linux_man_cn/blkid.md @@ -1,6 +1,6 @@ blkid === - + 查看块设备的文件系统类型、LABEL、UUID等信息 ## 补充说明 diff --git a/LinuxCommands/blockdev.md b/Linux_man_cn/blockdev.md similarity index 100% rename from LinuxCommands/blockdev.md rename to Linux_man_cn/blockdev.md diff --git a/LinuxCommands/bmodinfo.md b/Linux_man_cn/bmodinfo.md similarity index 100% rename from LinuxCommands/bmodinfo.md rename to Linux_man_cn/bmodinfo.md diff --git a/LinuxCommands/builtin.md b/Linux_man_cn/builtin.md similarity index 100% rename from LinuxCommands/builtin.md rename to Linux_man_cn/builtin.md diff --git a/LinuxCommands/bunzip2.md b/Linux_man_cn/bunzip2.md similarity index 100% rename from LinuxCommands/bunzip2.md rename to Linux_man_cn/bunzip2.md diff --git a/LinuxCommands/bye.md b/Linux_man_cn/bye.md similarity index 100% rename from LinuxCommands/bye.md rename to Linux_man_cn/bye.md diff --git a/LinuxCommands/bzcat.md b/Linux_man_cn/bzcat.md similarity index 100% rename from LinuxCommands/bzcat.md rename to Linux_man_cn/bzcat.md diff --git a/LinuxCommands/bzcmp.md b/Linux_man_cn/bzcmp.md similarity index 100% rename from LinuxCommands/bzcmp.md rename to Linux_man_cn/bzcmp.md diff --git a/LinuxCommands/bzdiff.md b/Linux_man_cn/bzdiff.md similarity index 100% rename from LinuxCommands/bzdiff.md rename to Linux_man_cn/bzdiff.md diff --git a/LinuxCommands/bzgrep.md b/Linux_man_cn/bzgrep.md similarity index 100% rename from LinuxCommands/bzgrep.md rename to Linux_man_cn/bzgrep.md diff --git a/LinuxCommands/bzip2.md b/Linux_man_cn/bzip2.md similarity index 100% rename from LinuxCommands/bzip2.md rename to Linux_man_cn/bzip2.md diff --git a/LinuxCommands/bzip2recover.md b/Linux_man_cn/bzip2recover.md similarity index 100% rename from LinuxCommands/bzip2recover.md rename to Linux_man_cn/bzip2recover.md diff --git a/LinuxCommands/bzless.md b/Linux_man_cn/bzless.md similarity index 100% rename from LinuxCommands/bzless.md rename to Linux_man_cn/bzless.md diff --git a/LinuxCommands/bzmore.md b/Linux_man_cn/bzmore.md similarity index 100% rename from LinuxCommands/bzmore.md rename to Linux_man_cn/bzmore.md diff --git a/LinuxCommands/cal.md b/Linux_man_cn/cal.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/cal.md rename to Linux_man_cn/cal.md index 2346a67..3a17503 --- a/LinuxCommands/cal.md +++ b/Linux_man_cn/cal.md @@ -1,6 +1,6 @@ cal === - + 显示当前日历或指定日期的日历 ## 补充说明 diff --git a/LinuxCommands/cancel.md b/Linux_man_cn/cancel.md similarity index 100% rename from LinuxCommands/cancel.md rename to Linux_man_cn/cancel.md diff --git a/LinuxCommands/cat.md b/Linux_man_cn/cat.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/cat.md rename to Linux_man_cn/cat.md index e14a113..572ca57 --- a/LinuxCommands/cat.md +++ b/Linux_man_cn/cat.md @@ -1,6 +1,6 @@ cat === - + 连接文件并打印到标准输出设备上 ## 补充说明 diff --git a/LinuxCommands/cd.md b/Linux_man_cn/cd.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/cd.md rename to Linux_man_cn/cd.md index c676dd5..78c5adf --- a/LinuxCommands/cd.md +++ b/Linux_man_cn/cd.md @@ -1,6 +1,6 @@ cd === - + 切换用户当前工作目录 ## 补充说明 diff --git a/LinuxCommands/cdrecord.md b/Linux_man_cn/cdrecord.md similarity index 100% rename from LinuxCommands/cdrecord.md rename to Linux_man_cn/cdrecord.md diff --git a/LinuxCommands/chage.md b/Linux_man_cn/chage.md similarity index 100% rename from LinuxCommands/chage.md rename to Linux_man_cn/chage.md diff --git a/LinuxCommands/chattr.md b/Linux_man_cn/chattr.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/chattr.md rename to Linux_man_cn/chattr.md index fb1968b..9f65b5e --- a/LinuxCommands/chattr.md +++ b/Linux_man_cn/chattr.md @@ -1,6 +1,6 @@ chattr === - + 用来改变文件属性 ## 补充说明 diff --git a/LinuxCommands/chcon.md b/Linux_man_cn/chcon.md similarity index 100% rename from LinuxCommands/chcon.md rename to Linux_man_cn/chcon.md diff --git a/LinuxCommands/chfn.md b/Linux_man_cn/chfn.md similarity index 100% rename from LinuxCommands/chfn.md rename to Linux_man_cn/chfn.md diff --git a/LinuxCommands/chgrp.md b/Linux_man_cn/chgrp.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/chgrp.md rename to Linux_man_cn/chgrp.md index b5919fc..53ff3eb --- a/LinuxCommands/chgrp.md +++ b/Linux_man_cn/chgrp.md @@ -1,52 +1,52 @@ -chgrp -=== - -用来变更文件或目录的所属群组 - -## 补充说明 - -**chgrp命令** 用来改变文件或目录所属的用户组。该命令用来改变指定文件所属的用户组。其中,组名可以是用户组的id,也可以是用户组的组名。文件名可以 是由空格分开的要改变属组的文件列表,也可以是由通配符描述的文件集合。如果用户不是该文件的文件主或超级用户(root),则不能改变该文件的组。 - -在UNIX系统家族里,文件或目录权限的掌控以拥有者及所属群组来管理。您可以使用chgrp指令去变更文件与目录的所属群组,设置方式采用群组名称或群组识别码皆可。 - -### 语法 - -``` -chgrp [选项][组群][文件|目录] -``` - -### 选项 - -``` --R 递归式地改变指定目录及其下的所有子目录和文件的所属的组 --c或——changes:效果类似“-v”参数,但仅回报更改的部分; --f或--quiet或——silent:不显示错误信息; --h或--no-dereference:只对符号连接的文件作修改,而不是该其他任何相关文件; --H如果命令行参数是一个通到目录的符号链接,则遍历符号链接 --R或——recursive:递归处理,将指令目录下的所有文件及子目录一并处理; --L遍历每一个遇到的通到目录的符号链接 --P不遍历任何符号链接(默认) --v或——verbose:显示指令执行过程; ---reference=<参考文件或目录>:把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同; -``` - -### 参数 - -* 组:指定新工作名称; -* 文件:指定要改变所属组的文件列表。多个文件或者目录之间使用空格隔开。 - -### 实例 - -将`/usr/meng`及其子目录下的所有文件的用户组改为mengxin - -``` -chgrp -R mengxin /usr/meng -``` - -更改文件ah的组群所有者为newuser -``` -[root@rhel ~]# chgrp newuser ah -``` - - - +chgrp +=== + +用来变更文件或目录的所属群组 + +## 补充说明 + +**chgrp命令** 用来改变文件或目录所属的用户组。该命令用来改变指定文件所属的用户组。其中,组名可以是用户组的id,也可以是用户组的组名。文件名可以 是由空格分开的要改变属组的文件列表,也可以是由通配符描述的文件集合。如果用户不是该文件的文件主或超级用户(root),则不能改变该文件的组。 + +在UNIX系统家族里,文件或目录权限的掌控以拥有者及所属群组来管理。您可以使用chgrp指令去变更文件与目录的所属群组,设置方式采用群组名称或群组识别码皆可。 + +### 语法 + +``` +chgrp [选项][组群][文件|目录] +``` + +### 选项 + +``` +-R 递归式地改变指定目录及其下的所有子目录和文件的所属的组 +-c或——changes:效果类似“-v”参数,但仅回报更改的部分; +-f或--quiet或——silent:不显示错误信息; +-h或--no-dereference:只对符号连接的文件作修改,而不是该其他任何相关文件; +-H如果命令行参数是一个通到目录的符号链接,则遍历符号链接 +-R或——recursive:递归处理,将指令目录下的所有文件及子目录一并处理; +-L遍历每一个遇到的通到目录的符号链接 +-P不遍历任何符号链接(默认) +-v或——verbose:显示指令执行过程; +--reference=<参考文件或目录>:把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同; +``` + +### 参数 + +* 组:指定新工作名称; +* 文件:指定要改变所属组的文件列表。多个文件或者目录之间使用空格隔开。 + +### 实例 + +将`/usr/meng`及其子目录下的所有文件的用户组改为mengxin + +``` +chgrp -R mengxin /usr/meng +``` + +更改文件ah的组群所有者为newuser +``` +[root@rhel ~]# chgrp newuser ah +``` + + + diff --git a/LinuxCommands/chkconfig.md b/Linux_man_cn/chkconfig.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/chkconfig.md rename to Linux_man_cn/chkconfig.md index 439e1d0..4e51502 --- a/LinuxCommands/chkconfig.md +++ b/Linux_man_cn/chkconfig.md @@ -1,79 +1,79 @@ -chkconfig -=== - -检查或设置系统的各种服务 - -## 补充说明 - -**chkconfig命令** 检查、设置系统的各种服务。这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。 - -### 语法 - -```bash -chkconfig(选项) -``` - -### 选项 - -```bash ---add:增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据; ---del:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据; ---level<等级代号>:指定读系统服务要在哪一个执行等级中开启或关毕。 -``` -缺省的运行级,RHS用到的级别如下: - -* 0:关机 -* 1:单用户模式 -* 2:无网络支持的多用户模式 -* 3:有网络支持的多用户模式 -* 4:保留,未使用 -* 5:有网络支持有X-Window支持的多用户模式 -* 6:重新引导系统,即重启 - -对各个运行级的详细解释: - -* 0 为停机,机器关闭。 -* 1 为单用户模式,就像Win9x下的安全模式类似。 -* 2 为多用户模式,但是没有NFS支持。 -* 3 为完整的多用户模式,是标准的运行级。 -* 4 一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本 电脑的电池用尽时,可以切换到这个模式来做一些设置。 -* 5 就是X11,进到X Window系统了。 -* 6 为重启,运行init 6机器就会重启。 - -需要说明的是,level选项可以指定要查看的运行级而不一定是当前运行级。对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。 - -运行级文件: - -每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。第一行告诉chkconfig缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用`-`代替运行级。第二行对服务进行描述,可以用`\`跨行注释。 - -例如random.init包含三行: - -```bash -# chkconfig: 2345 20 80 -# description: Saves and restores system entropy pool for \ -# higher quality random number generation. -``` - -### 实例 - -```bash -chkconfig --list #列出所有的系统服务。 -chkconfig --add httpd #增加httpd服务。 -chkconfig --del httpd #删除httpd服务。 -chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态。 -chkconfig --list # 列出系统所有的服务启动情况。 -chkconfig --list mysqld # 列出mysqld服务设置情况。 -chkconfig --level 35 mysqld on # 设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭。 -chkconfig mysqld on # 设定mysqld在各等级为on,“各等级”包括2、3、4、5等级。 - -chkconfig –level redis 2345 on # 把redis在运行级别为2、3、4、5的情况下都是on(开启)的状态。 -``` - -如何增加一个服务: - -1. 服务脚本必须存放在`/etc/ini.d/`目录下; -2. `chkconfig --add servicename`在chkconfig工具服务列表中增加此服务,此时服务会被在`/etc/rc.d/rcN.d`中赋予K/S入口了; -3. `chkconfig --level 35 mysqld on`修改服务的默认启动等级。 - - - +chkconfig +=== + +检查或设置系统的各种服务 + +## 补充说明 + +**chkconfig命令** 检查、设置系统的各种服务。这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。 + +### 语法 + +```bash +chkconfig(选项) +``` + +### 选项 + +```bash +--add:增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据; +--del:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据; +--level<等级代号>:指定读系统服务要在哪一个执行等级中开启或关毕。 +``` +缺省的运行级,RHS用到的级别如下: + +* 0:关机 +* 1:单用户模式 +* 2:无网络支持的多用户模式 +* 3:有网络支持的多用户模式 +* 4:保留,未使用 +* 5:有网络支持有X-Window支持的多用户模式 +* 6:重新引导系统,即重启 + +对各个运行级的详细解释: + +* 0 为停机,机器关闭。 +* 1 为单用户模式,就像Win9x下的安全模式类似。 +* 2 为多用户模式,但是没有NFS支持。 +* 3 为完整的多用户模式,是标准的运行级。 +* 4 一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本 电脑的电池用尽时,可以切换到这个模式来做一些设置。 +* 5 就是X11,进到X Window系统了。 +* 6 为重启,运行init 6机器就会重启。 + +需要说明的是,level选项可以指定要查看的运行级而不一定是当前运行级。对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。 + +运行级文件: + +每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。第一行告诉chkconfig缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用`-`代替运行级。第二行对服务进行描述,可以用`\`跨行注释。 + +例如random.init包含三行: + +```bash +# chkconfig: 2345 20 80 +# description: Saves and restores system entropy pool for \ +# higher quality random number generation. +``` + +### 实例 + +```bash +chkconfig --list #列出所有的系统服务。 +chkconfig --add httpd #增加httpd服务。 +chkconfig --del httpd #删除httpd服务。 +chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态。 +chkconfig --list # 列出系统所有的服务启动情况。 +chkconfig --list mysqld # 列出mysqld服务设置情况。 +chkconfig --level 35 mysqld on # 设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭。 +chkconfig mysqld on # 设定mysqld在各等级为on,“各等级”包括2、3、4、5等级。 + +chkconfig –level redis 2345 on # 把redis在运行级别为2、3、4、5的情况下都是on(开启)的状态。 +``` + +如何增加一个服务: + +1. 服务脚本必须存放在`/etc/ini.d/`目录下; +2. `chkconfig --add servicename`在chkconfig工具服务列表中增加此服务,此时服务会被在`/etc/rc.d/rcN.d`中赋予K/S入口了; +3. `chkconfig --level 35 mysqld on`修改服务的默认启动等级。 + + + diff --git a/LinuxCommands/chmod.md b/Linux_man_cn/chmod.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/chmod.md rename to Linux_man_cn/chmod.md index 516847b..a172ebb --- a/LinuxCommands/chmod.md +++ b/Linux_man_cn/chmod.md @@ -1,91 +1,91 @@ -chmod -=== - -用来变更文件或目录的权限 - -## 补充说明 - -**chmod命令** 用来变更文件或目录的权限。在UNIX系统家族里,文件或目录权限的控制分别以读取、写入、执行3种一般权限来区分,另有3种特殊权限可供运用。用户可以使用chmod指令去变更文件与目录的权限,设置方式采用文字或数字代号皆可。符号连接的权限无法变更,如果用户对符号连接修改权限,其改变会作用在被连接的原始文件。 - -权限范围的表示法如下: - -`u` User,即文件或目录的拥有者; -`g` Group,即文件或目录的所属群组; -`o` Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围; -`a` All,即全部的用户,包含拥有者,所属群组以及其他用户; -`r` 读取权限,数字代号为“4”; -`w` 写入权限,数字代号为“2”; -`x` 执行或切换权限,数字代号为“1”; -`-` 不具任何权限,数字代号为“0”; -`s` 特殊功能说明:变更文件或目录的权限。 - -### 语法 - -``` -chmod(选项)(参数) -``` - -### 选项 - -```bash -u # 操作对象简称,用户user,文件或目录的所有者。 -g # 操作对象简称,同组用户group,文件或目录所属群组 -o # 操作对象简称,其它用户others -a # 操作对象简称,所有用户all,系统默认使用此项 -+ # 权限操作符,添加某些权限 -- # 权限操作符,取消某些权限 -= # 权限操作符,设置文件的权限为给定的权限 -r # 权限设定(英文),表示可读权限 -w # 权限设定(英文),表示可写权限 -x # 权限设定(英文),表示可执行权限 -- # 权限设定(英文字符),表示没有权限 -X # 权限设定,如果目标文件是可执行文件或目录,可给其设置可执行权限 -s # 权限设定,设置权限suid和sgid,使用权限组合“u+s”设定文件的用户的ID位,“g+s”设置组ID位 -t # 权限设定,只有目录或文件的所有者才可以删除目录下的文件 --c或——changes # 效果类似“-v”参数,但仅回报更改的部分,如果文件权限已经改变,显示其操作信息; --f或--quiet或——silent # 操作过程中不显示任何错误信息; --R或——recursive # 递归处理,将指令目录下的所有文件及子目录一并处理; --v或——verbose # 显示命令运行时的详细执行过程; ---reference=<参考文件或目录> # 把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同; -<权限范围>+<权限设置> # 开启权限范围的文件或目录的该选项权限设置; -<权限范围>-<权限设置> # 关闭权限范围的文件或目录的该选项权限设置; -<权限范围>=<权限设置> # 指定权限范围的文件或目录的该选项权限设置; ---help # 显示帮助信息 ---version # 显示版本信息 -``` - -### 参数 - -权限模式:指定文件的权限模式; -文件:要改变权限的文件。 - -### 知识扩展和实例 - -Linux用 户分为:拥有者、组群(Group)、其他(other),Linux系统中,预设的情況下,系统中所有的帐号与一般身份使用者,以及root的相关信 息, 都是记录在`/etc/passwd`文件中。每个人的密码则是记录在`/etc/shadow`文件下。 此外,所有的组群名称记录在`/etc/group`內! - -linux文件的用户权限的分析图 - -!linux文件的用户权限的分析图 - -例:rwx rw- r-- - -r=读取属性  //值=4 -w=写入属性  //值=2 -x=执行属性  //值=1 - -```bash -chmod u+x,g+w f01  # 为文件f01设置自己可以执行,组员可以写入的权限 -chmod u=rwx,g=rw,o=r f01 -chmod 764 f01 -chmod a+x f01   # 对文件f01的u,g,o都设置可执行属性 -``` - -文件的属主和属组属性设置 - -```bash -chown user:market f01  # 把文件f01给uesr,添加到market组 -ll -d f1 查看目录f1的属性 -``` - - - +chmod +=== + +用来变更文件或目录的权限 + +## 补充说明 + +**chmod命令** 用来变更文件或目录的权限。在UNIX系统家族里,文件或目录权限的控制分别以读取、写入、执行3种一般权限来区分,另有3种特殊权限可供运用。用户可以使用chmod指令去变更文件与目录的权限,设置方式采用文字或数字代号皆可。符号连接的权限无法变更,如果用户对符号连接修改权限,其改变会作用在被连接的原始文件。 + +权限范围的表示法如下: + +`u` User,即文件或目录的拥有者; +`g` Group,即文件或目录的所属群组; +`o` Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围; +`a` All,即全部的用户,包含拥有者,所属群组以及其他用户; +`r` 读取权限,数字代号为“4”; +`w` 写入权限,数字代号为“2”; +`x` 执行或切换权限,数字代号为“1”; +`-` 不具任何权限,数字代号为“0”; +`s` 特殊功能说明:变更文件或目录的权限。 + +### 语法 + +``` +chmod(选项)(参数) +``` + +### 选项 + +```bash +u # 操作对象简称,用户user,文件或目录的所有者。 +g # 操作对象简称,同组用户group,文件或目录所属群组 +o # 操作对象简称,其它用户others +a # 操作对象简称,所有用户all,系统默认使用此项 ++ # 权限操作符,添加某些权限 +- # 权限操作符,取消某些权限 += # 权限操作符,设置文件的权限为给定的权限 +r # 权限设定(英文),表示可读权限 +w # 权限设定(英文),表示可写权限 +x # 权限设定(英文),表示可执行权限 +- # 权限设定(英文字符),表示没有权限 +X # 权限设定,如果目标文件是可执行文件或目录,可给其设置可执行权限 +s # 权限设定,设置权限suid和sgid,使用权限组合“u+s”设定文件的用户的ID位,“g+s”设置组ID位 +t # 权限设定,只有目录或文件的所有者才可以删除目录下的文件 +-c或——changes # 效果类似“-v”参数,但仅回报更改的部分,如果文件权限已经改变,显示其操作信息; +-f或--quiet或——silent # 操作过程中不显示任何错误信息; +-R或——recursive # 递归处理,将指令目录下的所有文件及子目录一并处理; +-v或——verbose # 显示命令运行时的详细执行过程; +--reference=<参考文件或目录> # 把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同; +<权限范围>+<权限设置> # 开启权限范围的文件或目录的该选项权限设置; +<权限范围>-<权限设置> # 关闭权限范围的文件或目录的该选项权限设置; +<权限范围>=<权限设置> # 指定权限范围的文件或目录的该选项权限设置; +--help # 显示帮助信息 +--version # 显示版本信息 +``` + +### 参数 + +权限模式:指定文件的权限模式; +文件:要改变权限的文件。 + +### 知识扩展和实例 + +Linux用 户分为:拥有者、组群(Group)、其他(other),Linux系统中,预设的情況下,系统中所有的帐号与一般身份使用者,以及root的相关信 息, 都是记录在`/etc/passwd`文件中。每个人的密码则是记录在`/etc/shadow`文件下。 此外,所有的组群名称记录在`/etc/group`內! + +linux文件的用户权限的分析图 + +!linux文件的用户权限的分析图 + +例:rwx rw- r-- + +r=读取属性  //值=4 +w=写入属性  //值=2 +x=执行属性  //值=1 + +```bash +chmod u+x,g+w f01  # 为文件f01设置自己可以执行,组员可以写入的权限 +chmod u=rwx,g=rw,o=r f01 +chmod 764 f01 +chmod a+x f01   # 对文件f01的u,g,o都设置可执行属性 +``` + +文件的属主和属组属性设置 + +```bash +chown user:market f01  # 把文件f01给uesr,添加到market组 +ll -d f1 查看目录f1的属性 +``` + + + diff --git a/LinuxCommands/chown.md b/Linux_man_cn/chown.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/chown.md rename to Linux_man_cn/chown.md index 3c681dd..ac09dc1 --- a/LinuxCommands/chown.md +++ b/Linux_man_cn/chown.md @@ -1,6 +1,6 @@ chown === - + 用来变更文件或目录的拥有者或所属群组 ## 补充说明 diff --git a/LinuxCommands/chpasswd.md b/Linux_man_cn/chpasswd.md similarity index 100% rename from LinuxCommands/chpasswd.md rename to Linux_man_cn/chpasswd.md diff --git a/LinuxCommands/chroot.md b/Linux_man_cn/chroot.md similarity index 100% rename from LinuxCommands/chroot.md rename to Linux_man_cn/chroot.md diff --git a/LinuxCommands/chsh.md b/Linux_man_cn/chsh.md similarity index 100% rename from LinuxCommands/chsh.md rename to Linux_man_cn/chsh.md diff --git a/LinuxCommands/cksum.md b/Linux_man_cn/cksum.md similarity index 100% rename from LinuxCommands/cksum.md rename to Linux_man_cn/cksum.md diff --git a/LinuxCommands/clear.md b/Linux_man_cn/clear.md old mode 100755 new mode 100644 similarity index 94% rename from LinuxCommands/clear.md rename to Linux_man_cn/clear.md index 0887dfe..2f86957 --- a/LinuxCommands/clear.md +++ b/Linux_man_cn/clear.md @@ -1,6 +1,6 @@ clear === - + 清除当前屏幕终端上的任何信息 ## 补充说明 diff --git a/LinuxCommands/clock.md b/Linux_man_cn/clock.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/clock.md rename to Linux_man_cn/clock.md diff --git a/LinuxCommands/clockdiff.md b/Linux_man_cn/clockdiff.md similarity index 100% rename from LinuxCommands/clockdiff.md rename to Linux_man_cn/clockdiff.md diff --git a/LinuxCommands/cmp.md b/Linux_man_cn/cmp.md similarity index 100% rename from LinuxCommands/cmp.md rename to Linux_man_cn/cmp.md diff --git a/LinuxCommands/col.md b/Linux_man_cn/col.md similarity index 100% rename from LinuxCommands/col.md rename to Linux_man_cn/col.md diff --git a/LinuxCommands/colrm.md b/Linux_man_cn/colrm.md similarity index 100% rename from LinuxCommands/colrm.md rename to Linux_man_cn/colrm.md diff --git a/LinuxCommands/comm.md b/Linux_man_cn/comm.md similarity index 100% rename from LinuxCommands/comm.md rename to Linux_man_cn/comm.md diff --git a/LinuxCommands/command.md b/Linux_man_cn/command.md similarity index 100% rename from LinuxCommands/command.md rename to Linux_man_cn/command.md diff --git a/LinuxCommands/compress.md b/Linux_man_cn/compress.md similarity index 100% rename from LinuxCommands/compress.md rename to Linux_man_cn/compress.md diff --git a/LinuxCommands/consoletype.md b/Linux_man_cn/consoletype.md similarity index 100% rename from LinuxCommands/consoletype.md rename to Linux_man_cn/consoletype.md diff --git a/LinuxCommands/convertquota.md b/Linux_man_cn/convertquota.md similarity index 100% rename from LinuxCommands/convertquota.md rename to Linux_man_cn/convertquota.md diff --git a/LinuxCommands/cp.md b/Linux_man_cn/cp.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/cp.md rename to Linux_man_cn/cp.md index c4157de..3f4a083 --- a/LinuxCommands/cp.md +++ b/Linux_man_cn/cp.md @@ -1,152 +1,152 @@ -cp -=== - -将源文件或目录复制到目标文件或目录中 - -## 补充说明 - -**cp命令** 用来将一个或多个源文件或者目录复制到指定的目的文件或目录。它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下。cp命令还支持同时复制多个文件,当一次复制多个文件时,目标文件参数必须是一个已经存在的目录,否则将出现错误。 - -### 语法 - -``` -cp(选项)(参数) -``` - -### 选项 - -``` -用法:cp [选项]... [-T] 源文件 目标文件 - 或:cp [选项]... 源文件... 目录 - 或:cp [选项]... -t 目录 源文件... -Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. - -必选参数对长短选项同时适用。 - -a, --archive 等于-dR --preserve=all - --attributes-only 仅复制属性而不复制数据 --backup[=CONTROL 为每个已存在的目标文件创建备份 - -b 类似--backup 但不接受参数 - --copy-contents 在递归处理是复制特殊文件内容 - -d 等于--no-dereference --preserve=links,当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录; - -f, --force 强行复制文件或目录,不论目标文件或目录是否已存在强行复制文件或目录,不论目标文件或目录是否已存在 - -i, --interactive 覆盖既有文件之前先询问用户 - -H follow command-line symbolic links in SOURCE - -l, --link 对源文件建立硬连接,而非复制文件 - -L, --dereference always follow symbolic links in SOURCE - -n, --no-clobber 不要覆盖已存在的文件(使前面的 -i 选项失效) - -P, --no-dereference 不跟随源文件中的符号链接 - -p 等于--preserve=模式,所有权,时间戳 - --preserve[=属性列表 保持指定的属性(默认:模式,所有权,时间戳),如 果 - 可能保持附加属性:环境、链接、xattr 等 - --sno-preserve=属性列表 不保留指定的文件属性 - --parents 复制前在目标目录创建来源文件路径中的所有目录 - -R, -r, --recursive 递归复制目录及其子目录内的所有内容 - --reflink[=WHEN] 控制克隆/CoW 副本。请查看下面的内如。 - --remove-destination 尝试打开目标文件前先删除已存在的目的地 - 文件 (相对于 --force 选项) - --sparse=WHEN 控制创建稀疏文件的方式 - --strip-trailing-slashes 删除参数中所有源文件/目录末端的斜杠 - -s, --symbolic-link 只创建符号链接而不复制文件 - -S, --suffix=后缀 自行指定备份文件的后缀 - -t, --target-directory=目录 将所有参数指定的源文件/目录 - 复制至目标目录 - -T, --no-target-directory 将目标目录视作普通文件 - -u, --update 只在源文件比目标文件新,或目标文件 - 不存在时才进行复制 - -v, --verbose 显示详细的进行步骤 - -x, --one-file-system 不跨越文件系统进行操作 - -Z set SELinux security context of destination - file to default type - --context[=CTX] like -Z, or if CTX is specified then set the - SELinux or SMACK security context to CTX - --help 显示此帮助信息并退出 - --version 显示版本信息并退出 - -默认情况下,源文件的稀疏性仅仅通过简单的方法判断,对应的目标文件目标文件也 -被为稀疏。这是因为默认情况下使用了--sparse=auto 参数。如果明确使用 ---sparse=always 参数则不论源文件是否包含足够长的0 序列也将目标文件创文 -建为稀疏件。 -使用--sparse=never 参数禁止创建稀疏文件。 - -当指定了--reflink[=always] 参数时执行轻量化的复制,即只在数据块被修改的 -情况下才复制。如果复制失败或者同时指定了--reflink=auto,则返回标准复制模式。 - -The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. -The version control method may be selected via the --backup option or through -the VERSION_CONTROL environment variable. Here are the values: - - none, off 不进行备份(即使使用了--backup 选项) - numbered, t 备份文件加上数字进行排序 - existing, nil 若有数字的备份文件已经存在则使用数字,否则使用普通方式备份 - simple, never 永远使用普通方式备份 - -有一个特别情况:如果同时指定--force 和--backup 选项,而源文件和目标文件 -是同一个已存在的一般文件的话,cp 会将源文件备份。 -``` - -### 参数 - -* 源文件:制定源文件列表。默认情况下,cp命令不能复制目录,如果要复制目录,则必须使用`-R`选项; -* 目标文件:指定目标文件。当“源文件”为多个文件时,要求“目标文件”为指定的目录。 - -### 实例 - -下面的第一行中是 cp 命令和具体的参数(-r 是“递归”, -u 是“更新”,-v 是“详细”)。接下来的三行显示被复制文件的信息,最后一行显示命令行提示符。这样,只拷贝新的文件到我的存储设备上,我就使用 cp 的“更新”和“详细”选项。 - -通常来说,参数 `-r` 也可用更详细的风格 `--recursive`。但是以简短的方式,也可以这么连用 `-ruv`。 - -``` -cp -r -u -v /usr/men/tmp ~/men/tmp -``` - -版本备份 `--backup=numbered` 参数意思为“我要做个备份,而且是带编号的连续备份”。所以一个备份就是 1 号,第二个就是 2 号,等等。 - -```bash -$ cp --force --backup=numbered test1.py test1.py -$ ls -test1.py test1.py.~1~ test1.py.~2~ -``` - -如果把一个文件复制到一个目标文件中,而目标文件已经存在,那么,该目标文件的内容将被破坏。此命令中所有参数既可以是绝对路径名,也可以是相对路径名。通常会用到点`.`或点点`..`的形式。例如,下面的命令将指定文件复制到当前目录下: - -``` -cp ../mary/homework/assign . -``` - -所有目标文件指定的目录必须是己经存在的,cp命令不能创建目录。如果没有文件复制的权限,则系统会显示出错信息。 - -将文件file复制到目录`/usr/men/tmp`下,并改名为file1 - -``` -cp file /usr/men/tmp/file1 -``` - -将目录`/usr/men`下的所有文件及其子目录复制到目录`/usr/zh`中 - -``` -cp -r /usr/men /usr/zh -``` - -交互式地将目录`/usr/men`中的以m打头的所有.c文件复制到目录`/usr/zh`中 - -``` -cp -i /usr/men m*.c /usr/zh -``` - -我们在Linux下使用cp命令复制文件时候,有时候会需要覆盖一些同名文件,覆盖文件的时候都会有提示:需要不停的按Y来确定执行覆盖。文件数量不多还好,但是要是几百个估计按Y都要吐血了,于是折腾来半天总结了一个方法: - -``` -cp aaa/* /bbb -复制目录aaa下所有到/bbb目录下,这时如果/bbb目录下有和aaa同名的文件,需要按Y来确认并且会略过aaa目录下的子目录。 - -cp -r aaa/* /bbb -这次依然需要按Y来确认操作,但是没有忽略子目录。 - -cp -r -a aaa/* /bbb -依然需要按Y来确认操作,并且把aaa目录以及子目录和文件属性也传递到了/bbb。 - -\cp -r -a aaa/* /bbb -成功,没有提示按Y、传递了目录属性、没有略过目录。 -``` - - - +cp +=== + +将源文件或目录复制到目标文件或目录中 + +## 补充说明 + +**cp命令** 用来将一个或多个源文件或者目录复制到指定的目的文件或目录。它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下。cp命令还支持同时复制多个文件,当一次复制多个文件时,目标文件参数必须是一个已经存在的目录,否则将出现错误。 + +### 语法 + +``` +cp(选项)(参数) +``` + +### 选项 + +``` +用法:cp [选项]... [-T] 源文件 目标文件 + 或:cp [选项]... 源文件... 目录 + 或:cp [选项]... -t 目录 源文件... +Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. + +必选参数对长短选项同时适用。 + -a, --archive 等于-dR --preserve=all + --attributes-only 仅复制属性而不复制数据 --backup[=CONTROL 为每个已存在的目标文件创建备份 + -b 类似--backup 但不接受参数 + --copy-contents 在递归处理是复制特殊文件内容 + -d 等于--no-dereference --preserve=links,当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录; + -f, --force 强行复制文件或目录,不论目标文件或目录是否已存在强行复制文件或目录,不论目标文件或目录是否已存在 + -i, --interactive 覆盖既有文件之前先询问用户 + -H follow command-line symbolic links in SOURCE + -l, --link 对源文件建立硬连接,而非复制文件 + -L, --dereference always follow symbolic links in SOURCE + -n, --no-clobber 不要覆盖已存在的文件(使前面的 -i 选项失效) + -P, --no-dereference 不跟随源文件中的符号链接 + -p 等于--preserve=模式,所有权,时间戳 + --preserve[=属性列表 保持指定的属性(默认:模式,所有权,时间戳),如 果 + 可能保持附加属性:环境、链接、xattr 等 + --sno-preserve=属性列表 不保留指定的文件属性 + --parents 复制前在目标目录创建来源文件路径中的所有目录 + -R, -r, --recursive 递归复制目录及其子目录内的所有内容 + --reflink[=WHEN] 控制克隆/CoW 副本。请查看下面的内如。 + --remove-destination 尝试打开目标文件前先删除已存在的目的地 + 文件 (相对于 --force 选项) + --sparse=WHEN 控制创建稀疏文件的方式 + --strip-trailing-slashes 删除参数中所有源文件/目录末端的斜杠 + -s, --symbolic-link 只创建符号链接而不复制文件 + -S, --suffix=后缀 自行指定备份文件的后缀 + -t, --target-directory=目录 将所有参数指定的源文件/目录 + 复制至目标目录 + -T, --no-target-directory 将目标目录视作普通文件 + -u, --update 只在源文件比目标文件新,或目标文件 + 不存在时才进行复制 + -v, --verbose 显示详细的进行步骤 + -x, --one-file-system 不跨越文件系统进行操作 + -Z set SELinux security context of destination + file to default type + --context[=CTX] like -Z, or if CTX is specified then set the + SELinux or SMACK security context to CTX + --help 显示此帮助信息并退出 + --version 显示版本信息并退出 + +默认情况下,源文件的稀疏性仅仅通过简单的方法判断,对应的目标文件目标文件也 +被为稀疏。这是因为默认情况下使用了--sparse=auto 参数。如果明确使用 +--sparse=always 参数则不论源文件是否包含足够长的0 序列也将目标文件创文 +建为稀疏件。 +使用--sparse=never 参数禁止创建稀疏文件。 + +当指定了--reflink[=always] 参数时执行轻量化的复制,即只在数据块被修改的 +情况下才复制。如果复制失败或者同时指定了--reflink=auto,则返回标准复制模式。 + +The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. +The version control method may be selected via the --backup option or through +the VERSION_CONTROL environment variable. Here are the values: + + none, off 不进行备份(即使使用了--backup 选项) + numbered, t 备份文件加上数字进行排序 + existing, nil 若有数字的备份文件已经存在则使用数字,否则使用普通方式备份 + simple, never 永远使用普通方式备份 + +有一个特别情况:如果同时指定--force 和--backup 选项,而源文件和目标文件 +是同一个已存在的一般文件的话,cp 会将源文件备份。 +``` + +### 参数 + +* 源文件:制定源文件列表。默认情况下,cp命令不能复制目录,如果要复制目录,则必须使用`-R`选项; +* 目标文件:指定目标文件。当“源文件”为多个文件时,要求“目标文件”为指定的目录。 + +### 实例 + +下面的第一行中是 cp 命令和具体的参数(-r 是“递归”, -u 是“更新”,-v 是“详细”)。接下来的三行显示被复制文件的信息,最后一行显示命令行提示符。这样,只拷贝新的文件到我的存储设备上,我就使用 cp 的“更新”和“详细”选项。 + +通常来说,参数 `-r` 也可用更详细的风格 `--recursive`。但是以简短的方式,也可以这么连用 `-ruv`。 + +``` +cp -r -u -v /usr/men/tmp ~/men/tmp +``` + +版本备份 `--backup=numbered` 参数意思为“我要做个备份,而且是带编号的连续备份”。所以一个备份就是 1 号,第二个就是 2 号,等等。 + +```bash +$ cp --force --backup=numbered test1.py test1.py +$ ls +test1.py test1.py.~1~ test1.py.~2~ +``` + +如果把一个文件复制到一个目标文件中,而目标文件已经存在,那么,该目标文件的内容将被破坏。此命令中所有参数既可以是绝对路径名,也可以是相对路径名。通常会用到点`.`或点点`..`的形式。例如,下面的命令将指定文件复制到当前目录下: + +``` +cp ../mary/homework/assign . +``` + +所有目标文件指定的目录必须是己经存在的,cp命令不能创建目录。如果没有文件复制的权限,则系统会显示出错信息。 + +将文件file复制到目录`/usr/men/tmp`下,并改名为file1 + +``` +cp file /usr/men/tmp/file1 +``` + +将目录`/usr/men`下的所有文件及其子目录复制到目录`/usr/zh`中 + +``` +cp -r /usr/men /usr/zh +``` + +交互式地将目录`/usr/men`中的以m打头的所有.c文件复制到目录`/usr/zh`中 + +``` +cp -i /usr/men m*.c /usr/zh +``` + +我们在Linux下使用cp命令复制文件时候,有时候会需要覆盖一些同名文件,覆盖文件的时候都会有提示:需要不停的按Y来确定执行覆盖。文件数量不多还好,但是要是几百个估计按Y都要吐血了,于是折腾来半天总结了一个方法: + +``` +cp aaa/* /bbb +复制目录aaa下所有到/bbb目录下,这时如果/bbb目录下有和aaa同名的文件,需要按Y来确认并且会略过aaa目录下的子目录。 + +cp -r aaa/* /bbb +这次依然需要按Y来确认操作,但是没有忽略子目录。 + +cp -r -a aaa/* /bbb +依然需要按Y来确认操作,并且把aaa目录以及子目录和文件属性也传递到了/bbb。 + +\cp -r -a aaa/* /bbb +成功,没有提示按Y、传递了目录属性、没有略过目录。 +``` + + + diff --git a/LinuxCommands/cpio.md b/Linux_man_cn/cpio.md similarity index 100% rename from LinuxCommands/cpio.md rename to Linux_man_cn/cpio.md diff --git a/LinuxCommands/crontab.md b/Linux_man_cn/crontab.md similarity index 100% rename from LinuxCommands/crontab.md rename to Linux_man_cn/crontab.md diff --git a/LinuxCommands/csplit.md b/Linux_man_cn/csplit.md similarity index 100% rename from LinuxCommands/csplit.md rename to Linux_man_cn/csplit.md diff --git a/LinuxCommands/cu.md b/Linux_man_cn/cu.md similarity index 100% rename from LinuxCommands/cu.md rename to Linux_man_cn/cu.md diff --git a/LinuxCommands/cupsdisable.md b/Linux_man_cn/cupsdisable.md similarity index 100% rename from LinuxCommands/cupsdisable.md rename to Linux_man_cn/cupsdisable.md diff --git a/LinuxCommands/cupsenable.md b/Linux_man_cn/cupsenable.md similarity index 100% rename from LinuxCommands/cupsenable.md rename to Linux_man_cn/cupsenable.md diff --git a/LinuxCommands/curl.md b/Linux_man_cn/curl.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/curl.md rename to Linux_man_cn/curl.md diff --git a/LinuxCommands/cut.md b/Linux_man_cn/cut.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/cut.md rename to Linux_man_cn/cut.md index 0fb9e8e..1e64082 --- a/LinuxCommands/cut.md +++ b/Linux_man_cn/cut.md @@ -1,6 +1,6 @@ cut === - + 连接文件并打印到标准输出设备上 ## 补充说明 diff --git a/LinuxCommands/date.md b/Linux_man_cn/date.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/date.md rename to Linux_man_cn/date.md index 51acbdf..8e16871 --- a/LinuxCommands/date.md +++ b/Linux_man_cn/date.md @@ -1,170 +1,170 @@ -# **date** - -## 说明 - -**date命令** 是显示或设置系统时间与日期。 - -很多shell脚本里面需要打印不同格式的时间或日期,以及要根据时间和日期执行操作。延时通常用于脚本执行过程中提供一段等待的时间。日期可以以多种格式去打印,也可以使用命令设置固定的格式。在类UNIX系统中,日期被存储为一个整数,其大小为自世界标准时间(UTC)1970年1月1日0时0分0秒起流逝的秒数。 - -## 语法 - -用法:date [选项]... [+格式] - -或:date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] - -## 选项 - -```sh -必选参数对长短选项同时适用 - --d,--date=STRING 用STRING描述时间,而不是'NOW' - --debug 注释解析日期,并警告stderr的可疑用法 - --f,--file=DATEFILE 和--date相似,输出DATEFILE的每一行 - --I[FMT],--iso-8601[=FMT] 以ISO 8601格式输出,FMT='date'默认只适用于日期,'hour','minutes','seconds'或'ns',对于指定精度的日期和时间。 示例:2006-08-14T02:34:56-06:00 - --R,--rfc-email 以RFC 5322格式输出,例如:Mon, 14 Aug 2006 02:34:56 -0600 - --rfc-3339=FMT 以RFC 3339格式输出,FMT='date','hour','minutes','seconds'或'ns',对于指定精度的日期和时间。 示例: 2006-08-14 02:34:56-06:00 - --r,--reference=FILE 显示文件最后的修改时间 - --s,--set=STRING 以字符串方式设置时间 - --u,--utc,--universal 打印或者设置协调世界时(UTC) - -``` - -## 参数 - -给定的格式FORMAT 控制着输出,解释序列如下: - -```sh -%% 一个文字的%(即%不起到格式化的作用) -%a 当前locale 的星期名缩写(例如: 日,代表星期日) -%A 当前locale 的星期名全称 (如:星期日) -%b 当前locale 的月名缩写 (如:一,代表一月) -%B 当前locale 的月名全称 (如:一月) -%c 当前locale 的日期和时间 (如:2005年3月3日 -%C 世纪;比如 %Y,通常为省略当前年份的后两位 -%d 按月计的日期(例如:01) -%D 按月计的日期;等于%m/%d/%y -%e 按月计的日期,添加空格,等于%_d -%F 完整日期格式,等价于 %Y-%m-%d -%g ISO-8601 格式年份的最后两位 (参见%G) -%G ISO-8601 格式年份 (参见%V),一般只和 %V 结 -%h 等于%b -%H 小时(00-23) -%I 小时(00-12) -%j 按年计的日期(001-366) -%k hour, space padded ( 0..23); same as %_H -%l hour, space padded ( 1..12); same as %_I -%m month (01..12) -%M minute (00..59) -%n a newline -%N nanoseconds (000000000..999999999) -%p locale's equivalent of either AM or PM; bla -%P like %p, but lower case -%q quarter of year (1..4) -%r locale's 12-hour clock time (e.g., 11:11:04 -%R 24-hour hour and minute; same as %H:%M -%s seconds since 1970-01-01 00:00:00 UTC -%S 秒(00-60) -%t 输出制表符 Tab -%T 时间,等于%H:%M:%S -%u 星期,1 代表星期一 -%U 一年中的第几周,以周日为每星期第一天(00-53 -%V ISO-8601 格式规范下的一年中第几周,以周一 -%w 一星期中的第几日(0-6),0 代表周一 -%W 一年中的第几周,以周一为每星期第一天(00-53 -%x 当前locale 下的日期描述 (如:12/31/99) -%X 当前locale 下的时间描述 (如:23:13:48) -%y 年份最后两位数位 (00-99) -%Y 年份 -%z +hhmm 数字时区(例如,-0400) -%:z +hh:mm 数字时区(例如,-04:00) -%::z +hh:mm:ss 数字时区(例如,-04:00:00) -%:::z 数字时区带有必要的精度 (例如,-04 -%Z 按字母表排序的时区缩写 (例如,EDT) - -默认情况下,日期的数字区域以0填充 -以下可选标志可能跟在'%'后面: -- 连字符,不要填充字段 -_ 下划线,用空格填充 -0 用0填充 -^ 如果可能的话,使用大写字母 -# 尽可能使用相反的情况 - -在任何标记之后还允许一个可选的域宽度指定,它是一个十进制数字。 -作为一个可选的修饰声明,它可以是E,在可能的情况下使用本地环境关联的 -表示方式;或者是O,在可能的情况下使用本地环境关联的数字符号。 -例如: -将数字从纪元(1970-01-01)UTC开始转换为日期 -date --date='@2147483647' - -显示美国西海岸的时间(使用tzselect(1)查找TZ) -TZ='America/Los_Angeles' date - -显示下周五上午9点在美国西海岸的当地时间 -date --date='TZ="America/Los_Angeles" 09:00 next Fri' -``` - -## 实例 - -```sh -# 格式化输出并用-符号连接日期: -date +"%Y-%m-%d" -2009-12-07 - -# 输出昨天日期: -date -d "1 day ago" +"%Y-%m-%d"或date -d "yesterday" +"%Y-%m-%d"或date -d "-1 day" +"%Y-%m-%d" -2012-11-19 - -# 2秒后输出: -date -d "2 second" +"%Y-%m-%d %H:%M.%S" -2012-11-20 14:21.31 - -# 传说中的 1234567890 秒: -date -d "1970-01-01 1234567890 seconds" +"%Y-%m-%d %H:%m:%S" -2009-02-13 23:02:30 - -# 普通转格式: -date -d "2009-12-12" +"%Y/%m/%d %H:%M.%S" -2009/12/12 00:00.00 - -# apache格式转换: -date -d "Dec 5, 2009 12:00:37 AM" +"%Y-%m-%d %H:%M.%S" -2009-12-05 00:00.37 - -# 格式转换后时间游走: -date -d "Dec 5, 2009 12:00:37 AM 2 year ago" +"%Y-%m-%d %H:%M.%S" -2007-12-05 00:00.37 - -# 加减操作: -date +%Y%m%d //显示前天年月日 -date -d "+1 day" +%Y%m%d //显示前一天的日期 -date -d "-1 day" +%Y%m%d //显示后一天的日期 -date -d "-1 month" +%Y%m%d //显示上一月的日期 -date -d "+1 month" +%Y%m%d //显示下一月的日期 -date -d "-1 year" +%Y%m%d //显示前一年的日期 -date -d "+1 year" +%Y%m%d //显示下一年的日期 - -# 设定时间: -date -s //设置当前时间,只有root权限才能设置,其他只能查看 -date -s 20120523 //设置成20120523,这样会把具体时间设置成空00:00:00 -date -s 01:01:01 //设置具体时间,不会对日期做更改 -date -s "01:01:01 2012-05-23" //这样可以设置全部时间 -date -s "01:01:01 20120523" //这样可以设置全部时间 -date -s "2012-05-23 01:01:01" //这样可以设置全部时间 -date -s "20120523 01:01:01" //这样可以设置全部时间 - -# 有时需要检查一组命令花费的时间,举例: -#!/bin/bash - -start=$(date +%s) -nmap man.linuxde.net &> /dev/null - -end=$(date +%s) -difference=$(( end - start )) -echo $difference seconds. -``` +# **date** + +## 说明 + +**date命令** 是显示或设置系统时间与日期。 + +很多shell脚本里面需要打印不同格式的时间或日期,以及要根据时间和日期执行操作。延时通常用于脚本执行过程中提供一段等待的时间。日期可以以多种格式去打印,也可以使用命令设置固定的格式。在类UNIX系统中,日期被存储为一个整数,其大小为自世界标准时间(UTC)1970年1月1日0时0分0秒起流逝的秒数。 + +## 语法 + +用法:date [选项]... [+格式] + +或:date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] + +## 选项 + +```sh +必选参数对长短选项同时适用 + +-d,--date=STRING 用STRING描述时间,而不是'NOW' + --debug 注释解析日期,并警告stderr的可疑用法 + +-f,--file=DATEFILE 和--date相似,输出DATEFILE的每一行 + +-I[FMT],--iso-8601[=FMT] 以ISO 8601格式输出,FMT='date'默认只适用于日期,'hour','minutes','seconds'或'ns',对于指定精度的日期和时间。 示例:2006-08-14T02:34:56-06:00 + +-R,--rfc-email 以RFC 5322格式输出,例如:Mon, 14 Aug 2006 02:34:56 -0600 + --rfc-3339=FMT 以RFC 3339格式输出,FMT='date','hour','minutes','seconds'或'ns',对于指定精度的日期和时间。 示例: 2006-08-14 02:34:56-06:00 + +-r,--reference=FILE 显示文件最后的修改时间 + +-s,--set=STRING 以字符串方式设置时间 + +-u,--utc,--universal 打印或者设置协调世界时(UTC) + +``` + +## 参数 + +给定的格式FORMAT 控制着输出,解释序列如下: + +```sh +%% 一个文字的%(即%不起到格式化的作用) +%a 当前locale 的星期名缩写(例如: 日,代表星期日) +%A 当前locale 的星期名全称 (如:星期日) +%b 当前locale 的月名缩写 (如:一,代表一月) +%B 当前locale 的月名全称 (如:一月) +%c 当前locale 的日期和时间 (如:2005年3月3日 +%C 世纪;比如 %Y,通常为省略当前年份的后两位 +%d 按月计的日期(例如:01) +%D 按月计的日期;等于%m/%d/%y +%e 按月计的日期,添加空格,等于%_d +%F 完整日期格式,等价于 %Y-%m-%d +%g ISO-8601 格式年份的最后两位 (参见%G) +%G ISO-8601 格式年份 (参见%V),一般只和 %V 结 +%h 等于%b +%H 小时(00-23) +%I 小时(00-12) +%j 按年计的日期(001-366) +%k hour, space padded ( 0..23); same as %_H +%l hour, space padded ( 1..12); same as %_I +%m month (01..12) +%M minute (00..59) +%n a newline +%N nanoseconds (000000000..999999999) +%p locale's equivalent of either AM or PM; bla +%P like %p, but lower case +%q quarter of year (1..4) +%r locale's 12-hour clock time (e.g., 11:11:04 +%R 24-hour hour and minute; same as %H:%M +%s seconds since 1970-01-01 00:00:00 UTC +%S 秒(00-60) +%t 输出制表符 Tab +%T 时间,等于%H:%M:%S +%u 星期,1 代表星期一 +%U 一年中的第几周,以周日为每星期第一天(00-53 +%V ISO-8601 格式规范下的一年中第几周,以周一 +%w 一星期中的第几日(0-6),0 代表周一 +%W 一年中的第几周,以周一为每星期第一天(00-53 +%x 当前locale 下的日期描述 (如:12/31/99) +%X 当前locale 下的时间描述 (如:23:13:48) +%y 年份最后两位数位 (00-99) +%Y 年份 +%z +hhmm 数字时区(例如,-0400) +%:z +hh:mm 数字时区(例如,-04:00) +%::z +hh:mm:ss 数字时区(例如,-04:00:00) +%:::z 数字时区带有必要的精度 (例如,-04 +%Z 按字母表排序的时区缩写 (例如,EDT) + +默认情况下,日期的数字区域以0填充 +以下可选标志可能跟在'%'后面: +- 连字符,不要填充字段 +_ 下划线,用空格填充 +0 用0填充 +^ 如果可能的话,使用大写字母 +# 尽可能使用相反的情况 + +在任何标记之后还允许一个可选的域宽度指定,它是一个十进制数字。 +作为一个可选的修饰声明,它可以是E,在可能的情况下使用本地环境关联的 +表示方式;或者是O,在可能的情况下使用本地环境关联的数字符号。 +例如: +将数字从纪元(1970-01-01)UTC开始转换为日期 +date --date='@2147483647' + +显示美国西海岸的时间(使用tzselect(1)查找TZ) +TZ='America/Los_Angeles' date + +显示下周五上午9点在美国西海岸的当地时间 +date --date='TZ="America/Los_Angeles" 09:00 next Fri' +``` + +## 实例 + +```sh +# 格式化输出并用-符号连接日期: +date +"%Y-%m-%d" +2009-12-07 + +# 输出昨天日期: +date -d "1 day ago" +"%Y-%m-%d"或date -d "yesterday" +"%Y-%m-%d"或date -d "-1 day" +"%Y-%m-%d" +2012-11-19 + +# 2秒后输出: +date -d "2 second" +"%Y-%m-%d %H:%M.%S" +2012-11-20 14:21.31 + +# 传说中的 1234567890 秒: +date -d "1970-01-01 1234567890 seconds" +"%Y-%m-%d %H:%m:%S" +2009-02-13 23:02:30 + +# 普通转格式: +date -d "2009-12-12" +"%Y/%m/%d %H:%M.%S" +2009/12/12 00:00.00 + +# apache格式转换: +date -d "Dec 5, 2009 12:00:37 AM" +"%Y-%m-%d %H:%M.%S" +2009-12-05 00:00.37 + +# 格式转换后时间游走: +date -d "Dec 5, 2009 12:00:37 AM 2 year ago" +"%Y-%m-%d %H:%M.%S" +2007-12-05 00:00.37 + +# 加减操作: +date +%Y%m%d //显示前天年月日 +date -d "+1 day" +%Y%m%d //显示前一天的日期 +date -d "-1 day" +%Y%m%d //显示后一天的日期 +date -d "-1 month" +%Y%m%d //显示上一月的日期 +date -d "+1 month" +%Y%m%d //显示下一月的日期 +date -d "-1 year" +%Y%m%d //显示前一年的日期 +date -d "+1 year" +%Y%m%d //显示下一年的日期 + +# 设定时间: +date -s //设置当前时间,只有root权限才能设置,其他只能查看 +date -s 20120523 //设置成20120523,这样会把具体时间设置成空00:00:00 +date -s 01:01:01 //设置具体时间,不会对日期做更改 +date -s "01:01:01 2012-05-23" //这样可以设置全部时间 +date -s "01:01:01 20120523" //这样可以设置全部时间 +date -s "2012-05-23 01:01:01" //这样可以设置全部时间 +date -s "20120523 01:01:01" //这样可以设置全部时间 + +# 有时需要检查一组命令花费的时间,举例: +#!/bin/bash + +start=$(date +%s) +nmap man.linuxde.net &> /dev/null + +end=$(date +%s) +difference=$(( end - start )) +echo $difference seconds. +``` diff --git a/LinuxCommands/dd.md b/Linux_man_cn/dd.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/dd.md rename to Linux_man_cn/dd.md diff --git a/LinuxCommands/declare.md b/Linux_man_cn/declare.md similarity index 100% rename from LinuxCommands/declare.md rename to Linux_man_cn/declare.md diff --git a/LinuxCommands/depmod.md b/Linux_man_cn/depmod.md similarity index 100% rename from LinuxCommands/depmod.md rename to Linux_man_cn/depmod.md diff --git a/LinuxCommands/df.md b/Linux_man_cn/df.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/df.md rename to Linux_man_cn/df.md index 7356441..0514e37 --- a/LinuxCommands/df.md +++ b/Linux_man_cn/df.md @@ -1,6 +1,6 @@ df === - + 显示磁盘的相关信息 ## 补充说明 diff --git a/LinuxCommands/dhclient.md b/Linux_man_cn/dhclient.md similarity index 100% rename from LinuxCommands/dhclient.md rename to Linux_man_cn/dhclient.md diff --git a/LinuxCommands/dhcpd.md b/Linux_man_cn/dhcpd.md similarity index 100% rename from LinuxCommands/dhcpd.md rename to Linux_man_cn/dhcpd.md diff --git a/LinuxCommands/dhcrelay.md b/Linux_man_cn/dhcrelay.md similarity index 100% rename from LinuxCommands/dhcrelay.md rename to Linux_man_cn/dhcrelay.md diff --git a/LinuxCommands/diff.md b/Linux_man_cn/diff.md similarity index 100% rename from LinuxCommands/diff.md rename to Linux_man_cn/diff.md diff --git a/LinuxCommands/diff3.md b/Linux_man_cn/diff3.md similarity index 100% rename from LinuxCommands/diff3.md rename to Linux_man_cn/diff3.md diff --git a/LinuxCommands/diffstat.md b/Linux_man_cn/diffstat.md similarity index 100% rename from LinuxCommands/diffstat.md rename to Linux_man_cn/diffstat.md diff --git a/LinuxCommands/dig.md b/Linux_man_cn/dig.md similarity index 100% rename from LinuxCommands/dig.md rename to Linux_man_cn/dig.md diff --git a/LinuxCommands/dircolors.md b/Linux_man_cn/dircolors.md similarity index 100% rename from LinuxCommands/dircolors.md rename to Linux_man_cn/dircolors.md diff --git a/LinuxCommands/dirname.md b/Linux_man_cn/dirname.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/dirname.md rename to Linux_man_cn/dirname.md index 1a75c15..652dbe8 --- a/LinuxCommands/dirname.md +++ b/Linux_man_cn/dirname.md @@ -1,6 +1,6 @@ dirname === - + 去除文件名中的非目录部分 ## 补充说明 diff --git a/LinuxCommands/dirs.md b/Linux_man_cn/dirs.md similarity index 100% rename from LinuxCommands/dirs.md rename to Linux_man_cn/dirs.md diff --git a/LinuxCommands/dmesg.md b/Linux_man_cn/dmesg.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/dmesg.md rename to Linux_man_cn/dmesg.md index be21352..bdbbc0f --- a/LinuxCommands/dmesg.md +++ b/Linux_man_cn/dmesg.md @@ -1,53 +1,53 @@ -dmesg -=== - -显示Linux系统启动信息 - -## 补充说明 - -**dmesg命令** 被用于检查和控制内核的环形缓冲区。kernel会将开机信息存储在ring buffer中。您若是开机时来不及查看信息,可利用dmesg来查看。开机信息保存在`/var/log/dmesg`文件里。 - -### 语法 - -``` -dmesg(选项) -``` - -### 选项 - -``` --c:显示信息后,清除ring buffer中的内容; --s<缓冲区大小>:预设置为8196,刚好等于ring buffer的大小; --n:设置记录信息的层级。 -``` - -### 实例 - -``` -[root@localhost ~]# dmesg | head -Linux version 2.6.18-348.6.1.el5 (mockbuild@builder17.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Tue May 21 15:34:22 EDT 2013 -BIOS-provided physical RAM map: - BIOS-e820: 0000000000010000 - 000000000009f400 (usable) - BIOS-e820: 000000000009f400 - 00000000000a0000 (reserved) - BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved) - BIOS-e820: 0000000000100000 - 000000007f590000 (usable) - BIOS-e820: 000000007f590000 - 000000007f5e3000 (ACPI NVS) - BIOS-e820: 000000007f5e3000 - 000000007f5f0000 (ACPI data) - BIOS-e820: 000000007f5f0000 - 000000007f600000 (reserved) - BIOS-e820: 00000000e0000000 - 00000000e8000000 (reserved) -``` - -查看硬盘基础信息 - -```bash -dmesg | grep sda - -[ 2.442555] sd 0:0:0:0: [sda] 488281250 512-byte logical blocks: (250 GB/232 GiB) -[ 2.442590] sd 0:0:0:0: [sda] Write Protect is off -[ 2.442592] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00 -[ 2.442607] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA -[ 2.447533] sda: sda1 -[ 2.448503] sd 0:0:0:0: [sda] Attached SCSI disk -``` - - +dmesg +=== + +显示Linux系统启动信息 + +## 补充说明 + +**dmesg命令** 被用于检查和控制内核的环形缓冲区。kernel会将开机信息存储在ring buffer中。您若是开机时来不及查看信息,可利用dmesg来查看。开机信息保存在`/var/log/dmesg`文件里。 + +### 语法 + +``` +dmesg(选项) +``` + +### 选项 + +``` +-c:显示信息后,清除ring buffer中的内容; +-s<缓冲区大小>:预设置为8196,刚好等于ring buffer的大小; +-n:设置记录信息的层级。 +``` + +### 实例 + +``` +[root@localhost ~]# dmesg | head +Linux version 2.6.18-348.6.1.el5 (mockbuild@builder17.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Tue May 21 15:34:22 EDT 2013 +BIOS-provided physical RAM map: + BIOS-e820: 0000000000010000 - 000000000009f400 (usable) + BIOS-e820: 000000000009f400 - 00000000000a0000 (reserved) + BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved) + BIOS-e820: 0000000000100000 - 000000007f590000 (usable) + BIOS-e820: 000000007f590000 - 000000007f5e3000 (ACPI NVS) + BIOS-e820: 000000007f5e3000 - 000000007f5f0000 (ACPI data) + BIOS-e820: 000000007f5f0000 - 000000007f600000 (reserved) + BIOS-e820: 00000000e0000000 - 00000000e8000000 (reserved) +``` + +查看硬盘基础信息 + +```bash +dmesg | grep sda + +[ 2.442555] sd 0:0:0:0: [sda] 488281250 512-byte logical blocks: (250 GB/232 GiB) +[ 2.442590] sd 0:0:0:0: [sda] Write Protect is off +[ 2.442592] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00 +[ 2.442607] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA +[ 2.447533] sda: sda1 +[ 2.448503] sd 0:0:0:0: [sda] Attached SCSI disk +``` + + diff --git a/LinuxCommands/dmidecode.md b/Linux_man_cn/dmidecode.md similarity index 100% rename from LinuxCommands/dmidecode.md rename to Linux_man_cn/dmidecode.md diff --git a/LinuxCommands/dnf.md b/Linux_man_cn/dnf.md similarity index 100% rename from LinuxCommands/dnf.md rename to Linux_man_cn/dnf.md diff --git a/LinuxCommands/dnsdomainname.md b/Linux_man_cn/dnsdomainname.md similarity index 100% rename from LinuxCommands/dnsdomainname.md rename to Linux_man_cn/dnsdomainname.md diff --git a/LinuxCommands/domainname.md b/Linux_man_cn/domainname.md similarity index 100% rename from LinuxCommands/domainname.md rename to Linux_man_cn/domainname.md diff --git a/LinuxCommands/dos2unix.md b/Linux_man_cn/dos2unix.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/dos2unix.md rename to Linux_man_cn/dos2unix.md index 4f4939d..227af3d --- a/LinuxCommands/dos2unix.md +++ b/Linux_man_cn/dos2unix.md @@ -1,6 +1,6 @@ dos2unix === - + 将DOS格式文本文件转换成Unix格式 ## 补充说明 diff --git a/LinuxCommands/dpkg-deb.md b/Linux_man_cn/dpkg-deb.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/dpkg-deb.md rename to Linux_man_cn/dpkg-deb.md index 8da7ee4..a0490bd --- a/LinuxCommands/dpkg-deb.md +++ b/Linux_man_cn/dpkg-deb.md @@ -1,6 +1,6 @@ dpkg-deb === - + Debian Linux下的软件包管理工具 ## 补充说明 diff --git a/LinuxCommands/dpkg-divert.md b/Linux_man_cn/dpkg-divert.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/dpkg-divert.md rename to Linux_man_cn/dpkg-divert.md index 3f89f17..7ab25de --- a/LinuxCommands/dpkg-divert.md +++ b/Linux_man_cn/dpkg-divert.md @@ -1,6 +1,6 @@ dpkg-divert === - + Debian Linux中创建并管理一个转向列表 ## 补充说明 diff --git a/LinuxCommands/dpkg-preconfigure.md b/Linux_man_cn/dpkg-preconfigure.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/dpkg-preconfigure.md rename to Linux_man_cn/dpkg-preconfigure.md index faca15f..cd4b509 --- a/LinuxCommands/dpkg-preconfigure.md +++ b/Linux_man_cn/dpkg-preconfigure.md @@ -1,6 +1,6 @@ dpkg-preconfigure === - + Debian Linux中软件包安装之前询问问题 ## 补充说明 diff --git a/LinuxCommands/dpkg-query.md b/Linux_man_cn/dpkg-query.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/dpkg-query.md rename to Linux_man_cn/dpkg-query.md index ab2b3a2..cdc4100 --- a/LinuxCommands/dpkg-query.md +++ b/Linux_man_cn/dpkg-query.md @@ -1,6 +1,6 @@ dpkg-query === - + Debian Linux中软件包的查询工具 ## 补充说明 diff --git a/LinuxCommands/dpkg-reconfigure.md b/Linux_man_cn/dpkg-reconfigure.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/dpkg-reconfigure.md rename to Linux_man_cn/dpkg-reconfigure.md index 145887d..fbfe476 --- a/LinuxCommands/dpkg-reconfigure.md +++ b/Linux_man_cn/dpkg-reconfigure.md @@ -1,6 +1,6 @@ dpkg-reconfigure === - + Debian Linux中重新配制一个已经安装的软件包 ## 补充说明 diff --git a/LinuxCommands/dpkg-split.md b/Linux_man_cn/dpkg-split.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/dpkg-split.md rename to Linux_man_cn/dpkg-split.md index efba150..7e2e503 --- a/LinuxCommands/dpkg-split.md +++ b/Linux_man_cn/dpkg-split.md @@ -1,6 +1,6 @@ dpkg-split === - + Debian Linux中将大软件包分割成小包 ## 补充说明 diff --git a/LinuxCommands/dpkg-statoverride.md b/Linux_man_cn/dpkg-statoverride.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/dpkg-statoverride.md rename to Linux_man_cn/dpkg-statoverride.md index 0407a2a..d2cccc9 --- a/LinuxCommands/dpkg-statoverride.md +++ b/Linux_man_cn/dpkg-statoverride.md @@ -1,6 +1,6 @@ dpkg-statoverride === - + Debian Linux中覆盖文件的所有权和模式 ## 补充说明 diff --git a/LinuxCommands/dpkg-trigger.md b/Linux_man_cn/dpkg-trigger.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/dpkg-trigger.md rename to Linux_man_cn/dpkg-trigger.md index a5096d8..06f4b63 --- a/LinuxCommands/dpkg-trigger.md +++ b/Linux_man_cn/dpkg-trigger.md @@ -1,6 +1,6 @@ dpkg-trigger === - + Debian Linux下的软件包触发器 ## 补充说明 diff --git a/LinuxCommands/dpkg.md b/Linux_man_cn/dpkg.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/dpkg.md rename to Linux_man_cn/dpkg.md index 3261fc0..744fa99 --- a/LinuxCommands/dpkg.md +++ b/Linux_man_cn/dpkg.md @@ -1,6 +1,6 @@ dpkg === - + Debian Linux系统上安装、创建和管理软件包 ## 补充说明 diff --git a/LinuxCommands/dris.md b/Linux_man_cn/dris.md similarity index 100% rename from LinuxCommands/dris.md rename to Linux_man_cn/dris.md diff --git a/LinuxCommands/dstat.md b/Linux_man_cn/dstat.md similarity index 100% rename from LinuxCommands/dstat.md rename to Linux_man_cn/dstat.md diff --git a/LinuxCommands/du.md b/Linux_man_cn/du.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/du.md rename to Linux_man_cn/du.md index 5c46279..d2aeba0 --- a/LinuxCommands/du.md +++ b/Linux_man_cn/du.md @@ -1,6 +1,6 @@ du === - + 显示每个文件和目录的磁盘使用空间 ## 补充说明 diff --git a/LinuxCommands/dump.md b/Linux_man_cn/dump.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/dump.md rename to Linux_man_cn/dump.md index 5c8264b..44bf464 --- a/LinuxCommands/dump.md +++ b/Linux_man_cn/dump.md @@ -1,6 +1,6 @@ dump === - + 用于备份ext2或者ext3文件系统 ## 补充说明 diff --git a/LinuxCommands/dumpe2fs.md b/Linux_man_cn/dumpe2fs.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/dumpe2fs.md rename to Linux_man_cn/dumpe2fs.md diff --git a/LinuxCommands/e2fsck.md b/Linux_man_cn/e2fsck.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/e2fsck.md rename to Linux_man_cn/e2fsck.md diff --git a/LinuxCommands/e2label.md b/Linux_man_cn/e2label.md similarity index 100% rename from LinuxCommands/e2label.md rename to Linux_man_cn/e2label.md diff --git a/LinuxCommands/echo.md b/Linux_man_cn/echo.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/echo.md rename to Linux_man_cn/echo.md diff --git a/LinuxCommands/ed.md b/Linux_man_cn/ed.md similarity index 100% rename from LinuxCommands/ed.md rename to Linux_man_cn/ed.md diff --git a/LinuxCommands/edquota.md b/Linux_man_cn/edquota.md similarity index 100% rename from LinuxCommands/edquota.md rename to Linux_man_cn/edquota.md diff --git a/LinuxCommands/egrep.md b/Linux_man_cn/egrep.md similarity index 100% rename from LinuxCommands/egrep.md rename to Linux_man_cn/egrep.md diff --git a/LinuxCommands/eject.md b/Linux_man_cn/eject.md similarity index 100% rename from LinuxCommands/eject.md rename to Linux_man_cn/eject.md diff --git a/LinuxCommands/elinks.md b/Linux_man_cn/elinks.md similarity index 100% rename from LinuxCommands/elinks.md rename to Linux_man_cn/elinks.md diff --git a/LinuxCommands/elm.md b/Linux_man_cn/elm.md similarity index 100% rename from LinuxCommands/elm.md rename to Linux_man_cn/elm.md diff --git a/LinuxCommands/emacs.md b/Linux_man_cn/emacs.md similarity index 100% rename from LinuxCommands/emacs.md rename to Linux_man_cn/emacs.md diff --git a/LinuxCommands/enable.md b/Linux_man_cn/enable.md similarity index 100% rename from LinuxCommands/enable.md rename to Linux_man_cn/enable.md diff --git a/LinuxCommands/env.md b/Linux_man_cn/env.md similarity index 100% rename from LinuxCommands/env.md rename to Linux_man_cn/env.md diff --git a/LinuxCommands/ethtool.md b/Linux_man_cn/ethtool.md similarity index 100% rename from LinuxCommands/ethtool.md rename to Linux_man_cn/ethtool.md diff --git a/LinuxCommands/ex.md b/Linux_man_cn/ex.md similarity index 100% rename from LinuxCommands/ex.md rename to Linux_man_cn/ex.md diff --git a/LinuxCommands/exec.md b/Linux_man_cn/exec.md similarity index 100% rename from LinuxCommands/exec.md rename to Linux_man_cn/exec.md diff --git a/LinuxCommands/exit.md b/Linux_man_cn/exit.md similarity index 100% rename from LinuxCommands/exit.md rename to Linux_man_cn/exit.md diff --git a/LinuxCommands/expand.md b/Linux_man_cn/expand.md similarity index 100% rename from LinuxCommands/expand.md rename to Linux_man_cn/expand.md diff --git a/LinuxCommands/export.md b/Linux_man_cn/export.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/export.md rename to Linux_man_cn/export.md index b19ab33..873fca8 --- a/LinuxCommands/export.md +++ b/Linux_man_cn/export.md @@ -1,6 +1,6 @@ export === - + 设置或显示系统环境变量 ## 补充说明 diff --git a/LinuxCommands/exportfs.md b/Linux_man_cn/exportfs.md similarity index 100% rename from LinuxCommands/exportfs.md rename to Linux_man_cn/exportfs.md diff --git a/LinuxCommands/expr.md b/Linux_man_cn/expr.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/expr.md rename to Linux_man_cn/expr.md diff --git a/LinuxCommands/fc.md b/Linux_man_cn/fc.md similarity index 100% rename from LinuxCommands/fc.md rename to Linux_man_cn/fc.md diff --git a/LinuxCommands/fdisk.md b/Linux_man_cn/fdisk.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/fdisk.md rename to Linux_man_cn/fdisk.md index 2bcefba..bd311c5 --- a/LinuxCommands/fdisk.md +++ b/Linux_man_cn/fdisk.md @@ -1,321 +1,321 @@ -fdisk -=== - -查看磁盘使用情况和磁盘分区 - -## 补充说明 - -**fdisk命令** 用于观察硬盘实体使用情况,也可对硬盘分区。它采用传统的问答式界面,而非类似DOS fdisk的cfdisk互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。 - -### 语法 - -``` -fdisk(选项)(参数) -``` - -### 选项 - -``` - -b <大小> 扇区大小(512、1024、2048或4096) - -c[=<模式>] 兼容模式:“dos”或“nondos”(默认) - -h 打印此帮助文本 - -u[=<单位>] 显示单位:“cylinders”(柱面)或“sectors”(扇区,默认) - -v 打印程序版本 - -C <数字> 指定柱面数 - -H <数字> 指定磁头数 - -S <数字> 指定每个磁道的扇区数 -``` - -### 参数 - -设备文件:指定要进行分区或者显示分区的硬盘设备文件。 - -### 实例 - -首先选择要进行操作的磁盘: - -``` -[root@localhost ~]# fdisk /dev/sdb -``` - -输入`m`列出可以执行的命令: - -``` -command (m for help): m -Command action - a toggle a bootable flag - b edit bsd disklabel - c toggle the dos compatibility flag - d delete a partition - l list known partition types - m print this menu - n add a new partition - o create a new empty DOS partition table - p print the partition table - q quit without saving changes - s create a new empty Sun disklabel - t change a partition's system id - u change display/entry units - v verify the partition table - w write table to disk and exit - x extra functionality (experts only) -``` - -输入`p`列出磁盘目前的分区情况: - -``` -Command (m for help): p - -Disk /dev/sdb: 3221 MB, 3221225472 bytes -255 heads, 63 sectors/track, 391 cylinders -Units = cylinders of 16065 * 512 = 8225280 bytes - - Device Boot Start End Blocks Id System -/dev/sdb1 1 1 8001 8e Linux LVM -/dev/sdb2 2 26 200812+ 83 Linux -``` - -输入`d`然后选择分区,删除现有分区: - -``` -Command (m for help): d -Partition number (1-4): 1 - -Command (m for help): d -Selected partition 2 -``` - -查看分区情况,确认分区已经删除: - -``` -Command (m for help): print - -Disk /dev/sdb: 3221 MB, 3221225472 bytes -255 heads, 63 sectors/track, 391 cylinders -Units = cylinders of 16065 * 512 = 8225280 bytes - - Device Boot Start End Blocks Id System - -Command (m for help): -``` - -输入`n`建立新的磁盘分区,首先建立两个主磁盘分区: - -``` -Command (m for help): n -Command action - e extended - p primary partition (1-4) -p //建立主分区 -Partition number (1-4): 1 //分区号 -First cylinder (1-391, default 1): //分区起始位置 -Using default value 1 -last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区 - -Command (m for help): n //再建立一个分区 -Command action - e extended - p primary partition (1-4) -p -Partition number (1-4): 2 //分区号为2 -First cylinder (101-391, default 101): -Using default value 101 -Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M -``` - -确认分区建立成功: - -``` -Command (m for help): p - -Disk /dev/sdb: 3221 MB, 3221225472 bytes -255 heads, 63 sectors/track, 391 cylinders -Units = cylinders of 16065 * 512 = 8225280 bytes - - Device Boot Start End Blocks Id System -/dev/sdb1 1 100 803218+ 83 Linux -/dev/sdb2 101 125 200812+ 83 Linux -``` - -再建立一个逻辑分区: - -``` -Command (m for help): n -Command action - e extended - p primary partition (1-4) -e //选择扩展分区 -Partition number (1-4): 3 -First cylinder (126-391, default 126): -Using default value 126 -Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): -Using default value 391 -``` - -确认扩展分区建立成功: - -``` -Command (m for help): p - -Disk /dev/sdb: 3221 MB, 3221225472 bytes -255 heads, 63 sectors/track, 391 cylinders -Units = cylinders of 16065 * 512 = 8225280 bytes - - Device Boot Start End Blocks Id System -/dev/sdb1 1 100 803218+ 83 Linux -/dev/sdb2 101 125 200812+ 83 Linux -/dev/sdb3 126 391 2136645 5 Extended -``` - -在扩展分区上建立两个逻辑分区: - -``` -Command (m for help): n -Command action - l logical (5 or over) - p primary partition (1-4) -l //选择逻辑分区 -First cylinder (126-391, default 126): -Using default value 126 -Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M - -Command (m for help): n -Command action - l logical (5 or over) - p primary partition (1-4) -l -First cylinder (176-391, default 176): -Using default value 176 -Last cylinder or +size or +sizeM or +sizeK (176-391, default 391): -Using default value 391 -``` - -确认逻辑分区建立成功: - -``` -Command (m for help): p - -Disk /dev/sdb: 3221 MB, 3221225472 bytes -255 heads, 63 sectors/track, 391 cylinders -Units = cylinders of 16065 * 512 = 8225280 bytes - - Device Boot Start End Blocks Id System -/dev/sdb1 1 100 803218+ 83 Linux -/dev/sdb2 101 125 200812+ 83 Linux -/dev/sdb3 126 391 2136645 5 Extended -/dev/sdb5 126 175 401593+ 83 Linux -/dev/sdb6 176 391 1734988+ 83 Linux - -Command (m for help): -``` - -从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6) - -注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。 - -最后对分区操作进行保存: - -``` -Command (m for help): w -The partition table has been altered! - -Calling ioctl() to re-read partition table. -Syncing disks. -``` - -建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。 - -在sdb1上建立ext2分区: - -``` -[root@localhost ~]# mkfs.ext2 /dev/sdb1 -mke2fs 1.39 (29-May-2006) -Filesystem label= -OS type: Linux -Block size=4096 (log=2) -Fragment size=4096 (log=2) -100576 inodes, 200804 blocks -10040 blocks (5.00%) reserved for the super user -First data block=0 -Maximum filesystem blocks=209715200 -7 block groups -32768 blocks per group, 32768 fragments per group -14368 inodes per group -Superblock backups stored on blocks: - 32768, 98304, 163840 - -Writing inode tables: done -Writing superblocks and filesystem accounting information: done - -This filesystem will be automatically checked every 32 mounts or -180 days, whichever comes first. Use tune2fs -c or -i to override. -``` - -在sdb6上建立ext3分区: - -``` -[root@localhost ~]# mkfs.ext3 /dev/sdb6 -mke2fs 1.39 (29-May-2006) -Filesystem label= -OS type: Linux -Block size=4096 (log=2) -Fragment size=4096 (log=2) -217280 inodes, 433747 blocks -21687 blocks (5.00%) reserved for the super user -First data block=0 -Maximum filesystem blocks=444596224 -14 block groups -32768 blocks per group, 32768 fragments per group -15520 inodes per group -Superblock backups stored on blocks: - 32768, 98304, 163840, 229376, 294912 - -Writing inode tables: done -Creating journal (8192 blocks): done -Writing superblocks and filesystem accounting information: done - -This filesystem will be automatically checked every 32 mounts or -180 days, whichever comes first. Use tune2fs -c or -i to override. -[root@localhost ~]# -``` - -建立两个目录`/oracle`和`/web`,将新建好的两个分区挂载到系统: - -``` -[root@localhost ~]# mkdir /oracle -[root@localhost ~]# mkdir /web -[root@localhost ~]# mount /dev/sdb1 /oracle -[root@localhost ~]# mount /dev/sdb6 /web -``` - -查看分区挂载情况: - -``` -[root@localhost ~]# df -h -文件系统 容量 已用 可用 已用% 挂载点 -/dev/mapper/VolGroup00-LogVol00 - 6.7G 2.8G 3.6G 44% / -/dev/sda1 99M 12M 82M 13% /boot -tmpfs 125M 0 125M 0% /dev/shm -/dev/sdb1 773M 808K 733M 1% /oracle -/dev/sdb6 1.7G 35M 1.6G 3% /web -``` - -如果需要每次开机自动挂载则需要修改`/etc/fstab`文件,加入两行配置: - -``` -[root@localhost ~]# vim /etc/fstab - -/dev/VolGroup00/LogVol00 / ext3 defaults 1 1 -LABEL=/boot /boot ext3 defaults 1 2 -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 -/dev/VolGroup00/LogVol01 swap swap defaults 0 0 -/dev/sdb1 /oracle ext2 defaults 0 0 -/dev/sdb6 /web ext3 defaults 0 0 -``` - - - +fdisk +=== + +查看磁盘使用情况和磁盘分区 + +## 补充说明 + +**fdisk命令** 用于观察硬盘实体使用情况,也可对硬盘分区。它采用传统的问答式界面,而非类似DOS fdisk的cfdisk互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。 + +### 语法 + +``` +fdisk(选项)(参数) +``` + +### 选项 + +``` + -b <大小> 扇区大小(512、1024、2048或4096) + -c[=<模式>] 兼容模式:“dos”或“nondos”(默认) + -h 打印此帮助文本 + -u[=<单位>] 显示单位:“cylinders”(柱面)或“sectors”(扇区,默认) + -v 打印程序版本 + -C <数字> 指定柱面数 + -H <数字> 指定磁头数 + -S <数字> 指定每个磁道的扇区数 +``` + +### 参数 + +设备文件:指定要进行分区或者显示分区的硬盘设备文件。 + +### 实例 + +首先选择要进行操作的磁盘: + +``` +[root@localhost ~]# fdisk /dev/sdb +``` + +输入`m`列出可以执行的命令: + +``` +command (m for help): m +Command action + a toggle a bootable flag + b edit bsd disklabel + c toggle the dos compatibility flag + d delete a partition + l list known partition types + m print this menu + n add a new partition + o create a new empty DOS partition table + p print the partition table + q quit without saving changes + s create a new empty Sun disklabel + t change a partition's system id + u change display/entry units + v verify the partition table + w write table to disk and exit + x extra functionality (experts only) +``` + +输入`p`列出磁盘目前的分区情况: + +``` +Command (m for help): p + +Disk /dev/sdb: 3221 MB, 3221225472 bytes +255 heads, 63 sectors/track, 391 cylinders +Units = cylinders of 16065 * 512 = 8225280 bytes + + Device Boot Start End Blocks Id System +/dev/sdb1 1 1 8001 8e Linux LVM +/dev/sdb2 2 26 200812+ 83 Linux +``` + +输入`d`然后选择分区,删除现有分区: + +``` +Command (m for help): d +Partition number (1-4): 1 + +Command (m for help): d +Selected partition 2 +``` + +查看分区情况,确认分区已经删除: + +``` +Command (m for help): print + +Disk /dev/sdb: 3221 MB, 3221225472 bytes +255 heads, 63 sectors/track, 391 cylinders +Units = cylinders of 16065 * 512 = 8225280 bytes + + Device Boot Start End Blocks Id System + +Command (m for help): +``` + +输入`n`建立新的磁盘分区,首先建立两个主磁盘分区: + +``` +Command (m for help): n +Command action + e extended + p primary partition (1-4) +p //建立主分区 +Partition number (1-4): 1 //分区号 +First cylinder (1-391, default 1): //分区起始位置 +Using default value 1 +last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区 + +Command (m for help): n //再建立一个分区 +Command action + e extended + p primary partition (1-4) +p +Partition number (1-4): 2 //分区号为2 +First cylinder (101-391, default 101): +Using default value 101 +Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M +``` + +确认分区建立成功: + +``` +Command (m for help): p + +Disk /dev/sdb: 3221 MB, 3221225472 bytes +255 heads, 63 sectors/track, 391 cylinders +Units = cylinders of 16065 * 512 = 8225280 bytes + + Device Boot Start End Blocks Id System +/dev/sdb1 1 100 803218+ 83 Linux +/dev/sdb2 101 125 200812+ 83 Linux +``` + +再建立一个逻辑分区: + +``` +Command (m for help): n +Command action + e extended + p primary partition (1-4) +e //选择扩展分区 +Partition number (1-4): 3 +First cylinder (126-391, default 126): +Using default value 126 +Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +Using default value 391 +``` + +确认扩展分区建立成功: + +``` +Command (m for help): p + +Disk /dev/sdb: 3221 MB, 3221225472 bytes +255 heads, 63 sectors/track, 391 cylinders +Units = cylinders of 16065 * 512 = 8225280 bytes + + Device Boot Start End Blocks Id System +/dev/sdb1 1 100 803218+ 83 Linux +/dev/sdb2 101 125 200812+ 83 Linux +/dev/sdb3 126 391 2136645 5 Extended +``` + +在扩展分区上建立两个逻辑分区: + +``` +Command (m for help): n +Command action + l logical (5 or over) + p primary partition (1-4) +l //选择逻辑分区 +First cylinder (126-391, default 126): +Using default value 126 +Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M + +Command (m for help): n +Command action + l logical (5 or over) + p primary partition (1-4) +l +First cylinder (176-391, default 176): +Using default value 176 +Last cylinder or +size or +sizeM or +sizeK (176-391, default 391): +Using default value 391 +``` + +确认逻辑分区建立成功: + +``` +Command (m for help): p + +Disk /dev/sdb: 3221 MB, 3221225472 bytes +255 heads, 63 sectors/track, 391 cylinders +Units = cylinders of 16065 * 512 = 8225280 bytes + + Device Boot Start End Blocks Id System +/dev/sdb1 1 100 803218+ 83 Linux +/dev/sdb2 101 125 200812+ 83 Linux +/dev/sdb3 126 391 2136645 5 Extended +/dev/sdb5 126 175 401593+ 83 Linux +/dev/sdb6 176 391 1734988+ 83 Linux + +Command (m for help): +``` + +从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6) + +注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。 + +最后对分区操作进行保存: + +``` +Command (m for help): w +The partition table has been altered! + +Calling ioctl() to re-read partition table. +Syncing disks. +``` + +建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。 + +在sdb1上建立ext2分区: + +``` +[root@localhost ~]# mkfs.ext2 /dev/sdb1 +mke2fs 1.39 (29-May-2006) +Filesystem label= +OS type: Linux +Block size=4096 (log=2) +Fragment size=4096 (log=2) +100576 inodes, 200804 blocks +10040 blocks (5.00%) reserved for the super user +First data block=0 +Maximum filesystem blocks=209715200 +7 block groups +32768 blocks per group, 32768 fragments per group +14368 inodes per group +Superblock backups stored on blocks: + 32768, 98304, 163840 + +Writing inode tables: done +Writing superblocks and filesystem accounting information: done + +This filesystem will be automatically checked every 32 mounts or +180 days, whichever comes first. Use tune2fs -c or -i to override. +``` + +在sdb6上建立ext3分区: + +``` +[root@localhost ~]# mkfs.ext3 /dev/sdb6 +mke2fs 1.39 (29-May-2006) +Filesystem label= +OS type: Linux +Block size=4096 (log=2) +Fragment size=4096 (log=2) +217280 inodes, 433747 blocks +21687 blocks (5.00%) reserved for the super user +First data block=0 +Maximum filesystem blocks=444596224 +14 block groups +32768 blocks per group, 32768 fragments per group +15520 inodes per group +Superblock backups stored on blocks: + 32768, 98304, 163840, 229376, 294912 + +Writing inode tables: done +Creating journal (8192 blocks): done +Writing superblocks and filesystem accounting information: done + +This filesystem will be automatically checked every 32 mounts or +180 days, whichever comes first. Use tune2fs -c or -i to override. +[root@localhost ~]# +``` + +建立两个目录`/oracle`和`/web`,将新建好的两个分区挂载到系统: + +``` +[root@localhost ~]# mkdir /oracle +[root@localhost ~]# mkdir /web +[root@localhost ~]# mount /dev/sdb1 /oracle +[root@localhost ~]# mount /dev/sdb6 /web +``` + +查看分区挂载情况: + +``` +[root@localhost ~]# df -h +文件系统 容量 已用 可用 已用% 挂载点 +/dev/mapper/VolGroup00-LogVol00 + 6.7G 2.8G 3.6G 44% / +/dev/sda1 99M 12M 82M 13% /boot +tmpfs 125M 0 125M 0% /dev/shm +/dev/sdb1 773M 808K 733M 1% /oracle +/dev/sdb6 1.7G 35M 1.6G 3% /web +``` + +如果需要每次开机自动挂载则需要修改`/etc/fstab`文件,加入两行配置: + +``` +[root@localhost ~]# vim /etc/fstab + +/dev/VolGroup00/LogVol00 / ext3 defaults 1 1 +LABEL=/boot /boot ext3 defaults 1 2 +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 +/dev/VolGroup00/LogVol01 swap swap defaults 0 0 +/dev/sdb1 /oracle ext2 defaults 0 0 +/dev/sdb6 /web ext3 defaults 0 0 +``` + + + diff --git a/LinuxCommands/fg.md b/Linux_man_cn/fg.md similarity index 100% rename from LinuxCommands/fg.md rename to Linux_man_cn/fg.md diff --git a/LinuxCommands/fgrep.md b/Linux_man_cn/fgrep.md similarity index 100% rename from LinuxCommands/fgrep.md rename to Linux_man_cn/fgrep.md diff --git a/LinuxCommands/file.md b/Linux_man_cn/file.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/file.md rename to Linux_man_cn/file.md index 207c046..8c14def --- a/LinuxCommands/file.md +++ b/Linux_man_cn/file.md @@ -1,6 +1,6 @@ file === - + 用来探测给定文件的类型。 ## 补充说明 diff --git a/LinuxCommands/find.md b/Linux_man_cn/find.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/find.md rename to Linux_man_cn/find.md index 05f1734..9ab1822 --- a/LinuxCommands/find.md +++ b/Linux_man_cn/find.md @@ -1,1251 +1,1251 @@ -find -=== - -```txt -使用find和xargs可能需要系统查找具有某一特征的文件,例如文件权限、文件属主、文件长度、文件类型等,出于安全性考虑,一般系统管理任务只是为了找出一个知道存放在哪里的文件,find可以遍历当前目录甚至整个文件系统查找文件或目录。即使系统中含有网络文件系统(NFS),find命令在该文件系统中同样有效,只要你具有相应的权限。 -``` - -## 补充说明 - -**find命令** 用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。 - -在运行一个非常消耗资源的find命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间(这里是指30G字节以上的文件系统)。 - -### 语法 - -```sh -find(选项)(参数) - -find的使用格式如下: -$ find <指定目录> <指定条件> <指定动作> -- <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。 -- <指定条件>: 所要搜索的文件的特征。 -- <指定动作>: 对搜索结果进行特定的处理。 - -find 命令格式: -1、find命令的一般形式为; -2、find命令的参数; -3、find命令选项; -4、使用exec或ok来执行shell命令; -``` - -```sh -Find命令的一般形式为: - find pathname -options [-print -exec -ok] -该命令的参数解释: - pathname find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 - -print find命令将匹配的文件输出到标准输出。 - -exec find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'comm- - and'{}\;,注意{}和\;之间的空格。 - -ok和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。 -``` - -### 选项 - -```sh --amin<分钟>:查找在指定时间曾被存取过的文件或目录,单位以分钟计算; --anewer<参考文件或目录>:查找其存取时间较指定文件或目录的存取时间更接近现在的文件或目录; --atime<24小时数>:查找在指定时间曾被存取过的文件或目录,单位以24小时计算; --cmin<分钟>:查找在指定时间之时被更改过的文件或目录; --cnewer<参考文件或目录>查找其更改时间较指定文件或目录的更改时间更接近现在的文件或目录; --ctime<24小时数>:查找在指定时间之时被更改的文件或目录,单位以24小时计算; --daystart:从本日开始计算时间; --depth:从指定目录下最深层的子目录开始查找; --empty:寻找文件大小为0 Byte的文件,或目录下没有任何子目录或文件的空目录; --exec<执行指令>:假设find指令的回传值为True,就执行该指令; --false:将find指令的回传值皆设为False; --fls<列表文件>:此参数的效果和指定“-ls”参数类似,但会把结果保存为指定的列表文件; --follow:排除符号连接;如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。(常用选项) --fprint<列表文件>:此参数的效果和指定“-print”参数类似,但会把结果保存成指定的列表文件; --fprint0<列表文件>:此参数的效果和指定“-print0”参数类似,但会把结果保存成指定的列表文件; --fprintf<列表文件><输出格式>:此参数的效果和指定“-printf”参数类似,但会把结果保存成指定的列表文件; --fstype<文件系统类型>:只寻找该文件系统类型下的文件或目录;(常用选项) --gid<群组识别码>:查找符合指定之群组识别码的文件或目录; --group<群组名称>:查找符合指定之群组名称的文件或目录;(常用选项) --help或——help:在线帮助; --ilname<范本样式>:此参数的效果和指定“-lname”参数类似,但忽略字符大小写的差别; --iname<范本样式>:此参数的效果和指定“-name”参数类似,但忽略字符大小写的差别; --inum:查找符合指定的inode编号的文件或目录; --ipath<范本样式>:此参数的效果和指定“-path”参数类似,但忽略字符大小写的差别; --iregex<范本样式>:此参数的效果和指定“-regexe”参数类似,但忽略字符大小写的差别; --links<连接数目>:查找符合指定的硬连接数目的文件或目录; --iname<范本样式>:指定字符串作为寻找符号连接的范本样式; --ls:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出; --maxdepth<目录层级>:设置最大目录层级; --mindepth<目录层级>:设置最小目录层级; --mmin<分钟>:查找在指定时间曾被更改过的文件或目录,单位以分钟计算; --mount:此参数的效果和指定“-xdev”相同;在查找文件时不跨越文件系统mount点。(常用选项) --mtime<24小时数>:查找在指定时间曾被更改过的文件或目录,单位以24小时计算;-mtime-n+n按照文件的更改时间来查找文件,-n表示文件更改时间距现在n天以内,+n表示文件更改时间距现在n天以前。(常用选项) --name<范本样式>:指定字符串作为寻找文件或目录的范本样式;(常用选项) --newer<参考文件或目录>:查找其更改时间较指定文件或目录的更改时间更接近现在的文件或目录;-newerfile1!file2查找更改时间比文件file1新但比文件file2旧的文件。(常用选项) --nogroup:找出不属于本地主机群组识别码的文件或目录;(常用选项) --noleaf:不去考虑目录至少需拥有两个硬连接存在; --nouser:找出不属于本地主机用户识别码的文件或目录;(常用选项) --ok<执行指令>:此参数的效果和指定“-exec”类似,但在执行指令之前会先询问用户,若回答“y”或“Y”,则放弃执行命令; --path<范本样式>:指定字符串作为寻找目录的范本样式; --perm<权限数值>:查找符合指定的权限数值的文件或目录;(常用选项) --print:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出。格式为每列一个名称,每个名称前皆有“./”字符串; --print0:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出。格式为全部的名称皆在同一行; --printf<输出格式>:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出。格式可以自行指定; --prune:不寻找字符串作为寻找文件或目录的范本样式;如果同时使用了-depth选项,那么-prune选项将被find命令忽略。(常用选项) --regex<范本样式>:指定字符串作为寻找文件或目录的范本样式; --size<文件大小>:查找符合指定的文件大小的文件; --true:将find指令的回传值皆设为True; --type<文件类型>:只寻找符合指定的文件类型的文件;(常用选项) -诸如: - b-块设备文件。 - d-目录。 - c-字符设备文件。 - p-管道文件。 - l-符号链接文件。 - f-普通文件。 --uid<用户识别码>:查找符合指定的用户识别码的文件或目录; --used<日数>:查找文件或目录被更改之后在指定时间曾被存取过的文件或目录,单位以日计算; --user<拥有者名称>:查找符和指定的拥有者名称的文件或目录;(常用选项) --version或——version:显示版本信息; --xdev:将范围局限在先行的文件系统中; --xtype<文件类型>:此参数的效果和指定“-type”参数类似,差别在于它针对符号连接检查。 -``` - -### 参数 - -起始目录:查找文件的起始目录。 - -### 实例 - -```sh -# 当前目录搜索所有文件,文件内容 包含 “140.206.111.111” 的内容 -find . -type f -name "*" | xargs grep "140.206.111.111" -print -``` - -搜索当前目录中,所有文件名以my开头的文件,并显示它们的详细信息。 -find . -name 'my*' -ls - -搜索当前目录中,所有过去10分钟中更新过的普通文件。如果不加-type f参数,则搜索普通文件+特殊文件+目录。 -find . -type f -mmin -10 - -#### 根据文件或者正则表达式进行匹配 - -列出当前目录及子目录下所有文件和文件夹 - -```sh -find . -``` - -在`/home`目录下查找以.txt结尾的文件名 - -```sh -find /home -name "*.txt" -print -``` - -同上,但忽略大小写 - -```sh -find /home -iname "*.txt" -print -``` - -当前目录及子目录下查找所有以.txt和.pdf结尾的文件 - -```sh -find . \( -name "*.txt" -o -name "*.pdf" \) -print - -或 - -find . -name "*.txt" -o -name "*.pdf" -print -``` - -匹配文件路径或者文件 - -```sh -find /usr/ -path "*local*" -print -``` - -基于正则表达式匹配文件路径 - -```sh -find . -regex ".*\(\.txt\|\.pdf\)$" -print -``` - -同上,但忽略大小写 - -```sh -find . -iregex ".*\(\.txt\|\.pdf\)$" -print -``` - -想要在/etc目录中查找文件名以host开头的文件,可以用: -``` -find /etc -name "host*" -print -``` - -想要的当前目录及子目录中查找文件名以一个大写字母开头的文件,可以用: - -```sh -find . -name "[A-Z]*" -print -``` - -如果想在当前目录查找文件名以两个小写字母开头,跟着是两个数字,最后是*.txt的文件,下面的命令就能够返回名为ax37.txt的文件: -``` -find . -name "[a-z][a-z][0--9][0--9].txt" -print -``` - -Find命令查找指定文件并执行删除操作 -``` -find ./ -name "文件名" -exec rm -f {}\; -``` - -#### 否定参数 - -找出/home下不是以.txt结尾的文件 - -```sh -find /home ! -name "*.txt" -print -``` - -#### 根据文件类型进行搜索 - -```sh -find . -type 类型参数 -``` - - -类型参数列表: - -* **f** 普通文件 -* **l** 符号连接 -* **d** 目录 -* **c** 字符设备 -* **b** 块设备 -* **s** 套接字 -* **p** Fifo - -#### 基于目录深度搜索 - -向下最大深度限制为3 - -``` -find . -maxdepth 3 -type f -``` - -搜索出深度距离当前目录至少2个子目录的所有文件 - -``` -find . -mindepth 2 -type f -``` - -#### 根据文件时间戳进行搜索 - -``` -find . -type f 时间戳 -``` - -UNIX/Linux文件系统每个文件都有三种时间戳: - -* **访问时间** (-atime/天,-amin/分钟):用户最近一次访问时间。 -* **修改时间** (-mtime/天,-mmin/分钟):文件最后一次修改时间。 -* **变化时间** (-ctime/天,-cmin/分钟):文件数据元(例如权限等)最后一次修改时间。 - -搜索最近七天内被访问过的所有文件 - -``` -find . -type f -atime -7 -``` - -搜索恰好在七天前被访问过的所有文件 - -``` -find . -type f -atime 7 -``` - -搜索超过七天内被访问过的所有文件 - -``` -find . -type f -atime +7 -``` - -搜索访问时间超过10分钟的所有文件 - -``` -find . -type f -amin +10 -``` - -找出比file.log修改时间更长的所有文件 - -``` -find . -type f -newer file.log -``` - -#### 根据文件大小进行匹配 - -``` -find . -type f -size 文件大小单元 -``` - -文件大小单元: - -* **b** —— 块(512字节) -* **c** —— 字节 -* **w** —— 字(2字节) -* **k** —— 千字节 -* **M** —— 兆字节 -* **G** —— 吉字节 - -搜索大于10KB的文件 - -``` -find . -type f -size +10k -``` - -搜索小于10KB的文件 - -``` -find . -type f -size -10k -``` - -搜索等于10KB的文件 - -``` -find . -type f -size 10k -``` - -#### 删除匹配文件 - -删除当前目录下所有.txt文件 - -``` -find . -type f -name "*.txt" -delete -``` - -#### 根据文件权限/所有权进行匹配 - -当前目录下搜索出权限为777的文件 - -``` -find . -type f -perm 777 -``` - -找出当前目录下权限不是644的php文件 - -``` -find . -type f -name "*.php" ! -perm 644 -``` - -找出当前目录用户tom拥有的所有文件 - -``` -find . -type f -user tom -``` - -找出当前目录用户组sunk拥有的所有文件 - -``` -find . -type f -group sunk -``` - -#### 借助`-exec`选项与其他命令结合使用 - -找出当前目录下所有root的文件,并把所有权更改为用户tom - -``` -find .-type f -user root -exec chown tom {} \; -``` - -上例中, **{}** 用于与 **-exec** 选项结合使用来匹配所有文件,然后会被替换为相应的文件名。 - -找出自己家目录下所有的.txt文件并删除 - -``` -find $HOME/. -name "*.txt" -ok rm {} \; -``` - -上例中, **-ok** 和 **-exec** 行为一样,不过它会给出提示,是否执行相应的操作。 - -查找当前目录下所有.txt文件并把他们拼接起来写入到all.txt文件中 - -``` -find . -type f -name "*.txt" -exec cat {} \;> all.txt -``` - -将30天前的.log文件移动到old目录中 - -``` -find . -type f -mtime +30 -name "*.log" -exec cp {} old \; -``` - -找出当前目录下所有.txt文件并以“File:文件名”的形式打印出来 - -``` -find . -type f -name "*.txt" -exec printf "File: %s\n" {} \; -``` - -因为单行命令中-exec参数中无法使用多个命令,以下方法可以实现在-exec之后接受多条命令 - -``` --exec ./text.sh {} \; -``` - -#### 搜索但跳出指定的目录 - -查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk - -``` -find . -path "./sk" -prune -o -name "*.txt" -print -``` - -#### find其他技巧收集 - -要列出所有长度为零的文件 - -``` -find . -empty -``` - -#### 删除指定文件夹下后缀名相同的文件 - -```sh -方法一: -find 目录 -name "*.abc" | xargs rm -命令有点危险,可以先执行前半段,看看是不是你要删除的文件, 然后再整条执行 - -方法二: -find . -name '*.exe' -type f -print -exec rm -rf {} \; -(1) "." 表示从当前目录开始递归查找 -(2) “ -name '*.exe' "根据名称来查找,要查找所有以.exe结尾的文件夹或者文件 -(3) " -type f "查找的类型为文件 -(4) "-print" 输出查找的文件目录名 -(5) 最主要的是是-exec了,-exec选项后边跟着一个所要执行的命令,表示将find出来的文件或目录执行该命令。 -exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{},一个空格和一个\,最后是一个分号 -``` - -#### 如何找出设置了SET位的权限的文件? - -```sh -ls -lh $(find / -type f -perm +6000) -find / -type f -perm +6000 -exec ls -lh {} \; -命令含义介绍: --perm +6000 表示不检查基本权限(000),只要附加权限中匹配任何一位(6包含了4、2)即满足条件;结合“ls -lh”命令是为了同时显示出结果文件的详细属性 -两种方法的区别在于:前者使用了Shell的命令替换操作( $() 符号或者反撇号 ``),只有在find命令执行完毕后才能看到结果;而后一种方法则每找到一条结果就立即显示出来了 -``` - - - -#### 暂未整理一 - -```sh - -2.1.2使用perm选项 -如果希望按照文件权限模式来查找文件的话,可以采用-perm选项。你可能需要找到所有用户都具有执行权限的文件,或是希望查看某个用户目录下的文件权限类型。在使用这一选项的时候,最好使用八进制的权限表示法。 -为了在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用: -$ find . -perm 755 -print -如果希望在当前目录下查找所有用户都可读、写、执行的文件(要小心这种情况),我们可以使用find命令的-perm选项。在八进制数字前面要加一个横杠-。在下面的命令中-perm代表按照文件权限查找,而‘007’和你在chmod命令的绝对模式中所采用的表示法完全相同。 -$ find . -perm -007 -print -2.1.3忽略某个目录 -如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了-depth选项,那么-prune选项就会被find命令忽略。 -如果希望在/apps目录下查找文件,但不希望在/apps/bin目录下查找,可以用: -$ find /apps -name "/apps/bin" -prune -o -print -2.1.4使用user和nouser选项 -如果希望按照文件属主查找文件,可以给出相应的用户名。例如,在$HOME目录中查找文件属主为dave的文件,可以用: -$ find ~ -user dave -print -在/etc目录下查找文件属主为uucp的文件: -$ find /etc -user uucp -print -为了查找属主帐户已经被删除的文件,可以使用-nouser选项。这样就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件。在使用-nouser选项时,不必给出用户名;find命令能够为你完成相应的工作。例如,希望在/home目录下查找所有的这类文件,可以用: -$ find /home -nouser -print -2.1.5使用group和nogroup选项 -就像user和nouser选项一样,针对文件所属于的用户组,find命令也具有同样的选项,为了在/apps目录下查找属于accts用户组的文件,可以用: -$ find /apps -group accts -print -要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样的文件 -$ find / -nogroup -print -2.1.6按照更改时间查找文件 -如果希望按照更改时间来查找文件,可以使用mtime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时就可以用mtime选项来查找这样的文件。用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距今n日以前的文件。 -希望在系统根目录下查找更改时间在5日以内的文件,可以用: -$ find/-mtime-5-print -为了在/var/adm目录下查找更改时间在3日以前的文件,可以用: -$ find /var/adm -mtime +3 -print -2.1.7查找比某个文件新或旧的文件 -如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可以使用-newer选项。它的一般形式为: -newest_file_name ! oldest_file_name -其中,!是逻辑非符号。 -这里有两个文件,它们的更改时间大约相差两天。 --rwxr-x-r-x 1 root root 92 Apr 18 11:18 age.awk --rwxrwxr-x 1 root root 1045 Apr 20 19:37 belts.awk -下面给出的find命令能够查找更改时间比文件age.awk新但比文件belts.awk旧的文件: -$ find . -newer age.awk ! -newer belts.awk -exec ls -l {} \; --rwxrwxr-x 1 root root 62 Apr 18 11:32 ./who.awk --rwxr-xr-x 1 root root 49 Apr 18 12:05 ./group.awk --rw-r--r-- 1 root root 201 Apr 20 19:30 ./grade2.txt --rwxrwxr-x 1 root root 1054 Apr 20 19:37 ./belts.awk -如果想使用find命令的这一选项来查找更改时间在两个小时以内的文件,除非有一个现成的文件其更改时间恰好在两个小时以前,否则就没有可用来比较更改时间的文件。为了解决这一问题,可以首先创建一个文件并将其日期和时间戳设置为所需要的时间。这可以用touch命令来实现。 -假设现在的时间是23:40,希望查找更改时间在两个小时以内的文件,可以首先创建这样一个文件: -$ touch -t 05042140 dstamp --rw-r--r-- 1 dave admin 0 May 4 21:40 dstamp -一个符合要求的文件已经被创建;这里我们假设今天是五月四日,而该文件的更改时间是21:40,比现在刚好早两个小时。 -现在我们就可以使用find命令的-newer选项在当前目录下查找所有更改时间在两个小时以内的文件: -$find . -newer dstamp -print -2.1.8使用type选项 -UNIX或LINUX系统中有若干种不同的文件类型,这部分内容我们在前面的章节已经做了介绍,这里就不再赘述。如果要在/etc目录下查找所有的目录,可以用: -$find /etc -type d -print -为了在当前目录下查找除目录以外的所有类型的文件,可以用: -$find . ! -type d -print -为了在/etc目录下查找所有的符号链接文件,可以用: -$find /etc -type l -print -2.1.9 -使用size选项可以按照文件长度来查找文件,这里所指的文件长度既可以用块(block)来计量,也可以用字节来计量。以字节计量文件长度的表达形式为Nc;以块计量文件长度只用数字表示即可。 -就我个人而言,我总是使用以字节计的方式,在按照文件长度查找文件时,大多数人都喜欢使用这种以字节表示的文件长度,而不用块的数目来表示,除非是在查看文件系统的大 -小,因为这时使用块来计量更容易转换。 -为了在当前目录下查找文件长度大于1M字节的文件,可以用: -$find . -size +1000000c -print -为了在/home/apache目录下查找文件长度恰好为100字节的文件,可以用: -$find /home /apache -size 100c -print -为了在当前目录下查找长度超过10块的文件(一块等于512字节),可以用: -$find . -size +10 -print -2.1.10使用depth选项 -在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个原因就是,当在使用find命令向磁带上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。 -在下面的例子中,find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。它将首先匹配所有的文件然后再进入子目录中查找。 -$find / -name "CON.FILE" -depth -print -2.1.11使用mount选项 -在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。在下面的例子中,我们从当前目录开始查找位于本文件系统中文件名以XC结尾的文件: -$find . -name "*.XC" -mount -print -2.1.12使用cpio选项 -cpio命令可以用来向磁带设备备份文件或从中恢复文件。可以使用find命令在整个文件系统中(更多的情况下是在部分文件系统中)查找文件,然后用cpio命令将其备份到磁带上。 -如果希望使用cpio命令备份/etc、/home和/apps目录中的文件,可以使用下面所给出的命令,不过要记住你是在文件系统的根目录下: -$ cd / -$ find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0 -(在上面的例子中,第一行末尾的\告诉shell命令还未结束,忽略\后面的回车。) -在上面的例子中,应当注意到路径中缺少/。这叫作相对路径。之所以使用相对路径,是因为在从磁带中恢复这些文件的时候,可以选择恢复文件的路径。例如,可以将这些文件先恢复到另外一个目录中,对它们进行某些操作后,再恢复到原始目录中。如果在备份时使用了绝对路径,例如/etc,那么在恢复时,就只能恢复到/etc目录中去,别无其他选择。在上面的例子中,我告诉find命令首先进入/etc目录,然后是/home和/apps目录,先匹配这些目录下的文件,然后再匹配其子目录中的文件,所有这些结果将通过管道传递给cpio命令进行备份。 -顺便说一下,在上面的例子中cpio命令使用了C65536选项,我本可以使用B选项,不过这样每块的大小只有512字节,而使用了C65536选项后,块的大小变成了64K字节(65536/1024)。 -2.1.13使用exec或ok来执行shell命令 -当匹配到一些文件以后,可能希望对其进行某些操作,这时就可以使用-exec选项。一旦find命令匹配到了相应的文件,就可以用-exec选项中的命令对其进行操作(在有些操作系统中只允许-exec选项执行诸如ls或ls-l这样的命令)。大多数用户使用这一选项是为了查找旧文件并删除它们。这里我强烈地建议你在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 -exec选项后面跟随着所要执行的命令,然后是一对儿{},一个空格和一个\,最后是一个分号。 -为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。 -为了用ls-l命令列出所匹配到的文件,可以把ls-l命令放在find命令的-exec选项中,例如: -$ find . -type f -exec ls-l {} \; --rwxr-xr-x 10 root wheel 1222 Jan 4 1993 ./sbin/C80 --rwxr-xr-x 10 root wheel 1222 Jan 4 1993 ./sbin/Normal --rwxr-xr-x 10 root wheel 1222 Jan 4 1993 ./sbin/Revvid -上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls-l命令将它们列出。 -为了在/logs目录中查找更改时间在5日以前的文件并删除它们,可以用: -$ find logs -type f -mtime +5 -exec rm {} \; -记住,在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心! -当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。在下面的例子中,find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。 -$ find . -name “*.LOG” -mtime +5 -ok rm {} \; - ?y -按y键删除文件,按n键不删除。 -任何形式的命令都可以在-exec选项中使用。在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个rounder用户。 -$ find /etc -name “passwd*” -exec grep “rounder” {} \; -rounder:JL9TtUqk8EHwc:500:500::/home/apps/nets/rounder:/bin/sh -2.1.14find命令的例子 -我们已经介绍了find命令的基本选项,下面给出find命令的一些其他的例子。 -为了匹配$HOME目录下的所有文件,下面两种方法都可以使用: -$ find $HOME -print -$ find ~ -print -为了在当前目录中查找suid置位,文件属主具有读、写、执行权限,并且文件所属组的用户和其他用户具有读和执行的权限的文件,可以用: -$ find . -type f -perm 4755 -print -为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径,可以用: -$ find / -type f -size 0 -exec ls-l {} \; -为了查找/var/logs目录中更改时间在7日以前的普通文件,并删除它们,可以用: -$ find /var/logs -type f -mtime +7 -exec rm {} \; -为了查找系统中所有属于audit组的文件,可以用: -$ find / -name -group audit -print -我们的一个审计系统每天创建一个审计日志文件。日志文件名的最后含有数字,这样我们一眼就可以看出哪个文件是最新的,哪个是最旧的。Admin.log文件编上了序号:admin.log.001、admin.log.002等等。下面的find命令将删除/logs目录中访问时间在7日以前、含有数字后缀的admin.log文件。该命令只检查三位数字,所以相应日志文件的后缀不要超过999。 -$ find / logs -name 'admin.log[0-9][0-9]' [-0a-t9i]me +7 -exec rm {} \; -为了查找当前文件系统中的所有目录并排序,可以用: -$ find . -type d -print -local -mount | sort -为了查找系统中所有的rmt磁带设备,可以用: -$ find /dev/rmt -print -2.2xargs -在使用find命令的-exec选项处理匹配到的文件时,find命令将所有匹配到的文件一起传递给exec执行。不幸的是,有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。Find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高;而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。 -让我们来看看xargs命令是如何同find命令一起使用的,并给出一些例子。 -下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件: -$ find / -type f -print | xargs file -/etc/protocols: Enghlish text -/etc/securetty: ASCII test -… -下面的例子在整个系统中查找内存信息转储文件(coredump),然后把结果保存到/tmp/core.log文件中: -$ find . -name "core" -print | xargs echo "" >/tmp/core.log -下面的例子在/apps/audit目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限: -$ find /apps/audit -perm -7 -print | xargs chmod o -w -在下面的例子中,我们用grep命令在所有的普通文件中搜索device这个词: -$ find / -type f -print | xargs grep "device" -在下面的例子中,我们用grep命令在当前目录下的所有普通文件中搜索DBO这个词: -$ find . -name *\ -type f -print | xargs grep "DBO" -注意,在上面的例子中,\用来取消find命令中的*在shell中的特殊含义。 -find简单示例 -(1) find . -type f -exec ls -l {} \; -解释:查找当前路径下的所有普通文件,并把它们列出来。 -(2)find logs -type f -mtime +5 -exec rm {} \; -解释:删除logs目录下更新时间为5日以上的文件。 -(3)find . -name "*.log" -mtime +5 -ok rm {} \; -解释:删除当前路径下以。log结尾的五日以上的文件,删除之前要确认。 -(4) find ~ -type f -perm 4755 -print -解释:查找$HOME目录下suid位被设置,文件属性为755的文件打印出来。 -说明: find在有点系统中会一次性得到将匹配到的文件都传给exec,但是有的系统对exec的命令长度做限制,就会报:”参数列太长“,这就需要使用xargs。xargs是部分取传来的文件。 -(5)find / -type f -print |xargs file -解释:xargs测试文件分类 -(6)find . -name "core*" -print|xargs echo " ">/tmp/core.log -解释:将core文件信息查询结果报存到core。log日志。 -(7)find / -type f -print | xargs chmod o -w -(8)find . -name * -print |xargs grep "DBO" -find用法小结 -1. 通过文件的特征查找: -1) 按文件名 -find / -name httpd.conf -find /usr -name httpd.conf -find /etc -name '*srm*' -2) 按大小 -find / -size 1500c # 查找文件大小为1,500 bytes的文件,字符 c 表明这个要查找的文件的大小是以bytes为单位。 -find/ -size +10000000c # "+”是表示要求系统只列出大于指定大小的文件, "-”表示小于 -find / -empty # 查找在系统中为空的文件或者文件夹 --size:表示文件大小,+表示大于某个数,-表示小于某个数。c表示单位是字节,你可以将c换成k,M,G。 -3) 按时间 -find / -amin -10 # 查找在系统中最后10分钟访问的文件 -find / -atime -2 # 查找在系统中最后48小时访问的文件 -find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件 -find / -mtime -1 # 查找在系统中最后24小时里修改过的文件 -find / -cmin -5 # 查找在系统中最后5分钟里被改变状态的文件 -find / -ctime -1 # 查找在系统中最后24小时里被改变状态的文件 -访问过用amin,修改过用mmin,文件状态改变过用cmin -精确到分钟的用amin,mmin,cmin,精确到天的用atime,mtime,ctime -在5分钟之内的用-5,在5分钟以上的用+5 -4) 按用户 -find / -user fred # 查找在系统中属于FRED这个用户的文件 -find / -group cat # 查找在系统中属于 groupcat的文件 -find / -nouser # 查找在系统中属于作废用户的文件 -5) 其他 --false 查找系统中总是错误的文件 --fstype type 查找系统中存在于指定文件系统的文件,例如:ext2 . --gid n 查找系统中文件数字组 ID 为 n的文件 --group gname 查找系统中文件属于gnam文件组,并且指定组和ID的文件 -2. 通过文件的特征查找: -Find命令也提供给用户一些特有的选项来控制查找操作。下表就是我们总结出的最基本,最常用的find命令的控制选项及其用法。 -选项 用途描述 --daystart . .测试系统从今天开始24小时以内的文件,用法类似-amin --depth 使用深度级别的查找过程方式,在某层指定目录中优先查找文件内容 --follow 遵循通配符链接方式查找; 另外,也可忽略通配符链接方式查询 --maxdepth levels 在某个层次的目录中按照递减方法查找 --mount 不在文件系统目录中查找, 用法类似 -xdev. --noleaf 禁止在非UNUX文件系统,MS-DOS系统,CD-ROM文件系统中进行最优化查找 --help 显示命令摘要 --version 打印版本数字 -使用-follow选项后,find命令则遵循通配符链接方式进行查uuuu找,除非你指定这个选项,否则一般情况下find命令将忽略通配符链接方式进行文件查找。 --maxdepth选项的作用就是限制find命令在目录中按照递减方式查找文件的时候搜索文件超过某个级别或者搜索过多的目录,这样导致查找速度变慢,查找花费的时间过多。例如,我们要在当前(.)目录技巧子目录中查找一个名叫fred的文件,我们可以使用如下命令 -find . -maxdepth 2 -name fred -假如这个fred文件在./sub1/fred目录中,那么这个命令就会直接定位这个文件,查找很容易成功。假如,这个文件在./sub1/sub2 /fred目录中,那么这个命令就无法查找到。因为前面已经给find命令在目录中最大的查询目录级别为2,只能查找2层目录下的文件。这样做的目的就是为了让find命令更加精确的定位文件,如果你已经知道了某个文件大概所在的文件目录级数,那么加入-maxdepth n 就很快的能在指定目录中查找成功。 -3. 使用混合查找方式: -find /tmp -size +10000000c -and -mtime +2 // -and -find / -user fred -or -user george // -or 在/tmp目录中查找属于fred或者george这两个用户的文件 -find /tmp ! -user panda // -or 在/tmp目录中查找所有不属于panda的文件 -命令就可以解决了。很简单。 -查找并显示文件的方法 -查找到某个文件是我们的目的,我们更想知道查找到的文件的详细信息和属性, -find / -name "httpd.conf" -ls -下面的表格就是一些常用的查找文件并显示文件信息的参数和使用方法 -选项 用途描述 --exec command; 查找并执行命令 --fprint file 打印文件完整文件名 --fprint0 file 打印文件完整文件名包括空的文件 --fprintf file format 打印文件格式 --ok command; 给用户命令执行操作,根据用户的Y 确认输入执行 --printf format 打印文件格式 --ls 打印同种文件格式的文件. -2. 普通用户无错误查找: -find / -name access_log 2>/dev/null -说明:当普通用户使用"find”命令来查询某些没有相应权限文件目录时(Linux系统中系统管理员ROOT可以把某些文件目录设置成禁止访问模式) -往往会出现"Permissiondenied."(禁止访问)字样。 2>/dev/null就是表明系统将把错误信息输送到stderrstream 2中. --exec command; -删除一个目录中的全部文件 -cd “目的目录” -find . -name * -exec rm -f {} \; --exec 参数后面跟的是 command命令,注意如下几点: -1) command命令的终止,使用 ';' (分号)来判定,在后面必须有一个 ';' -出于不明原因, ';'需要用'\'来转义 ,所以命令整体形式为: -exec rm -f {} \; -2) '{}',使用{}来表示文件名,也就是find前面处理过程中过滤出来的文件,用于command命令进行处理 -1.查询所有保护字符串“Hello”的文件 -find / -exec grep "Hello" {} \; -2.删除所有临时文件 -find / -name "*.tmp" -exec rm -f {} \; -3. 使用混合查找方式: -find /tmp -size +10000000c -and -mtime +2 // -and -find / -user fred -or -user george // -or 在/tmp目录中查找属于fred或者george这两个用户的文件 -find /tmp ! -user panda // -or 在/tmp目录中查找所有不属于panda的文件 -find /tmp ! \( -user 0 -o -user 500 -o -user 501 \) -exec ls -l {} \; -把用户名改成UID就可以了 -find命令使用经验 -find pathname -options [-print -exec -ok] -pathname find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 --print find命令将匹配的文件输出到标准输出。 --exec find命令对匹配的文件执行该参数所给出的shell命令。 -相应命令的形式为'command'{} \;,注意{}和\;之间的空格。 --ok和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行 -文件状态判断: --mtime: 指定时间文件内容被修改过 --ctime: 指定时间文件权限被修改过 --atime: 指定时间文件被读取过 -找出3天“以前”被修改过的文档 -# find /var/log/ -mtime +3 -type f -print -找出3天“内”被修改过的文档 -# find /var/log/ -mtime -3 -type f -print -找出第3天被修改过的文档. -# find /var/log/ -mtime 3 -type f -print -或这样写: -#find /var/log/ -mtime +2 -mtime -4 -type f -print -注: -访问过用amin,修改过用mmin,文件状态改变过用cmin -精确到分钟的用amin,mmin,cmin,精确到天的用atime,mtime,ctime -xargs - build and execute command lines from standard input -在使用find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。 -find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。 -在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高; -而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。 -来看看xargs命令是如何同find命令一起使用的,并给出一些例子。 -下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件 -#find . -type f -print | xargs file -./.kde/Autostart/Autorun.desktop: UTF-8 Unicode English text -./.kde/Autostart/.directory: ISO-8859 text\ -...... -在整个系统中查找内存信息转储文件(core dump) ,然后把结果保存到/tmp/core.log 文件中: -$ find / -name "core" -print | xargs echo "" >/tmp/core.log -上面这个执行太慢,我改成在当前目录下查找 -#find . -name "file*" -print | xargs echo "" > /temp/core.log -# cat /temp/core.log -./file6 -在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限: -# ls -l -drwxrwxrwx 2 sam adm 4096 10月 30 20:14 file6 --rwxrwxrwx 2 sam adm 0 10月 31 01:01 http3.conf --rwxrwxrwx 2 sam adm 0 10月 31 01:01 httpd.conf -# find . -perm -7 -print | xargs chmod o-w -# ls -l -drwxrwxr-x 2 sam adm 4096 10月 30 20:14 file6 --rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf --rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf -用grep命令在所有的普通文件中搜索hostname这个词: -# find . -type f -print | xargs grep "hostname" -./httpd1.conf:# different IP addresses or hostnames and have them handled by the -./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames -on your -用grep命令在当前目录下的所有普通文件中搜索hostnames这个词: -# find . -name \* -type f -print | xargs grep "hostnames" -./httpd1.conf:# different IP addresses or hostnames and have them handled by the -./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames -on your -注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。 -find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令 -使用exec或ok来执行shell命令 -使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的 -在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 -exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{ },一个空格和一个\,最后是一个分号。为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。 -例如:为了用ls -l命令列出所匹配到的文件,可以把ls -l命令放在find命令的-exec选项中 -# find . -type f -exec ls -l { } \; --rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf --rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic --rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README -上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls -l命令将它们列出。 -在/logs目录中查找更改时间在5日以前的文件并删除它们: -$ find logs -type f -mtime +5 -exec rm { } \; -记住:在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心!当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。 -在下面的例子中, find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。 -$ find . -name "*.conf" -mtime +5 -ok rm { } \; -< rm ... ./conf/httpd.conf > ? n -按y键删除文件,按n键不删除。 -任何形式的命令都可以在-exec选项中使用。 -在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“ passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个sam用户。 -# find /etc -name "passwd*" -exec grep "sam" { } \; -sam:x:501:501::/usr/sam:/bin/bash -find 命令用法 -find / -name access_log 2>/dev/null -find /etc -name ‘*srm*’ -find / -amin -10 # 查找在系统中最后10分钟访问的文件 -find / -atime -2 # 查找在系统中最后48小时访问的文件 -find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件 -find / -mtime -1 #查找在系统中最后24小时里修改过的文件 -find / -cmin -5 # 查找在系统中最后5分钟里被改变状态的文件 -find / -ctime -1 #查找在系统中最后24小时里被改变状态的文件 -find / -user reda #查找在系统中属于fred这个用户的文件 -find / -not -user red #查找在系统中不属于red这个用户的文件 -find / -group redagrp # 查找在系统中属于redagrp组的文件 -find / -gid 501 #查找系统中属于组id为501的文件 -find / -user fred -a -group redagrp -find / -user reda -o -user tracy -find / -nouser #查找在系统中属于作废用户的文件 -find / -empty # 查找在系统中为空的文件或者为空的文件夹 -find / -false #查找系统中总是错误的文件 -find / -size +5k #查找系统中大于5k字节的文件 -find / -size +5c #查找系统中大于5字节的文件 -find / -perm +6000 -find / -type b -文件类型: -b 块(缓冲)设备. -c 字符设备. -d 目录. -p 有名管道(FIFO). -f 规则文件. -l 符号链结. -s SOCKET. -find / -maxdepth 2 -name fred -find /tmp -size +10000000c -and -mtime +2 -find / -user reda -or -user tracy -find /tmp ! -user reda -find / -name "httpd.conf" -ls -find / -user reda -exec ls -l {} \; -find / -user reda -ok #确认后执行 -find / -user reda | xargs ls -l -6.2 使用|| -使用||的一般形式为: -命令1 || 命令2 -||的作用有一些不同。如果||左边的命令(命令1)未执行成功,那么就执行||右边的命令(命令2);或者换句话说,“如果这个命令执行失败了|| 那么就执行这个命令”。 -这里有一个使用||的简单例子: -$ cp wopper.txt wopper.bak || echo “if you are seeing this cp failed” -cp: wopper.txt: No such file or directory -if you are seeing this cp failed -在上面的例子中,拷贝命令没有能够被成功执行,因此||后面的命令被执行。 -这里有一个更为实用的例子。我希望从一个审计文件中抽取第1个和第5个域,并将其输出到一个临时文件中,如果这一操作未成功,我希望能够收到一个相应邮件: -$ awk ‘{print $5}’ acc.qtr > qtr.tmp || echo “Sorry the payroll extraction didn’t work” | mail dave -在这里不只可以使用系统命令;这里我们首先对month_end.txt文件执行了一个名为comet的shell脚本,如果该脚本未执行成功,该shell将结束。 -$ comet month_end.txt || exit -6.3 用()和{}将命令结合在一起 -如果希望把几个命令合在一起执行, shell提供了两种方法。既可以在当前shell也可以在子shell中执行一组命令。 -为了在当前shell中执行一组命令,可以用命令分隔符隔开每一个命令,并把所有的命令用圆括号()括起来。 -它的一般形式为: -(命令1;命令2;. . .) -如果使用{ }来代替(),那么相应的命令将在子shell而不是当前shell中作为一个整体被执行,只有在{ }中所有命令的输出作为一个整体被重定向时,其中的命令才被放到子shell中执行,否则在当前shell执行。它的一般形式为: -{命令1;命令2;. . . } -我很少单独使用这两种方法。我一般只和&&或||一起使用这两种方法。 -再回到前面那个comet脚本的例子,如果这个脚本执行失败了,我很可能会希望执行两个以上的命令,而不只是一个命令。我可以使用这两种方法。这是原先那个例子: -$ comet month_end.txt || exit -现在如果该脚本执行失败了,我希望先给自己发个邮件,然后再退出,可以用下面的方法来实现: -$ comet month_end || (echo “Hello, guess what! Comet did not work”|mail dave;exit) -在上面的例子中,如果只使用了命令分隔符而没有把它们组合在一起,shell将直接执行最后一个命令(exit)。 -我们再回头来看看前面那个使用&&排序的例子,下面是原来的那个例子: -$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted -使用命令组合的方法,如果sort命令执行成功了,可以先将输出文件拷贝到一个日志区,然后再打印。 -6.4 小结 -在编写shell脚本时,使用&&和||对构造判断语句非常有用。如果希望在前一个命令执行失败的情况不执行后面的命令,那么本章所讲述的方法非常简单有效。使用这样的方法,可以根据&&或||前面命令的返回值来控制其后面命令的执行。 -``` - -#### 暂未整理二 - -```sh - -一、find 命令格式 - - -1、find命令的一般形式为; - -find pathname -options [-print -exec -ok ...] - -2、find命令的参数; - -pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 --print: find命令将匹配的文件输出到标准输出。 --exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' {} \;,注意{}和\;之间的空格。 --ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。 - -3、find命令选项 - --name - -按照文件名查找文件。 - --perm -按照文件权限来查找文件。 - --prune -使用这一选项可以使find命令不在当前指定的目录中查找,如果同时使用-depth选项,那么-prune将被find命令忽略。 - --user -按照文件属主来查找文件。 - --group -按照文件所属的组来查找文件。 - --mtime -n +n -按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项,但它们都和-m time选项。 - --nogroup -查找无有效所属组的文件,即该文件所属的组在/etc/groups中不存在。 - --nouser -查找无有效属主的文件,即该文件的属主在/etc/passwd中不存在。 --newer file1 ! file2 - -查找更改时间比文件file1新但比文件file2旧的文件。 --type - -查找某一类型的文件,诸如: - -b - 块设备文件。 -d - 目录。 -c - 字符设备文件。 -p - 管道文件。 -l - 符号链接文件。 -f - 普通文件。 - --size n:[c] 查找文件长度为n块的文件,带有c时表示文件长度以字节计。 --depth:在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。 --fstype:查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。 - --mount:在查找文件时不跨越文件系统mount点。 --follow:如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。 --cpio:对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。 -另外,下面三个的区别: - --amin n -查找系统中最后N分钟访问的文件 - --atime n -查找系统中最后n*24小时访问的文件 - --cmin n -查找系统中最后N分钟被改变文件状态的文件 - --ctime n -查找系统中最后n*24小时被改变文件状态的文件 - --mmin n -查找系统中最后N分钟被改变文件数据的文件 - --mtime n -查找系统中最后n*24小时被改变文件数据的文件 - -4、使用exec或ok来执行shell命令 - -使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的 - -在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 - -exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{ },一个空格和一个\,最后是一个分号。为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。 - -例如:为了用ls -l命令列出所匹配到的文件,可以把ls -l命令放在find命令的-exec选项中 - -# find . -type f -exec ls -l {} \; --rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf --rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic --rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README -上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls -l命令将它们列出。 -在/logs目录中查找更改时间在5日以前的文件并删除它们: - -$ find logs -type f -mtime +5 -exec rm {} \; -记住:在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心!当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。 - -在下面的例子中, find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。 - -$ find . -name "*.log" -mtime +5 -ok rm {} \; -< rm ... ./conf/httpd.conf > ? n -按y键删除文件,按n键不删除。 - -任何形式的命令都可以在-exec选项中使用。 - -在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“ passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个sam用户。 - -# find /etc -name "passwd*" -exec grep "sam" {} \; -sam:x:501:501::/usr/sam:/bin/bash - -二、find命令的例子; - - -1、查找当前用户主目录下的所有文件: - -下面两种方法都可以使用 - -$ find $HOME -print -$ find ~ -print - -2、让当前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件; - -$ find . -type f -perm 644 -exec ls -l {} \; - -3、为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径; - -$ find / -type f -size 0 -exec ls -l {} \; - -4、查找/var/logs目录中更改时间在7日以前的普通文件,并在删除之前询问它们; - -$ find /var/logs -type f -mtime +7 -ok rm {} \; - -5、为了查找系统中所有属于root组的文件; - -$find . -group root -exec ls -l {} \; --rw-r--r-- 1 root root 595 10月 31 01:09 ./fie1 - -6、find命令将删除当目录中访问时间在7日以来、含有数字后缀的admin.log文件。 - -该命令只检查三位数字,所以相应文件的后缀不要超过999。先建几个admin.log*的文件 ,才能使用下面这个命令 - -$ find . -name "admin.log[0-9][0-9][0-9]" -atime -7 -ok -rm {} \; -< rm ... ./admin.log001 > ? n -< rm ... ./admin.log002 > ? n -< rm ... ./admin.log042 > ? n -< rm ... ./admin.log942 > ? n - -7、为了查找当前文件系统中的所有目录并排序; - -$ find . -type d | sort - -8、为了查找系统中所有的rmt磁带设备; - -$ find /dev/rmt -print - -三、xargs - -xargs – build and execute command lines from standard input - -在使用find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。 - -find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。 - -在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高; - -而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。 - -来看看xargs命令是如何同find命令一起使用的,并给出一些例子。 - -下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件 - -#find . -type f -print | xargs file -./.kde/Autostart/Autorun.desktop: UTF-8 Unicode English text -./.kde/Autostart/.directory: ISO-8859 text\ -...... -在整个系统中查找内存信息转储文件(core dump) ,然后把结果保存到/tmp/core.log 文件中: - -$ find / -name "core" -print | xargs echo "" >/tmp/core.log -上面这个执行太慢,我改成在当前目录下查找 - -#find . -name "file*" -print | xargs echo "" > /temp/core.log -# cat /temp/core.log -./file6 -在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限: - -# ls -l -drwxrwxrwx 2 sam adm 4096 10月 30 20:14 file6 --rwxrwxrwx 2 sam adm 0 10月 31 01:01 http3.conf --rwxrwxrwx 2 sam adm 0 10月 31 01:01 httpd.conf - -# find . -perm -7 -print | xargs chmod o-w -# ls -l -drwxrwxr-x 2 sam adm 4096 10月 30 20:14 file6 --rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf --rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf -用grep命令在所有的普通文件中搜索hostname这个词: - -# find . -type f -print | xargs grep "hostname" -./httpd1.conf:# different IP addresses or hostnames and have them handled by the -./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames -on your -用grep命令在当前目录下的所有普通文件中搜索hostnames这个词: - -# find . -name \* -type f -print | xargs grep "hostnames" -./httpd1.conf:# different IP addresses or hostnames and have them handled by the -./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames -on your -注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。 - -find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令。 - - -四、find 命令的参数 - -下面是find一些常用参数的例子,有用到的时候查查就行了,像上面前几个贴子,都用到了其中的的一些参数,也可以用man或查看论坛里其它贴子有find的命令手册 - - -1、使用name选项 - -文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用。 - -可以使用某种文件名模式来匹配文件,记住要用引号将文件名模式引起来。 - -不管当前路径是什么,如果想要在自己的根目录$HOME中查找文件名符合*.txt的文件,使用~作为 ‘pathname’参数,波浪号~代表了你的$HOME目录。 - -$ find ~ -name "*.txt" -print -想要在当前目录及子目录中查找所有的‘ *.txt’文件,可以用: - -$ find . -name "*.txt" -print -想要的当前目录及子目录中查找文件名以一个大写字母开头的文件,可以用: - -$ find . -name "[A-Z]*" -print -想要在/etc目录中查找文件名以host开头的文件,可以用: - -$ find /etc -name "host*" -print -想要查找$HOME目录中的文件,可以用: - -$ find ~ -name "*" -print 或find . -print -要想让系统高负荷运行,就从根目录开始查找所有的文件。 - -$ find / -name "*" -print -如果想在当前目录查找文件名以两个小写字母开头,跟着是两个数字,最后是.txt的文件,下面的命令就能够返回名为ax37.txt的文件: - -$find . -name "[a-z][a-z][0--9][0--9].txt" -print - -2、用perm选项 - -按照文件权限模式用-perm选项,按文件权限模式来查找文件的话。最好使用八进制的权限表示法。 - -如在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用: - -$ find . -perm 755 -print -还有一种表达方法:在八进制数字前面要加一个横杠-,表示都匹配,如-007就相当于777,-006相当于666 - -# ls -l --rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf --rw-rw-rw- 1 sam adm 34890 10月 31 00:57 httpd1.conf --rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf -drw-rw-rw- 2 gem group 4096 10月 26 19:48 sam --rw-rw-rw- 1 root root 2792 10月 31 20:19 temp - -# find . -perm 006 -# find . -perm -006 -./sam -./httpd1.conf -./temp --perm mode:文件许可正好符合mode - --perm +mode:文件许可部分符合mode - --perm -mode: 文件许可完全符合mode - - -3、忽略某个目录 - -如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了-depth选项,那么-prune选项就会被find命令忽略。 - -如果希望在/apps目录下查找文件,但不希望在/apps/bin目录下查找,可以用: - -$ find /apps -path "/apps/bin" -prune -o -print - -4、使用find查找文件的时候怎么避开某个文件目录 - -比如要在/usr/sam目录下查找不在dir1子目录之内的所有文件 - -find /usr/sam -path "/usr/sam/dir1" -prune -o -print -find [-path ..] [expression] 在路径列表的后面的是表达式 --path “/usr/sam” -prune -o -print 是 -path “/usr/sam” -a -prune -o --print 的简写表达式按顺序求值, -a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果 -path “/usr/sam” 为真,则求值 -prune , -prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假。如果 -path “/usr/sam” -a -prune 为假,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值 -print,或逻辑表达式为真。 - -这个表达式组合特例可以用伪码写为 - -if -path "/usr/sam" then --prune -else --print -避开多个文件夹 - -find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print -圆括号表示表达式的结合。 - -\ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。 -查找某一确定文件,-name等选项加在-o 之后 - -#find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print - -5、使用user和nouser选项 - -按文件属主查找文件,如在$HOME目录中查找文件属主为sam的文件,可以用: - -$ find ~ -user sam -print -在/etc目录下查找文件属主为uucp的文件: - -$ find /etc -user uucp -print -为了查找属主帐户已经被删除的文件,可以使用-nouser选项。这样就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件。在使用-nouser选项时,不必给出用户名; find命令能够为你完成相应的工作。 - -例如,希望在/home目录下查找所有的这类文件,可以用: - -$ find /home -nouser -print - -6、使用group和nogroup选项 - -就像user和nouser选项一样,针对文件所属于的用户组, find命令也具有同样的选项,为了在/apps目录下查找属于gem用户组的文件,可以用: - -$ find /apps -group gem -print -要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样的文件 - -$ find / -nogroup-print - -7、按照更改时间或访问时间等查找文件 - -如果希望按照更改时间来查找文件,可以使用mtime,atime或ctime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时就可以用mtime选项来查找这样的文件。 - -用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距今n日以前的文件。 - -希望在系统根目录下查找更改时间在5日以内的文件,可以用: - -$ find / -mtime -5 -print -为了在/var/adm目录下查找更改时间在3日以前的文件,可以用: - -$ find /var/adm -mtime +3 -print - -8、查找比某个文件新或旧的文件 - -如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可以使用-newer选项。它的一般形式为: - -newest_file_name ! oldest_file_name -其中,!是逻辑非符号。 - -查找更改时间比文件sam新但比文件temp旧的文件: - -例:有两个文件 - --rw-r--r-- 1 sam adm 0 10月 31 01:07 fiel --rw-rw-rw- 1 sam adm 34890 10月 31 00:57 httpd1.conf --rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf -drw-rw-rw- 2 gem group 4096 10月 26 19:48 sam --rw-rw-rw- 1 root root 2792 10月 31 20:19 temp - -# find -newer httpd1.conf ! -newer temp -ls -1077669 0 -rwxrwxr-x 2 sam adm 0 10月 31 01:01 ./httpd.conf -1077671 4 -rw-rw-rw- 1 root root 2792 10月 31 20:19 ./temp -1077673 0 -rw-r--r-- 1 sam adm 0 10月 31 01:07 ./fiel -查找更改时间在比temp文件新的文件: - -$ find . -newer temp -print - -9、使用type选项 - -在/etc目录下查找所有的目录,可以用: - -$ find /etc -type d -print -在当前目录下查找除目录以外的所有类型的文件,可以用: - -$ find . ! -type d -print -在/etc目录下查找所有的符号链接文件,可以用 - -$ find /etc -type l -print - -10、使用size选项 - -可以按照文件长度来查找文件,这里所指的文件长度既可以用块(block)来计量,也可以用字节来计量。以字节计量文件长度的表达形式为N c;以块计量文件长度只用数字表示即可。 - -在按照文件长度查找文件时,一般使用这种以字节表示的文件长度,在查看文件系统的大小,因为这时使用块来计量更容易转换。 -在当前目录下查找文件长度大于1 M字节的文件: - -$ find . -size +1000000c -print -查找当前目录中大于10M的文件: - -find . -size +10000k -exec ls -ld {} ; -将find出来的文件复制到另一个地方: - -find *.c -exec cp '{}' /tmp ';' -在/home/apache目录下查找文件长度恰好为100字节的文件: - -$ find /home/apache -size 100c -print -在当前目录下查找长度超过10块的文件(一块等于512字节): - -$ find . -size +10 -print - -11、使用depth选项 - -在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个原因就是,当在使用find命令向磁带上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。 - -在下面的例子中, find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。 - -它将首先匹配所有的文件然后再进入子目录中查找。 - -$ find / -name "CON.FILE" -depth -print - -12、使用mount选项 - -在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。 - -从当前目录开始查找位于本文件系统中文件名以XC结尾的文件: - -$ find . -name "*.XC" -mount -print - +find +=== + +```txt +使用find和xargs可能需要系统查找具有某一特征的文件,例如文件权限、文件属主、文件长度、文件类型等,出于安全性考虑,一般系统管理任务只是为了找出一个知道存放在哪里的文件,find可以遍历当前目录甚至整个文件系统查找文件或目录。即使系统中含有网络文件系统(NFS),find命令在该文件系统中同样有效,只要你具有相应的权限。 +``` + +## 补充说明 + +**find命令** 用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。 + +在运行一个非常消耗资源的find命令时,很多人都倾向于把它放在后台执行,因为遍历一个大的文件系统可能会花费很长的时间(这里是指30G字节以上的文件系统)。 + +### 语法 + +```sh +find(选项)(参数) + +find的使用格式如下: +$ find <指定目录> <指定条件> <指定动作> +- <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。 +- <指定条件>: 所要搜索的文件的特征。 +- <指定动作>: 对搜索结果进行特定的处理。 + +find 命令格式: +1、find命令的一般形式为; +2、find命令的参数; +3、find命令选项; +4、使用exec或ok来执行shell命令; +``` + +```sh +Find命令的一般形式为: + find pathname -options [-print -exec -ok] +该命令的参数解释: + pathname find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 + -print find命令将匹配的文件输出到标准输出。 + -exec find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'comm- + and'{}\;,注意{}和\;之间的空格。 + -ok和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。 +``` + +### 选项 + +```sh +-amin<分钟>:查找在指定时间曾被存取过的文件或目录,单位以分钟计算; +-anewer<参考文件或目录>:查找其存取时间较指定文件或目录的存取时间更接近现在的文件或目录; +-atime<24小时数>:查找在指定时间曾被存取过的文件或目录,单位以24小时计算; +-cmin<分钟>:查找在指定时间之时被更改过的文件或目录; +-cnewer<参考文件或目录>查找其更改时间较指定文件或目录的更改时间更接近现在的文件或目录; +-ctime<24小时数>:查找在指定时间之时被更改的文件或目录,单位以24小时计算; +-daystart:从本日开始计算时间; +-depth:从指定目录下最深层的子目录开始查找; +-empty:寻找文件大小为0 Byte的文件,或目录下没有任何子目录或文件的空目录; +-exec<执行指令>:假设find指令的回传值为True,就执行该指令; +-false:将find指令的回传值皆设为False; +-fls<列表文件>:此参数的效果和指定“-ls”参数类似,但会把结果保存为指定的列表文件; +-follow:排除符号连接;如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。(常用选项) +-fprint<列表文件>:此参数的效果和指定“-print”参数类似,但会把结果保存成指定的列表文件; +-fprint0<列表文件>:此参数的效果和指定“-print0”参数类似,但会把结果保存成指定的列表文件; +-fprintf<列表文件><输出格式>:此参数的效果和指定“-printf”参数类似,但会把结果保存成指定的列表文件; +-fstype<文件系统类型>:只寻找该文件系统类型下的文件或目录;(常用选项) +-gid<群组识别码>:查找符合指定之群组识别码的文件或目录; +-group<群组名称>:查找符合指定之群组名称的文件或目录;(常用选项) +-help或——help:在线帮助; +-ilname<范本样式>:此参数的效果和指定“-lname”参数类似,但忽略字符大小写的差别; +-iname<范本样式>:此参数的效果和指定“-name”参数类似,但忽略字符大小写的差别; +-inum:查找符合指定的inode编号的文件或目录; +-ipath<范本样式>:此参数的效果和指定“-path”参数类似,但忽略字符大小写的差别; +-iregex<范本样式>:此参数的效果和指定“-regexe”参数类似,但忽略字符大小写的差别; +-links<连接数目>:查找符合指定的硬连接数目的文件或目录; +-iname<范本样式>:指定字符串作为寻找符号连接的范本样式; +-ls:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出; +-maxdepth<目录层级>:设置最大目录层级; +-mindepth<目录层级>:设置最小目录层级; +-mmin<分钟>:查找在指定时间曾被更改过的文件或目录,单位以分钟计算; +-mount:此参数的效果和指定“-xdev”相同;在查找文件时不跨越文件系统mount点。(常用选项) +-mtime<24小时数>:查找在指定时间曾被更改过的文件或目录,单位以24小时计算;-mtime-n+n按照文件的更改时间来查找文件,-n表示文件更改时间距现在n天以内,+n表示文件更改时间距现在n天以前。(常用选项) +-name<范本样式>:指定字符串作为寻找文件或目录的范本样式;(常用选项) +-newer<参考文件或目录>:查找其更改时间较指定文件或目录的更改时间更接近现在的文件或目录;-newerfile1!file2查找更改时间比文件file1新但比文件file2旧的文件。(常用选项) +-nogroup:找出不属于本地主机群组识别码的文件或目录;(常用选项) +-noleaf:不去考虑目录至少需拥有两个硬连接存在; +-nouser:找出不属于本地主机用户识别码的文件或目录;(常用选项) +-ok<执行指令>:此参数的效果和指定“-exec”类似,但在执行指令之前会先询问用户,若回答“y”或“Y”,则放弃执行命令; +-path<范本样式>:指定字符串作为寻找目录的范本样式; +-perm<权限数值>:查找符合指定的权限数值的文件或目录;(常用选项) +-print:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出。格式为每列一个名称,每个名称前皆有“./”字符串; +-print0:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出。格式为全部的名称皆在同一行; +-printf<输出格式>:假设find指令的回传值为Ture,就将文件或目录名称列出到标准输出。格式可以自行指定; +-prune:不寻找字符串作为寻找文件或目录的范本样式;如果同时使用了-depth选项,那么-prune选项将被find命令忽略。(常用选项) +-regex<范本样式>:指定字符串作为寻找文件或目录的范本样式; +-size<文件大小>:查找符合指定的文件大小的文件; +-true:将find指令的回传值皆设为True; +-type<文件类型>:只寻找符合指定的文件类型的文件;(常用选项) +诸如: + b-块设备文件。 + d-目录。 + c-字符设备文件。 + p-管道文件。 + l-符号链接文件。 + f-普通文件。 +-uid<用户识别码>:查找符合指定的用户识别码的文件或目录; +-used<日数>:查找文件或目录被更改之后在指定时间曾被存取过的文件或目录,单位以日计算; +-user<拥有者名称>:查找符和指定的拥有者名称的文件或目录;(常用选项) +-version或——version:显示版本信息; +-xdev:将范围局限在先行的文件系统中; +-xtype<文件类型>:此参数的效果和指定“-type”参数类似,差别在于它针对符号连接检查。 +``` + +### 参数 + +起始目录:查找文件的起始目录。 + +### 实例 + +```sh +# 当前目录搜索所有文件,文件内容 包含 “140.206.111.111” 的内容 +find . -type f -name "*" | xargs grep "140.206.111.111" -print +``` + +搜索当前目录中,所有文件名以my开头的文件,并显示它们的详细信息。 +find . -name 'my*' -ls + +搜索当前目录中,所有过去10分钟中更新过的普通文件。如果不加-type f参数,则搜索普通文件+特殊文件+目录。 +find . -type f -mmin -10 + +#### 根据文件或者正则表达式进行匹配 + +列出当前目录及子目录下所有文件和文件夹 + +```sh +find . +``` + +在`/home`目录下查找以.txt结尾的文件名 + +```sh +find /home -name "*.txt" -print +``` + +同上,但忽略大小写 + +```sh +find /home -iname "*.txt" -print +``` + +当前目录及子目录下查找所有以.txt和.pdf结尾的文件 + +```sh +find . \( -name "*.txt" -o -name "*.pdf" \) -print + +或 + +find . -name "*.txt" -o -name "*.pdf" -print +``` + +匹配文件路径或者文件 + +```sh +find /usr/ -path "*local*" -print +``` + +基于正则表达式匹配文件路径 + +```sh +find . -regex ".*\(\.txt\|\.pdf\)$" -print +``` + +同上,但忽略大小写 + +```sh +find . -iregex ".*\(\.txt\|\.pdf\)$" -print +``` + +想要在/etc目录中查找文件名以host开头的文件,可以用: +``` +find /etc -name "host*" -print +``` + +想要的当前目录及子目录中查找文件名以一个大写字母开头的文件,可以用: + +```sh +find . -name "[A-Z]*" -print +``` + +如果想在当前目录查找文件名以两个小写字母开头,跟着是两个数字,最后是*.txt的文件,下面的命令就能够返回名为ax37.txt的文件: +``` +find . -name "[a-z][a-z][0--9][0--9].txt" -print +``` + +Find命令查找指定文件并执行删除操作 +``` +find ./ -name "文件名" -exec rm -f {}\; +``` + +#### 否定参数 + +找出/home下不是以.txt结尾的文件 + +```sh +find /home ! -name "*.txt" -print +``` + +#### 根据文件类型进行搜索 + +```sh +find . -type 类型参数 +``` + + +类型参数列表: + +* **f** 普通文件 +* **l** 符号连接 +* **d** 目录 +* **c** 字符设备 +* **b** 块设备 +* **s** 套接字 +* **p** Fifo + +#### 基于目录深度搜索 + +向下最大深度限制为3 + +``` +find . -maxdepth 3 -type f +``` + +搜索出深度距离当前目录至少2个子目录的所有文件 + +``` +find . -mindepth 2 -type f +``` + +#### 根据文件时间戳进行搜索 + +``` +find . -type f 时间戳 +``` + +UNIX/Linux文件系统每个文件都有三种时间戳: + +* **访问时间** (-atime/天,-amin/分钟):用户最近一次访问时间。 +* **修改时间** (-mtime/天,-mmin/分钟):文件最后一次修改时间。 +* **变化时间** (-ctime/天,-cmin/分钟):文件数据元(例如权限等)最后一次修改时间。 + +搜索最近七天内被访问过的所有文件 + +``` +find . -type f -atime -7 +``` + +搜索恰好在七天前被访问过的所有文件 + +``` +find . -type f -atime 7 +``` + +搜索超过七天内被访问过的所有文件 + +``` +find . -type f -atime +7 +``` + +搜索访问时间超过10分钟的所有文件 + +``` +find . -type f -amin +10 +``` + +找出比file.log修改时间更长的所有文件 + +``` +find . -type f -newer file.log +``` + +#### 根据文件大小进行匹配 + +``` +find . -type f -size 文件大小单元 +``` + +文件大小单元: + +* **b** —— 块(512字节) +* **c** —— 字节 +* **w** —— 字(2字节) +* **k** —— 千字节 +* **M** —— 兆字节 +* **G** —— 吉字节 + +搜索大于10KB的文件 + +``` +find . -type f -size +10k +``` + +搜索小于10KB的文件 + +``` +find . -type f -size -10k +``` + +搜索等于10KB的文件 + +``` +find . -type f -size 10k +``` + +#### 删除匹配文件 + +删除当前目录下所有.txt文件 + +``` +find . -type f -name "*.txt" -delete +``` + +#### 根据文件权限/所有权进行匹配 + +当前目录下搜索出权限为777的文件 + +``` +find . -type f -perm 777 +``` + +找出当前目录下权限不是644的php文件 + +``` +find . -type f -name "*.php" ! -perm 644 +``` + +找出当前目录用户tom拥有的所有文件 + +``` +find . -type f -user tom +``` + +找出当前目录用户组sunk拥有的所有文件 + +``` +find . -type f -group sunk +``` + +#### 借助`-exec`选项与其他命令结合使用 + +找出当前目录下所有root的文件,并把所有权更改为用户tom + +``` +find .-type f -user root -exec chown tom {} \; +``` + +上例中, **{}** 用于与 **-exec** 选项结合使用来匹配所有文件,然后会被替换为相应的文件名。 + +找出自己家目录下所有的.txt文件并删除 + +``` +find $HOME/. -name "*.txt" -ok rm {} \; +``` + +上例中, **-ok** 和 **-exec** 行为一样,不过它会给出提示,是否执行相应的操作。 + +查找当前目录下所有.txt文件并把他们拼接起来写入到all.txt文件中 + +``` +find . -type f -name "*.txt" -exec cat {} \;> all.txt +``` + +将30天前的.log文件移动到old目录中 + +``` +find . -type f -mtime +30 -name "*.log" -exec cp {} old \; +``` + +找出当前目录下所有.txt文件并以“File:文件名”的形式打印出来 + +``` +find . -type f -name "*.txt" -exec printf "File: %s\n" {} \; +``` + +因为单行命令中-exec参数中无法使用多个命令,以下方法可以实现在-exec之后接受多条命令 + +``` +-exec ./text.sh {} \; +``` + +#### 搜索但跳出指定的目录 + +查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk + +``` +find . -path "./sk" -prune -o -name "*.txt" -print +``` + +#### find其他技巧收集 + +要列出所有长度为零的文件 + +``` +find . -empty +``` + +#### 删除指定文件夹下后缀名相同的文件 + +```sh +方法一: +find 目录 -name "*.abc" | xargs rm +命令有点危险,可以先执行前半段,看看是不是你要删除的文件, 然后再整条执行 + +方法二: +find . -name '*.exe' -type f -print -exec rm -rf {} \; +(1) "." 表示从当前目录开始递归查找 +(2) “ -name '*.exe' "根据名称来查找,要查找所有以.exe结尾的文件夹或者文件 +(3) " -type f "查找的类型为文件 +(4) "-print" 输出查找的文件目录名 +(5) 最主要的是是-exec了,-exec选项后边跟着一个所要执行的命令,表示将find出来的文件或目录执行该命令。 +exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{},一个空格和一个\,最后是一个分号 +``` + +#### 如何找出设置了SET位的权限的文件? + +```sh +ls -lh $(find / -type f -perm +6000) +find / -type f -perm +6000 -exec ls -lh {} \; +命令含义介绍: +-perm +6000 表示不检查基本权限(000),只要附加权限中匹配任何一位(6包含了4、2)即满足条件;结合“ls -lh”命令是为了同时显示出结果文件的详细属性 +两种方法的区别在于:前者使用了Shell的命令替换操作( $() 符号或者反撇号 ``),只有在find命令执行完毕后才能看到结果;而后一种方法则每找到一条结果就立即显示出来了 +``` + + + +#### 暂未整理一 + +```sh + +2.1.2使用perm选项 +如果希望按照文件权限模式来查找文件的话,可以采用-perm选项。你可能需要找到所有用户都具有执行权限的文件,或是希望查看某个用户目录下的文件权限类型。在使用这一选项的时候,最好使用八进制的权限表示法。 +为了在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用: +$ find . -perm 755 -print +如果希望在当前目录下查找所有用户都可读、写、执行的文件(要小心这种情况),我们可以使用find命令的-perm选项。在八进制数字前面要加一个横杠-。在下面的命令中-perm代表按照文件权限查找,而‘007’和你在chmod命令的绝对模式中所采用的表示法完全相同。 +$ find . -perm -007 -print +2.1.3忽略某个目录 +如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了-depth选项,那么-prune选项就会被find命令忽略。 +如果希望在/apps目录下查找文件,但不希望在/apps/bin目录下查找,可以用: +$ find /apps -name "/apps/bin" -prune -o -print +2.1.4使用user和nouser选项 +如果希望按照文件属主查找文件,可以给出相应的用户名。例如,在$HOME目录中查找文件属主为dave的文件,可以用: +$ find ~ -user dave -print +在/etc目录下查找文件属主为uucp的文件: +$ find /etc -user uucp -print +为了查找属主帐户已经被删除的文件,可以使用-nouser选项。这样就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件。在使用-nouser选项时,不必给出用户名;find命令能够为你完成相应的工作。例如,希望在/home目录下查找所有的这类文件,可以用: +$ find /home -nouser -print +2.1.5使用group和nogroup选项 +就像user和nouser选项一样,针对文件所属于的用户组,find命令也具有同样的选项,为了在/apps目录下查找属于accts用户组的文件,可以用: +$ find /apps -group accts -print +要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样的文件 +$ find / -nogroup -print +2.1.6按照更改时间查找文件 +如果希望按照更改时间来查找文件,可以使用mtime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时就可以用mtime选项来查找这样的文件。用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距今n日以前的文件。 +希望在系统根目录下查找更改时间在5日以内的文件,可以用: +$ find/-mtime-5-print +为了在/var/adm目录下查找更改时间在3日以前的文件,可以用: +$ find /var/adm -mtime +3 -print +2.1.7查找比某个文件新或旧的文件 +如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可以使用-newer选项。它的一般形式为: +newest_file_name ! oldest_file_name +其中,!是逻辑非符号。 +这里有两个文件,它们的更改时间大约相差两天。 +-rwxr-x-r-x 1 root root 92 Apr 18 11:18 age.awk +-rwxrwxr-x 1 root root 1045 Apr 20 19:37 belts.awk +下面给出的find命令能够查找更改时间比文件age.awk新但比文件belts.awk旧的文件: +$ find . -newer age.awk ! -newer belts.awk -exec ls -l {} \; +-rwxrwxr-x 1 root root 62 Apr 18 11:32 ./who.awk +-rwxr-xr-x 1 root root 49 Apr 18 12:05 ./group.awk +-rw-r--r-- 1 root root 201 Apr 20 19:30 ./grade2.txt +-rwxrwxr-x 1 root root 1054 Apr 20 19:37 ./belts.awk +如果想使用find命令的这一选项来查找更改时间在两个小时以内的文件,除非有一个现成的文件其更改时间恰好在两个小时以前,否则就没有可用来比较更改时间的文件。为了解决这一问题,可以首先创建一个文件并将其日期和时间戳设置为所需要的时间。这可以用touch命令来实现。 +假设现在的时间是23:40,希望查找更改时间在两个小时以内的文件,可以首先创建这样一个文件: +$ touch -t 05042140 dstamp +-rw-r--r-- 1 dave admin 0 May 4 21:40 dstamp +一个符合要求的文件已经被创建;这里我们假设今天是五月四日,而该文件的更改时间是21:40,比现在刚好早两个小时。 +现在我们就可以使用find命令的-newer选项在当前目录下查找所有更改时间在两个小时以内的文件: +$find . -newer dstamp -print +2.1.8使用type选项 +UNIX或LINUX系统中有若干种不同的文件类型,这部分内容我们在前面的章节已经做了介绍,这里就不再赘述。如果要在/etc目录下查找所有的目录,可以用: +$find /etc -type d -print +为了在当前目录下查找除目录以外的所有类型的文件,可以用: +$find . ! -type d -print +为了在/etc目录下查找所有的符号链接文件,可以用: +$find /etc -type l -print +2.1.9 +使用size选项可以按照文件长度来查找文件,这里所指的文件长度既可以用块(block)来计量,也可以用字节来计量。以字节计量文件长度的表达形式为Nc;以块计量文件长度只用数字表示即可。 +就我个人而言,我总是使用以字节计的方式,在按照文件长度查找文件时,大多数人都喜欢使用这种以字节表示的文件长度,而不用块的数目来表示,除非是在查看文件系统的大 +小,因为这时使用块来计量更容易转换。 +为了在当前目录下查找文件长度大于1M字节的文件,可以用: +$find . -size +1000000c -print +为了在/home/apache目录下查找文件长度恰好为100字节的文件,可以用: +$find /home /apache -size 100c -print +为了在当前目录下查找长度超过10块的文件(一块等于512字节),可以用: +$find . -size +10 -print +2.1.10使用depth选项 +在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个原因就是,当在使用find命令向磁带上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。 +在下面的例子中,find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。它将首先匹配所有的文件然后再进入子目录中查找。 +$find / -name "CON.FILE" -depth -print +2.1.11使用mount选项 +在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。在下面的例子中,我们从当前目录开始查找位于本文件系统中文件名以XC结尾的文件: +$find . -name "*.XC" -mount -print +2.1.12使用cpio选项 +cpio命令可以用来向磁带设备备份文件或从中恢复文件。可以使用find命令在整个文件系统中(更多的情况下是在部分文件系统中)查找文件,然后用cpio命令将其备份到磁带上。 +如果希望使用cpio命令备份/etc、/home和/apps目录中的文件,可以使用下面所给出的命令,不过要记住你是在文件系统的根目录下: +$ cd / +$ find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0 +(在上面的例子中,第一行末尾的\告诉shell命令还未结束,忽略\后面的回车。) +在上面的例子中,应当注意到路径中缺少/。这叫作相对路径。之所以使用相对路径,是因为在从磁带中恢复这些文件的时候,可以选择恢复文件的路径。例如,可以将这些文件先恢复到另外一个目录中,对它们进行某些操作后,再恢复到原始目录中。如果在备份时使用了绝对路径,例如/etc,那么在恢复时,就只能恢复到/etc目录中去,别无其他选择。在上面的例子中,我告诉find命令首先进入/etc目录,然后是/home和/apps目录,先匹配这些目录下的文件,然后再匹配其子目录中的文件,所有这些结果将通过管道传递给cpio命令进行备份。 +顺便说一下,在上面的例子中cpio命令使用了C65536选项,我本可以使用B选项,不过这样每块的大小只有512字节,而使用了C65536选项后,块的大小变成了64K字节(65536/1024)。 +2.1.13使用exec或ok来执行shell命令 +当匹配到一些文件以后,可能希望对其进行某些操作,这时就可以使用-exec选项。一旦find命令匹配到了相应的文件,就可以用-exec选项中的命令对其进行操作(在有些操作系统中只允许-exec选项执行诸如ls或ls-l这样的命令)。大多数用户使用这一选项是为了查找旧文件并删除它们。这里我强烈地建议你在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 +exec选项后面跟随着所要执行的命令,然后是一对儿{},一个空格和一个\,最后是一个分号。 +为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。 +为了用ls-l命令列出所匹配到的文件,可以把ls-l命令放在find命令的-exec选项中,例如: +$ find . -type f -exec ls-l {} \; +-rwxr-xr-x 10 root wheel 1222 Jan 4 1993 ./sbin/C80 +-rwxr-xr-x 10 root wheel 1222 Jan 4 1993 ./sbin/Normal +-rwxr-xr-x 10 root wheel 1222 Jan 4 1993 ./sbin/Revvid +上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls-l命令将它们列出。 +为了在/logs目录中查找更改时间在5日以前的文件并删除它们,可以用: +$ find logs -type f -mtime +5 -exec rm {} \; +记住,在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心! +当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。在下面的例子中,find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。 +$ find . -name “*.LOG” -mtime +5 -ok rm {} \; + ?y +按y键删除文件,按n键不删除。 +任何形式的命令都可以在-exec选项中使用。在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个rounder用户。 +$ find /etc -name “passwd*” -exec grep “rounder” {} \; +rounder:JL9TtUqk8EHwc:500:500::/home/apps/nets/rounder:/bin/sh +2.1.14find命令的例子 +我们已经介绍了find命令的基本选项,下面给出find命令的一些其他的例子。 +为了匹配$HOME目录下的所有文件,下面两种方法都可以使用: +$ find $HOME -print +$ find ~ -print +为了在当前目录中查找suid置位,文件属主具有读、写、执行权限,并且文件所属组的用户和其他用户具有读和执行的权限的文件,可以用: +$ find . -type f -perm 4755 -print +为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径,可以用: +$ find / -type f -size 0 -exec ls-l {} \; +为了查找/var/logs目录中更改时间在7日以前的普通文件,并删除它们,可以用: +$ find /var/logs -type f -mtime +7 -exec rm {} \; +为了查找系统中所有属于audit组的文件,可以用: +$ find / -name -group audit -print +我们的一个审计系统每天创建一个审计日志文件。日志文件名的最后含有数字,这样我们一眼就可以看出哪个文件是最新的,哪个是最旧的。Admin.log文件编上了序号:admin.log.001、admin.log.002等等。下面的find命令将删除/logs目录中访问时间在7日以前、含有数字后缀的admin.log文件。该命令只检查三位数字,所以相应日志文件的后缀不要超过999。 +$ find / logs -name 'admin.log[0-9][0-9]' [-0a-t9i]me +7 -exec rm {} \; +为了查找当前文件系统中的所有目录并排序,可以用: +$ find . -type d -print -local -mount | sort +为了查找系统中所有的rmt磁带设备,可以用: +$ find /dev/rmt -print +2.2xargs +在使用find命令的-exec选项处理匹配到的文件时,find命令将所有匹配到的文件一起传递给exec执行。不幸的是,有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。Find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高;而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。 +让我们来看看xargs命令是如何同find命令一起使用的,并给出一些例子。 +下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件: +$ find / -type f -print | xargs file +/etc/protocols: Enghlish text +/etc/securetty: ASCII test +… +下面的例子在整个系统中查找内存信息转储文件(coredump),然后把结果保存到/tmp/core.log文件中: +$ find . -name "core" -print | xargs echo "" >/tmp/core.log +下面的例子在/apps/audit目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限: +$ find /apps/audit -perm -7 -print | xargs chmod o -w +在下面的例子中,我们用grep命令在所有的普通文件中搜索device这个词: +$ find / -type f -print | xargs grep "device" +在下面的例子中,我们用grep命令在当前目录下的所有普通文件中搜索DBO这个词: +$ find . -name *\ -type f -print | xargs grep "DBO" +注意,在上面的例子中,\用来取消find命令中的*在shell中的特殊含义。 +find简单示例 +(1) find . -type f -exec ls -l {} \; +解释:查找当前路径下的所有普通文件,并把它们列出来。 +(2)find logs -type f -mtime +5 -exec rm {} \; +解释:删除logs目录下更新时间为5日以上的文件。 +(3)find . -name "*.log" -mtime +5 -ok rm {} \; +解释:删除当前路径下以。log结尾的五日以上的文件,删除之前要确认。 +(4) find ~ -type f -perm 4755 -print +解释:查找$HOME目录下suid位被设置,文件属性为755的文件打印出来。 +说明: find在有点系统中会一次性得到将匹配到的文件都传给exec,但是有的系统对exec的命令长度做限制,就会报:”参数列太长“,这就需要使用xargs。xargs是部分取传来的文件。 +(5)find / -type f -print |xargs file +解释:xargs测试文件分类 +(6)find . -name "core*" -print|xargs echo " ">/tmp/core.log +解释:将core文件信息查询结果报存到core。log日志。 +(7)find / -type f -print | xargs chmod o -w +(8)find . -name * -print |xargs grep "DBO" +find用法小结 +1. 通过文件的特征查找: +1) 按文件名 +find / -name httpd.conf +find /usr -name httpd.conf +find /etc -name '*srm*' +2) 按大小 +find / -size 1500c # 查找文件大小为1,500 bytes的文件,字符 c 表明这个要查找的文件的大小是以bytes为单位。 +find/ -size +10000000c # "+”是表示要求系统只列出大于指定大小的文件, "-”表示小于 +find / -empty # 查找在系统中为空的文件或者文件夹 +-size:表示文件大小,+表示大于某个数,-表示小于某个数。c表示单位是字节,你可以将c换成k,M,G。 +3) 按时间 +find / -amin -10 # 查找在系统中最后10分钟访问的文件 +find / -atime -2 # 查找在系统中最后48小时访问的文件 +find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件 +find / -mtime -1 # 查找在系统中最后24小时里修改过的文件 +find / -cmin -5 # 查找在系统中最后5分钟里被改变状态的文件 +find / -ctime -1 # 查找在系统中最后24小时里被改变状态的文件 +访问过用amin,修改过用mmin,文件状态改变过用cmin +精确到分钟的用amin,mmin,cmin,精确到天的用atime,mtime,ctime +在5分钟之内的用-5,在5分钟以上的用+5 +4) 按用户 +find / -user fred # 查找在系统中属于FRED这个用户的文件 +find / -group cat # 查找在系统中属于 groupcat的文件 +find / -nouser # 查找在系统中属于作废用户的文件 +5) 其他 +-false 查找系统中总是错误的文件 +-fstype type 查找系统中存在于指定文件系统的文件,例如:ext2 . +-gid n 查找系统中文件数字组 ID 为 n的文件 +-group gname 查找系统中文件属于gnam文件组,并且指定组和ID的文件 +2. 通过文件的特征查找: +Find命令也提供给用户一些特有的选项来控制查找操作。下表就是我们总结出的最基本,最常用的find命令的控制选项及其用法。 +选项 用途描述 +-daystart . .测试系统从今天开始24小时以内的文件,用法类似-amin +-depth 使用深度级别的查找过程方式,在某层指定目录中优先查找文件内容 +-follow 遵循通配符链接方式查找; 另外,也可忽略通配符链接方式查询 +-maxdepth levels 在某个层次的目录中按照递减方法查找 +-mount 不在文件系统目录中查找, 用法类似 -xdev. +-noleaf 禁止在非UNUX文件系统,MS-DOS系统,CD-ROM文件系统中进行最优化查找 +-help 显示命令摘要 +-version 打印版本数字 +使用-follow选项后,find命令则遵循通配符链接方式进行查uuuu找,除非你指定这个选项,否则一般情况下find命令将忽略通配符链接方式进行文件查找。 +-maxdepth选项的作用就是限制find命令在目录中按照递减方式查找文件的时候搜索文件超过某个级别或者搜索过多的目录,这样导致查找速度变慢,查找花费的时间过多。例如,我们要在当前(.)目录技巧子目录中查找一个名叫fred的文件,我们可以使用如下命令 +find . -maxdepth 2 -name fred +假如这个fred文件在./sub1/fred目录中,那么这个命令就会直接定位这个文件,查找很容易成功。假如,这个文件在./sub1/sub2 /fred目录中,那么这个命令就无法查找到。因为前面已经给find命令在目录中最大的查询目录级别为2,只能查找2层目录下的文件。这样做的目的就是为了让find命令更加精确的定位文件,如果你已经知道了某个文件大概所在的文件目录级数,那么加入-maxdepth n 就很快的能在指定目录中查找成功。 +3. 使用混合查找方式: +find /tmp -size +10000000c -and -mtime +2 // -and +find / -user fred -or -user george // -or 在/tmp目录中查找属于fred或者george这两个用户的文件 +find /tmp ! -user panda // -or 在/tmp目录中查找所有不属于panda的文件 +命令就可以解决了。很简单。 +查找并显示文件的方法 +查找到某个文件是我们的目的,我们更想知道查找到的文件的详细信息和属性, +find / -name "httpd.conf" -ls +下面的表格就是一些常用的查找文件并显示文件信息的参数和使用方法 +选项 用途描述 +-exec command; 查找并执行命令 +-fprint file 打印文件完整文件名 +-fprint0 file 打印文件完整文件名包括空的文件 +-fprintf file format 打印文件格式 +-ok command; 给用户命令执行操作,根据用户的Y 确认输入执行 +-printf format 打印文件格式 +-ls 打印同种文件格式的文件. +2. 普通用户无错误查找: +find / -name access_log 2>/dev/null +说明:当普通用户使用"find”命令来查询某些没有相应权限文件目录时(Linux系统中系统管理员ROOT可以把某些文件目录设置成禁止访问模式) +往往会出现"Permissiondenied."(禁止访问)字样。 2>/dev/null就是表明系统将把错误信息输送到stderrstream 2中. +-exec command; +删除一个目录中的全部文件 +cd “目的目录” +find . -name * -exec rm -f {} \; +-exec 参数后面跟的是 command命令,注意如下几点: +1) command命令的终止,使用 ';' (分号)来判定,在后面必须有一个 ';' +出于不明原因, ';'需要用'\'来转义 ,所以命令整体形式为: -exec rm -f {} \; +2) '{}',使用{}来表示文件名,也就是find前面处理过程中过滤出来的文件,用于command命令进行处理 +1.查询所有保护字符串“Hello”的文件 +find / -exec grep "Hello" {} \; +2.删除所有临时文件 +find / -name "*.tmp" -exec rm -f {} \; +3. 使用混合查找方式: +find /tmp -size +10000000c -and -mtime +2 // -and +find / -user fred -or -user george // -or 在/tmp目录中查找属于fred或者george这两个用户的文件 +find /tmp ! -user panda // -or 在/tmp目录中查找所有不属于panda的文件 +find /tmp ! \( -user 0 -o -user 500 -o -user 501 \) -exec ls -l {} \; +把用户名改成UID就可以了 +find命令使用经验 +find pathname -options [-print -exec -ok] +pathname find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 +-print find命令将匹配的文件输出到标准输出。 +-exec find命令对匹配的文件执行该参数所给出的shell命令。 +相应命令的形式为'command'{} \;,注意{}和\;之间的空格。 +-ok和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行 +文件状态判断: +-mtime: 指定时间文件内容被修改过 +-ctime: 指定时间文件权限被修改过 +-atime: 指定时间文件被读取过 +找出3天“以前”被修改过的文档 +# find /var/log/ -mtime +3 -type f -print +找出3天“内”被修改过的文档 +# find /var/log/ -mtime -3 -type f -print +找出第3天被修改过的文档. +# find /var/log/ -mtime 3 -type f -print +或这样写: +#find /var/log/ -mtime +2 -mtime -4 -type f -print +注: +访问过用amin,修改过用mmin,文件状态改变过用cmin +精确到分钟的用amin,mmin,cmin,精确到天的用atime,mtime,ctime +xargs - build and execute command lines from standard input +在使用find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。 +find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。 +在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高; +而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。 +来看看xargs命令是如何同find命令一起使用的,并给出一些例子。 +下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件 +#find . -type f -print | xargs file +./.kde/Autostart/Autorun.desktop: UTF-8 Unicode English text +./.kde/Autostart/.directory: ISO-8859 text\ +...... +在整个系统中查找内存信息转储文件(core dump) ,然后把结果保存到/tmp/core.log 文件中: +$ find / -name "core" -print | xargs echo "" >/tmp/core.log +上面这个执行太慢,我改成在当前目录下查找 +#find . -name "file*" -print | xargs echo "" > /temp/core.log +# cat /temp/core.log +./file6 +在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限: +# ls -l +drwxrwxrwx 2 sam adm 4096 10月 30 20:14 file6 +-rwxrwxrwx 2 sam adm 0 10月 31 01:01 http3.conf +-rwxrwxrwx 2 sam adm 0 10月 31 01:01 httpd.conf +# find . -perm -7 -print | xargs chmod o-w +# ls -l +drwxrwxr-x 2 sam adm 4096 10月 30 20:14 file6 +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf +用grep命令在所有的普通文件中搜索hostname这个词: +# find . -type f -print | xargs grep "hostname" +./httpd1.conf:# different IP addresses or hostnames and have them handled by the +./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames +on your +用grep命令在当前目录下的所有普通文件中搜索hostnames这个词: +# find . -name \* -type f -print | xargs grep "hostnames" +./httpd1.conf:# different IP addresses or hostnames and have them handled by the +./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames +on your +注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。 +find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令 +使用exec或ok来执行shell命令 +使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的 +在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 +exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{ },一个空格和一个\,最后是一个分号。为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。 +例如:为了用ls -l命令列出所匹配到的文件,可以把ls -l命令放在find命令的-exec选项中 +# find . -type f -exec ls -l { } \; +-rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf +-rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic +-rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README +上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls -l命令将它们列出。 +在/logs目录中查找更改时间在5日以前的文件并删除它们: +$ find logs -type f -mtime +5 -exec rm { } \; +记住:在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心!当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。 +在下面的例子中, find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。 +$ find . -name "*.conf" -mtime +5 -ok rm { } \; +< rm ... ./conf/httpd.conf > ? n +按y键删除文件,按n键不删除。 +任何形式的命令都可以在-exec选项中使用。 +在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“ passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个sam用户。 +# find /etc -name "passwd*" -exec grep "sam" { } \; +sam:x:501:501::/usr/sam:/bin/bash +find 命令用法 +find / -name access_log 2>/dev/null +find /etc -name ‘*srm*’ +find / -amin -10 # 查找在系统中最后10分钟访问的文件 +find / -atime -2 # 查找在系统中最后48小时访问的文件 +find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件 +find / -mtime -1 #查找在系统中最后24小时里修改过的文件 +find / -cmin -5 # 查找在系统中最后5分钟里被改变状态的文件 +find / -ctime -1 #查找在系统中最后24小时里被改变状态的文件 +find / -user reda #查找在系统中属于fred这个用户的文件 +find / -not -user red #查找在系统中不属于red这个用户的文件 +find / -group redagrp # 查找在系统中属于redagrp组的文件 +find / -gid 501 #查找系统中属于组id为501的文件 +find / -user fred -a -group redagrp +find / -user reda -o -user tracy +find / -nouser #查找在系统中属于作废用户的文件 +find / -empty # 查找在系统中为空的文件或者为空的文件夹 +find / -false #查找系统中总是错误的文件 +find / -size +5k #查找系统中大于5k字节的文件 +find / -size +5c #查找系统中大于5字节的文件 +find / -perm +6000 +find / -type b +文件类型: +b 块(缓冲)设备. +c 字符设备. +d 目录. +p 有名管道(FIFO). +f 规则文件. +l 符号链结. +s SOCKET. +find / -maxdepth 2 -name fred +find /tmp -size +10000000c -and -mtime +2 +find / -user reda -or -user tracy +find /tmp ! -user reda +find / -name "httpd.conf" -ls +find / -user reda -exec ls -l {} \; +find / -user reda -ok #确认后执行 +find / -user reda | xargs ls -l +6.2 使用|| +使用||的一般形式为: +命令1 || 命令2 +||的作用有一些不同。如果||左边的命令(命令1)未执行成功,那么就执行||右边的命令(命令2);或者换句话说,“如果这个命令执行失败了|| 那么就执行这个命令”。 +这里有一个使用||的简单例子: +$ cp wopper.txt wopper.bak || echo “if you are seeing this cp failed” +cp: wopper.txt: No such file or directory +if you are seeing this cp failed +在上面的例子中,拷贝命令没有能够被成功执行,因此||后面的命令被执行。 +这里有一个更为实用的例子。我希望从一个审计文件中抽取第1个和第5个域,并将其输出到一个临时文件中,如果这一操作未成功,我希望能够收到一个相应邮件: +$ awk ‘{print $5}’ acc.qtr > qtr.tmp || echo “Sorry the payroll extraction didn’t work” | mail dave +在这里不只可以使用系统命令;这里我们首先对month_end.txt文件执行了一个名为comet的shell脚本,如果该脚本未执行成功,该shell将结束。 +$ comet month_end.txt || exit +6.3 用()和{}将命令结合在一起 +如果希望把几个命令合在一起执行, shell提供了两种方法。既可以在当前shell也可以在子shell中执行一组命令。 +为了在当前shell中执行一组命令,可以用命令分隔符隔开每一个命令,并把所有的命令用圆括号()括起来。 +它的一般形式为: +(命令1;命令2;. . .) +如果使用{ }来代替(),那么相应的命令将在子shell而不是当前shell中作为一个整体被执行,只有在{ }中所有命令的输出作为一个整体被重定向时,其中的命令才被放到子shell中执行,否则在当前shell执行。它的一般形式为: +{命令1;命令2;. . . } +我很少单独使用这两种方法。我一般只和&&或||一起使用这两种方法。 +再回到前面那个comet脚本的例子,如果这个脚本执行失败了,我很可能会希望执行两个以上的命令,而不只是一个命令。我可以使用这两种方法。这是原先那个例子: +$ comet month_end.txt || exit +现在如果该脚本执行失败了,我希望先给自己发个邮件,然后再退出,可以用下面的方法来实现: +$ comet month_end || (echo “Hello, guess what! Comet did not work”|mail dave;exit) +在上面的例子中,如果只使用了命令分隔符而没有把它们组合在一起,shell将直接执行最后一个命令(exit)。 +我们再回头来看看前面那个使用&&排序的例子,下面是原来的那个例子: +$ sort quarter_end.txt > quarter.sorted && lp quarter.sorted +使用命令组合的方法,如果sort命令执行成功了,可以先将输出文件拷贝到一个日志区,然后再打印。 +6.4 小结 +在编写shell脚本时,使用&&和||对构造判断语句非常有用。如果希望在前一个命令执行失败的情况不执行后面的命令,那么本章所讲述的方法非常简单有效。使用这样的方法,可以根据&&或||前面命令的返回值来控制其后面命令的执行。 +``` + +#### 暂未整理二 + +```sh + +一、find 命令格式 + + +1、find命令的一般形式为; + +find pathname -options [-print -exec -ok ...] + +2、find命令的参数; + +pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。 +-print: find命令将匹配的文件输出到标准输出。 +-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' {} \;,注意{}和\;之间的空格。 +-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。 + +3、find命令选项 + +-name + +按照文件名查找文件。 + +-perm +按照文件权限来查找文件。 + +-prune +使用这一选项可以使find命令不在当前指定的目录中查找,如果同时使用-depth选项,那么-prune将被find命令忽略。 + +-user +按照文件属主来查找文件。 + +-group +按照文件所属的组来查找文件。 + +-mtime -n +n +按照文件的更改时间来查找文件, - n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前。find命令还有-atime和-ctime 选项,但它们都和-m time选项。 + +-nogroup +查找无有效所属组的文件,即该文件所属的组在/etc/groups中不存在。 + +-nouser +查找无有效属主的文件,即该文件的属主在/etc/passwd中不存在。 +-newer file1 ! file2 + +查找更改时间比文件file1新但比文件file2旧的文件。 +-type + +查找某一类型的文件,诸如: + +b - 块设备文件。 +d - 目录。 +c - 字符设备文件。 +p - 管道文件。 +l - 符号链接文件。 +f - 普通文件。 + +-size n:[c] 查找文件长度为n块的文件,带有c时表示文件长度以字节计。 +-depth:在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。 +-fstype:查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。 + +-mount:在查找文件时不跨越文件系统mount点。 +-follow:如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。 +-cpio:对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。 +另外,下面三个的区别: + +-amin n +查找系统中最后N分钟访问的文件 + +-atime n +查找系统中最后n*24小时访问的文件 + +-cmin n +查找系统中最后N分钟被改变文件状态的文件 + +-ctime n +查找系统中最后n*24小时被改变文件状态的文件 + +-mmin n +查找系统中最后N分钟被改变文件数据的文件 + +-mtime n +查找系统中最后n*24小时被改变文件数据的文件 + +4、使用exec或ok来执行shell命令 + +使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的 + +在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 + +exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{ },一个空格和一个\,最后是一个分号。为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。 + +例如:为了用ls -l命令列出所匹配到的文件,可以把ls -l命令放在find命令的-exec选项中 + +# find . -type f -exec ls -l {} \; +-rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf +-rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic +-rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README +上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls -l命令将它们列出。 +在/logs目录中查找更改时间在5日以前的文件并删除它们: + +$ find logs -type f -mtime +5 -exec rm {} \; +记住:在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心!当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。 + +在下面的例子中, find命令在当前目录中查找所有文件名以.LOG结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。 + +$ find . -name "*.log" -mtime +5 -ok rm {} \; +< rm ... ./conf/httpd.conf > ? n +按y键删除文件,按n键不删除。 + +任何形式的命令都可以在-exec选项中使用。 + +在下面的例子中我们使用grep命令。find命令首先匹配所有文件名为“ passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个sam用户。 + +# find /etc -name "passwd*" -exec grep "sam" {} \; +sam:x:501:501::/usr/sam:/bin/bash + +二、find命令的例子; + + +1、查找当前用户主目录下的所有文件: + +下面两种方法都可以使用 + +$ find $HOME -print +$ find ~ -print + +2、让当前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件; + +$ find . -type f -perm 644 -exec ls -l {} \; + +3、为了查找系统中所有文件长度为0的普通文件,并列出它们的完整路径; + +$ find / -type f -size 0 -exec ls -l {} \; + +4、查找/var/logs目录中更改时间在7日以前的普通文件,并在删除之前询问它们; + +$ find /var/logs -type f -mtime +7 -ok rm {} \; + +5、为了查找系统中所有属于root组的文件; + +$find . -group root -exec ls -l {} \; +-rw-r--r-- 1 root root 595 10月 31 01:09 ./fie1 + +6、find命令将删除当目录中访问时间在7日以来、含有数字后缀的admin.log文件。 + +该命令只检查三位数字,所以相应文件的后缀不要超过999。先建几个admin.log*的文件 ,才能使用下面这个命令 + +$ find . -name "admin.log[0-9][0-9][0-9]" -atime -7 -ok +rm {} \; +< rm ... ./admin.log001 > ? n +< rm ... ./admin.log002 > ? n +< rm ... ./admin.log042 > ? n +< rm ... ./admin.log942 > ? n + +7、为了查找当前文件系统中的所有目录并排序; + +$ find . -type d | sort + +8、为了查找系统中所有的rmt磁带设备; + +$ find /dev/rmt -print + +三、xargs + +xargs – build and execute command lines from standard input + +在使用find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。 + +find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。 + +在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高; + +而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。 + +来看看xargs命令是如何同find命令一起使用的,并给出一些例子。 + +下面的例子查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件 + +#find . -type f -print | xargs file +./.kde/Autostart/Autorun.desktop: UTF-8 Unicode English text +./.kde/Autostart/.directory: ISO-8859 text\ +...... +在整个系统中查找内存信息转储文件(core dump) ,然后把结果保存到/tmp/core.log 文件中: + +$ find / -name "core" -print | xargs echo "" >/tmp/core.log +上面这个执行太慢,我改成在当前目录下查找 + +#find . -name "file*" -print | xargs echo "" > /temp/core.log +# cat /temp/core.log +./file6 +在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限: + +# ls -l +drwxrwxrwx 2 sam adm 4096 10月 30 20:14 file6 +-rwxrwxrwx 2 sam adm 0 10月 31 01:01 http3.conf +-rwxrwxrwx 2 sam adm 0 10月 31 01:01 httpd.conf + +# find . -perm -7 -print | xargs chmod o-w +# ls -l +drwxrwxr-x 2 sam adm 4096 10月 30 20:14 file6 +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf +用grep命令在所有的普通文件中搜索hostname这个词: + +# find . -type f -print | xargs grep "hostname" +./httpd1.conf:# different IP addresses or hostnames and have them handled by the +./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames +on your +用grep命令在当前目录下的所有普通文件中搜索hostnames这个词: + +# find . -name \* -type f -print | xargs grep "hostnames" +./httpd1.conf:# different IP addresses or hostnames and have them handled by the +./httpd1.conf:# VirtualHost: If you want to maintain multiple domains/hostnames +on your +注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。 + +find命令配合使用exec和xargs可以使用户对所匹配到的文件执行几乎所有的命令。 + + +四、find 命令的参数 + +下面是find一些常用参数的例子,有用到的时候查查就行了,像上面前几个贴子,都用到了其中的的一些参数,也可以用man或查看论坛里其它贴子有find的命令手册 + + +1、使用name选项 + +文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用。 + +可以使用某种文件名模式来匹配文件,记住要用引号将文件名模式引起来。 + +不管当前路径是什么,如果想要在自己的根目录$HOME中查找文件名符合*.txt的文件,使用~作为 ‘pathname’参数,波浪号~代表了你的$HOME目录。 + +$ find ~ -name "*.txt" -print +想要在当前目录及子目录中查找所有的‘ *.txt’文件,可以用: + +$ find . -name "*.txt" -print +想要的当前目录及子目录中查找文件名以一个大写字母开头的文件,可以用: + +$ find . -name "[A-Z]*" -print +想要在/etc目录中查找文件名以host开头的文件,可以用: + +$ find /etc -name "host*" -print +想要查找$HOME目录中的文件,可以用: + +$ find ~ -name "*" -print 或find . -print +要想让系统高负荷运行,就从根目录开始查找所有的文件。 + +$ find / -name "*" -print +如果想在当前目录查找文件名以两个小写字母开头,跟着是两个数字,最后是.txt的文件,下面的命令就能够返回名为ax37.txt的文件: + +$find . -name "[a-z][a-z][0--9][0--9].txt" -print + +2、用perm选项 + +按照文件权限模式用-perm选项,按文件权限模式来查找文件的话。最好使用八进制的权限表示法。 + +如在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用: + +$ find . -perm 755 -print +还有一种表达方法:在八进制数字前面要加一个横杠-,表示都匹配,如-007就相当于777,-006相当于666 + +# ls -l +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 http3.conf +-rw-rw-rw- 1 sam adm 34890 10月 31 00:57 httpd1.conf +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf +drw-rw-rw- 2 gem group 4096 10月 26 19:48 sam +-rw-rw-rw- 1 root root 2792 10月 31 20:19 temp + +# find . -perm 006 +# find . -perm -006 +./sam +./httpd1.conf +./temp +-perm mode:文件许可正好符合mode + +-perm +mode:文件许可部分符合mode + +-perm -mode: 文件许可完全符合mode + + +3、忽略某个目录 + +如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了-depth选项,那么-prune选项就会被find命令忽略。 + +如果希望在/apps目录下查找文件,但不希望在/apps/bin目录下查找,可以用: + +$ find /apps -path "/apps/bin" -prune -o -print + +4、使用find查找文件的时候怎么避开某个文件目录 + +比如要在/usr/sam目录下查找不在dir1子目录之内的所有文件 + +find /usr/sam -path "/usr/sam/dir1" -prune -o -print +find [-path ..] [expression] 在路径列表的后面的是表达式 +-path “/usr/sam” -prune -o -print 是 -path “/usr/sam” -a -prune -o +-print 的简写表达式按顺序求值, -a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果 -path “/usr/sam” 为真,则求值 -prune , -prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假。如果 -path “/usr/sam” -a -prune 为假,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值 -print,或逻辑表达式为真。 + +这个表达式组合特例可以用伪码写为 + +if -path "/usr/sam" then +-prune +else +-print +避开多个文件夹 + +find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print +圆括号表示表达式的结合。 + +\ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。 +查找某一确定文件,-name等选项加在-o 之后 + +#find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print + +5、使用user和nouser选项 + +按文件属主查找文件,如在$HOME目录中查找文件属主为sam的文件,可以用: + +$ find ~ -user sam -print +在/etc目录下查找文件属主为uucp的文件: + +$ find /etc -user uucp -print +为了查找属主帐户已经被删除的文件,可以使用-nouser选项。这样就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件。在使用-nouser选项时,不必给出用户名; find命令能够为你完成相应的工作。 + +例如,希望在/home目录下查找所有的这类文件,可以用: + +$ find /home -nouser -print + +6、使用group和nogroup选项 + +就像user和nouser选项一样,针对文件所属于的用户组, find命令也具有同样的选项,为了在/apps目录下查找属于gem用户组的文件,可以用: + +$ find /apps -group gem -print +要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样的文件 + +$ find / -nogroup-print + +7、按照更改时间或访问时间等查找文件 + +如果希望按照更改时间来查找文件,可以使用mtime,atime或ctime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时就可以用mtime选项来查找这样的文件。 + +用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距今n日以前的文件。 + +希望在系统根目录下查找更改时间在5日以内的文件,可以用: + +$ find / -mtime -5 -print +为了在/var/adm目录下查找更改时间在3日以前的文件,可以用: + +$ find /var/adm -mtime +3 -print + +8、查找比某个文件新或旧的文件 + +如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可以使用-newer选项。它的一般形式为: + +newest_file_name ! oldest_file_name +其中,!是逻辑非符号。 + +查找更改时间比文件sam新但比文件temp旧的文件: + +例:有两个文件 + +-rw-r--r-- 1 sam adm 0 10月 31 01:07 fiel +-rw-rw-rw- 1 sam adm 34890 10月 31 00:57 httpd1.conf +-rwxrwxr-x 2 sam adm 0 10月 31 01:01 httpd.conf +drw-rw-rw- 2 gem group 4096 10月 26 19:48 sam +-rw-rw-rw- 1 root root 2792 10月 31 20:19 temp + +# find -newer httpd1.conf ! -newer temp -ls +1077669 0 -rwxrwxr-x 2 sam adm 0 10月 31 01:01 ./httpd.conf +1077671 4 -rw-rw-rw- 1 root root 2792 10月 31 20:19 ./temp +1077673 0 -rw-r--r-- 1 sam adm 0 10月 31 01:07 ./fiel +查找更改时间在比temp文件新的文件: + +$ find . -newer temp -print + +9、使用type选项 + +在/etc目录下查找所有的目录,可以用: + +$ find /etc -type d -print +在当前目录下查找除目录以外的所有类型的文件,可以用: + +$ find . ! -type d -print +在/etc目录下查找所有的符号链接文件,可以用 + +$ find /etc -type l -print + +10、使用size选项 + +可以按照文件长度来查找文件,这里所指的文件长度既可以用块(block)来计量,也可以用字节来计量。以字节计量文件长度的表达形式为N c;以块计量文件长度只用数字表示即可。 + +在按照文件长度查找文件时,一般使用这种以字节表示的文件长度,在查看文件系统的大小,因为这时使用块来计量更容易转换。 +在当前目录下查找文件长度大于1 M字节的文件: + +$ find . -size +1000000c -print +查找当前目录中大于10M的文件: + +find . -size +10000k -exec ls -ld {} ; +将find出来的文件复制到另一个地方: + +find *.c -exec cp '{}' /tmp ';' +在/home/apache目录下查找文件长度恰好为100字节的文件: + +$ find /home/apache -size 100c -print +在当前目录下查找长度超过10块的文件(一块等于512字节): + +$ find . -size +10 -print + +11、使用depth选项 + +在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个原因就是,当在使用find命令向磁带上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。 + +在下面的例子中, find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。 + +它将首先匹配所有的文件然后再进入子目录中查找。 + +$ find / -name "CON.FILE" -depth -print + +12、使用mount选项 + +在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。 + +从当前目录开始查找位于本文件系统中文件名以XC结尾的文件: + +$ find . -name "*.XC" -mount -print + ``` \ No newline at end of file diff --git a/LinuxCommands/findfs.md b/Linux_man_cn/findfs.md similarity index 100% rename from LinuxCommands/findfs.md rename to Linux_man_cn/findfs.md diff --git a/LinuxCommands/finger.md b/Linux_man_cn/finger.md similarity index 100% rename from LinuxCommands/finger.md rename to Linux_man_cn/finger.md diff --git a/LinuxCommands/firewall-cmd.md b/Linux_man_cn/firewall-cmd.md similarity index 100% rename from LinuxCommands/firewall-cmd.md rename to Linux_man_cn/firewall-cmd.md diff --git a/LinuxCommands/fmt.md b/Linux_man_cn/fmt.md similarity index 100% rename from LinuxCommands/fmt.md rename to Linux_man_cn/fmt.md diff --git a/LinuxCommands/fold.md b/Linux_man_cn/fold.md similarity index 100% rename from LinuxCommands/fold.md rename to Linux_man_cn/fold.md diff --git a/LinuxCommands/free.md b/Linux_man_cn/free.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/free.md rename to Linux_man_cn/free.md index f36144f..deb9cfa --- a/LinuxCommands/free.md +++ b/Linux_man_cn/free.md @@ -1,159 +1,159 @@ -free -=== - -显示内存的使用情况 - -## 补充说明 - -**free命令** 可以显示当前系统未使用的和已使用的内存数目,还可以显示被内核使用的内存缓冲区。 - -### 语法 - -``` -free(选项) -``` - -### 选项 - -```bash --b # 以Byte为单位显示内存使用情况; --k # 以KB为单位显示内存使用情况; --m # 以MB为单位显示内存使用情况; --g # 以GB为单位显示内存使用情况。 --o # 不显示缓冲区调节列; --s<间隔秒数> # 持续观察内存使用状况; --t # 显示内存总和列; --V # 显示版本信息。 -``` - -### 实例 - -```bash -free -t # 以总和的形式显示内存的使用信息 -free -s 10 # 周期性的查询内存使用信息,每10s 执行一次命令 -``` - -显示内存使用情况 - -```bash -free -m - total used free shared buffers cached -Mem: 2016 1973 42 0 163 1497 --/+ buffers/cache: 312 1703 -Swap: 4094 0 4094 -``` - - **第一部分Mem行解释:** - -``` -total:内存总数; -used:已经使用的内存数; -free:空闲的内存数; -shared:当前已经废弃不用; -buffers Buffer:缓存内存数; -cached Page:缓存内存数。 -``` - -关系:total = used + free - - **第二部分(-/+ buffers/cache)解释:** - -``` -(-buffers/cache) used内存数:第一部分Mem行中的 used – buffers – cached -(+buffers/cache) free内存数: 第一部分Mem行中的 free + buffers + cached -``` - -可见-buffers/cache反映的是被程序实实在在吃掉的内存,而+buffers/cache反映的是可以挪用的内存总数。 - -第三部分是指交换分区。 - -输出结果的第四行是交换分区SWAP的,也就是我们通常所说的虚拟内存。 -区别:第二行(mem)的used/free与第三行(-/+ buffers/cache) used/free的区别。 这两个的区别在于使用的角度来看,第一行是从OS的角度来看,因为对于OS,buffers/cached 都是属于被使用,所以他的可用内存是2098428KB,已用内存是30841684KB,其中包括,内核(OS)使用+Application(X, oracle,etc)使用的+buffers+cached. - -第三行所指的是从应用程序角度来看,对于应用程序来说,buffers/cached 是等于可用的,因为buffer/cached是为了提高文件读取的性能,当应用程序需在用到内存的时候,buffer/cached会很快地被回收。 - -所以从应用程序的角度来说,可用内存=系统free memory+buffers+cached。 -如本机情况的可用内存为: - -18007156=2098428KB+4545340KB+11363424KB - -接下来解释什么时候内存会被交换,以及按什么方交换。 - -当可用内存少于额定值的时候,就会开会进行交换。如何看额定值: - -```bash -cat /proc/meminfo - -MemTotal: 16140816 kB -MemFree: 816004 kB -MemAvailable: 2913824 kB -Buffers: 17912 kB -Cached: 2239076 kB -SwapCached: 0 kB -Active: 12774804 kB -Inactive: 1594328 kB -Active(anon): 12085544 kB -Inactive(anon): 94572 kB -Active(file): 689260 kB -Inactive(file): 1499756 kB -Unevictable: 116888 kB -Mlocked: 116888 kB -SwapTotal: 8191996 kB -SwapFree: 8191996 kB -Dirty: 56 kB -Writeback: 0 kB -AnonPages: 12229228 kB -Mapped: 117136 kB -Shmem: 58736 kB -Slab: 395568 kB -SReclaimable: 246700 kB -SUnreclaim: 148868 kB -KernelStack: 30496 kB -PageTables: 165104 kB -NFS_Unstable: 0 kB -Bounce: 0 kB -WritebackTmp: 0 kB -CommitLimit: 16262404 kB -Committed_AS: 27698600 kB -VmallocTotal: 34359738367 kB -VmallocUsed: 311072 kB -VmallocChunk: 34350899200 kB -HardwareCorrupted: 0 kB -AnonHugePages: 3104768 kB -HugePages_Total: 0 -HugePages_Free: 0 -HugePages_Rsvd: 0 -HugePages_Surp: 0 -Hugepagesize: 2048 kB -DirectMap4k: 225536 kB -DirectMap2M: 13279232 kB -DirectMap1G: 5242880 kB -``` - -交换将通过三个途径来减少系统中使用的物理页面的个数:  - -1. 减少缓冲与页面cache的大小, -2. 将系统V类型的内存页面交换出去,  -3. 换出或者丢弃页面。(Application 占用的内存页,也就是物理内存不足)。 - -事实上,少量地使用swap是不是影响到系统性能的。 - -那buffers和cached都是缓存,两者有什么区别呢? - -为了提高磁盘存取效率, Linux做了一些精心的设计, 除了对dentry进行缓存(用于VFS,加速文件路径名到inode的转换), 还采取了两种主要Cache方式: - -Buffer Cache和Page Cache。前者针对磁盘块的读写,后者针对文件inode的读写。这些Cache有效缩短了 I/O系统调用(比如read,write,getdents)的时间。 -磁盘的操作有逻辑级(文件系统)和物理级(磁盘块),这两种Cache就是分别缓存逻辑和物理级数据的。 - -Page cache实际上是针对文件系统的,是文件的缓存,在文件层面上的数据会缓存到page cache。文件的逻辑层需要映射到实际的物理磁盘,这种映射关系由文件系统来完成。当page cache的数据需要刷新时,page cache中的数据交给buffer cache,因为Buffer Cache就是缓存磁盘块的。但是这种处理在2.6版本的内核之后就变的很简单了,没有真正意义上的cache操作。 - -Buffer cache是针对磁盘块的缓存,也就是在没有文件系统的情况下,直接对磁盘进行操作的数据会缓存到buffer cache中,例如,文件系统的元数据都会缓存到buffer cache中。 - -简单说来,page cache用来缓存文件数据,buffer cache用来缓存磁盘数据。在有文件系统的情况下,对文件操作,那么数据会缓存到page cache,如果直接采用dd等工具对磁盘进行读写,那么数据会缓存到buffer cache。 - -所以我们看linux,只要不用swap的交换空间,就不用担心自己的内存太少.如果常常swap用很多,可能你就要考虑加物理内存了.这也是linux看内存是否够用的标准. - -如果是应用服务器的话,一般只看第二行,+buffers/cache,即对应用程序来说free的内存太少了,也是该考虑优化程序或加内存了。 - - - +free +=== + +显示内存的使用情况 + +## 补充说明 + +**free命令** 可以显示当前系统未使用的和已使用的内存数目,还可以显示被内核使用的内存缓冲区。 + +### 语法 + +``` +free(选项) +``` + +### 选项 + +```bash +-b # 以Byte为单位显示内存使用情况; +-k # 以KB为单位显示内存使用情况; +-m # 以MB为单位显示内存使用情况; +-g # 以GB为单位显示内存使用情况。 +-o # 不显示缓冲区调节列; +-s<间隔秒数> # 持续观察内存使用状况; +-t # 显示内存总和列; +-V # 显示版本信息。 +``` + +### 实例 + +```bash +free -t # 以总和的形式显示内存的使用信息 +free -s 10 # 周期性的查询内存使用信息,每10s 执行一次命令 +``` + +显示内存使用情况 + +```bash +free -m + total used free shared buffers cached +Mem: 2016 1973 42 0 163 1497 +-/+ buffers/cache: 312 1703 +Swap: 4094 0 4094 +``` + + **第一部分Mem行解释:** + +``` +total:内存总数; +used:已经使用的内存数; +free:空闲的内存数; +shared:当前已经废弃不用; +buffers Buffer:缓存内存数; +cached Page:缓存内存数。 +``` + +关系:total = used + free + + **第二部分(-/+ buffers/cache)解释:** + +``` +(-buffers/cache) used内存数:第一部分Mem行中的 used – buffers – cached +(+buffers/cache) free内存数: 第一部分Mem行中的 free + buffers + cached +``` + +可见-buffers/cache反映的是被程序实实在在吃掉的内存,而+buffers/cache反映的是可以挪用的内存总数。 + +第三部分是指交换分区。 + +输出结果的第四行是交换分区SWAP的,也就是我们通常所说的虚拟内存。 +区别:第二行(mem)的used/free与第三行(-/+ buffers/cache) used/free的区别。 这两个的区别在于使用的角度来看,第一行是从OS的角度来看,因为对于OS,buffers/cached 都是属于被使用,所以他的可用内存是2098428KB,已用内存是30841684KB,其中包括,内核(OS)使用+Application(X, oracle,etc)使用的+buffers+cached. + +第三行所指的是从应用程序角度来看,对于应用程序来说,buffers/cached 是等于可用的,因为buffer/cached是为了提高文件读取的性能,当应用程序需在用到内存的时候,buffer/cached会很快地被回收。 + +所以从应用程序的角度来说,可用内存=系统free memory+buffers+cached。 +如本机情况的可用内存为: + +18007156=2098428KB+4545340KB+11363424KB + +接下来解释什么时候内存会被交换,以及按什么方交换。 + +当可用内存少于额定值的时候,就会开会进行交换。如何看额定值: + +```bash +cat /proc/meminfo + +MemTotal: 16140816 kB +MemFree: 816004 kB +MemAvailable: 2913824 kB +Buffers: 17912 kB +Cached: 2239076 kB +SwapCached: 0 kB +Active: 12774804 kB +Inactive: 1594328 kB +Active(anon): 12085544 kB +Inactive(anon): 94572 kB +Active(file): 689260 kB +Inactive(file): 1499756 kB +Unevictable: 116888 kB +Mlocked: 116888 kB +SwapTotal: 8191996 kB +SwapFree: 8191996 kB +Dirty: 56 kB +Writeback: 0 kB +AnonPages: 12229228 kB +Mapped: 117136 kB +Shmem: 58736 kB +Slab: 395568 kB +SReclaimable: 246700 kB +SUnreclaim: 148868 kB +KernelStack: 30496 kB +PageTables: 165104 kB +NFS_Unstable: 0 kB +Bounce: 0 kB +WritebackTmp: 0 kB +CommitLimit: 16262404 kB +Committed_AS: 27698600 kB +VmallocTotal: 34359738367 kB +VmallocUsed: 311072 kB +VmallocChunk: 34350899200 kB +HardwareCorrupted: 0 kB +AnonHugePages: 3104768 kB +HugePages_Total: 0 +HugePages_Free: 0 +HugePages_Rsvd: 0 +HugePages_Surp: 0 +Hugepagesize: 2048 kB +DirectMap4k: 225536 kB +DirectMap2M: 13279232 kB +DirectMap1G: 5242880 kB +``` + +交换将通过三个途径来减少系统中使用的物理页面的个数:  + +1. 减少缓冲与页面cache的大小, +2. 将系统V类型的内存页面交换出去,  +3. 换出或者丢弃页面。(Application 占用的内存页,也就是物理内存不足)。 + +事实上,少量地使用swap是不是影响到系统性能的。 + +那buffers和cached都是缓存,两者有什么区别呢? + +为了提高磁盘存取效率, Linux做了一些精心的设计, 除了对dentry进行缓存(用于VFS,加速文件路径名到inode的转换), 还采取了两种主要Cache方式: + +Buffer Cache和Page Cache。前者针对磁盘块的读写,后者针对文件inode的读写。这些Cache有效缩短了 I/O系统调用(比如read,write,getdents)的时间。 +磁盘的操作有逻辑级(文件系统)和物理级(磁盘块),这两种Cache就是分别缓存逻辑和物理级数据的。 + +Page cache实际上是针对文件系统的,是文件的缓存,在文件层面上的数据会缓存到page cache。文件的逻辑层需要映射到实际的物理磁盘,这种映射关系由文件系统来完成。当page cache的数据需要刷新时,page cache中的数据交给buffer cache,因为Buffer Cache就是缓存磁盘块的。但是这种处理在2.6版本的内核之后就变的很简单了,没有真正意义上的cache操作。 + +Buffer cache是针对磁盘块的缓存,也就是在没有文件系统的情况下,直接对磁盘进行操作的数据会缓存到buffer cache中,例如,文件系统的元数据都会缓存到buffer cache中。 + +简单说来,page cache用来缓存文件数据,buffer cache用来缓存磁盘数据。在有文件系统的情况下,对文件操作,那么数据会缓存到page cache,如果直接采用dd等工具对磁盘进行读写,那么数据会缓存到buffer cache。 + +所以我们看linux,只要不用swap的交换空间,就不用担心自己的内存太少.如果常常swap用很多,可能你就要考虑加物理内存了.这也是linux看内存是否够用的标准. + +如果是应用服务器的话,一般只看第二行,+buffers/cache,即对应用程序来说free的内存太少了,也是该考虑优化程序或加内存了。 + + + diff --git a/LinuxCommands/fsck.ext4.md b/Linux_man_cn/fsck.ext4.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/fsck.ext4.md rename to Linux_man_cn/fsck.ext4.md diff --git a/LinuxCommands/fsck.md b/Linux_man_cn/fsck.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/fsck.md rename to Linux_man_cn/fsck.md index e7d62b7..c1ffe9a --- a/LinuxCommands/fsck.md +++ b/Linux_man_cn/fsck.md @@ -1,6 +1,6 @@ fsck === - + 检查并且试图修复文件系统中的错误 ## 补充说明 diff --git a/LinuxCommands/ftp.md b/Linux_man_cn/ftp.md similarity index 100% rename from LinuxCommands/ftp.md rename to Linux_man_cn/ftp.md diff --git a/LinuxCommands/ftpcount.md b/Linux_man_cn/ftpcount.md similarity index 100% rename from LinuxCommands/ftpcount.md rename to Linux_man_cn/ftpcount.md diff --git a/LinuxCommands/ftpshut.md b/Linux_man_cn/ftpshut.md similarity index 100% rename from LinuxCommands/ftpshut.md rename to Linux_man_cn/ftpshut.md diff --git a/LinuxCommands/ftptop.md b/Linux_man_cn/ftptop.md similarity index 100% rename from LinuxCommands/ftptop.md rename to Linux_man_cn/ftptop.md diff --git a/LinuxCommands/ftpwho.md b/Linux_man_cn/ftpwho.md similarity index 100% rename from LinuxCommands/ftpwho.md rename to Linux_man_cn/ftpwho.md diff --git a/LinuxCommands/fuser.md b/Linux_man_cn/fuser.md similarity index 100% rename from LinuxCommands/fuser.md rename to Linux_man_cn/fuser.md diff --git a/LinuxCommands/gcc.md b/Linux_man_cn/gcc.md similarity index 100% rename from LinuxCommands/gcc.md rename to Linux_man_cn/gcc.md diff --git a/LinuxCommands/gcov.md b/Linux_man_cn/gcov.md similarity index 100% rename from LinuxCommands/gcov.md rename to Linux_man_cn/gcov.md diff --git a/LinuxCommands/gdb.md b/Linux_man_cn/gdb.md similarity index 100% rename from LinuxCommands/gdb.md rename to Linux_man_cn/gdb.md diff --git a/LinuxCommands/get_module.md b/Linux_man_cn/get_module.md similarity index 100% rename from LinuxCommands/get_module.md rename to Linux_man_cn/get_module.md diff --git a/LinuxCommands/getenforce.md b/Linux_man_cn/getenforce.md similarity index 100% rename from LinuxCommands/getenforce.md rename to Linux_man_cn/getenforce.md diff --git a/LinuxCommands/getsebool.md b/Linux_man_cn/getsebool.md similarity index 100% rename from LinuxCommands/getsebool.md rename to Linux_man_cn/getsebool.md diff --git a/LinuxCommands/gpasswd.md b/Linux_man_cn/gpasswd.md similarity index 100% rename from LinuxCommands/gpasswd.md rename to Linux_man_cn/gpasswd.md diff --git a/LinuxCommands/gpm.md b/Linux_man_cn/gpm.md similarity index 100% rename from LinuxCommands/gpm.md rename to Linux_man_cn/gpm.md diff --git a/LinuxCommands/grep.md b/Linux_man_cn/grep.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/grep.md rename to Linux_man_cn/grep.md diff --git a/LinuxCommands/groupadd.md b/Linux_man_cn/groupadd.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/groupadd.md rename to Linux_man_cn/groupadd.md index 03065a9..810ad78 --- a/LinuxCommands/groupadd.md +++ b/Linux_man_cn/groupadd.md @@ -1,6 +1,6 @@ groupadd === - + 用于创建一个新的工作组 ## 补充说明 diff --git a/LinuxCommands/groupdel.md b/Linux_man_cn/groupdel.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/groupdel.md rename to Linux_man_cn/groupdel.md index f4af465..9d2b6da --- a/LinuxCommands/groupdel.md +++ b/Linux_man_cn/groupdel.md @@ -1,6 +1,6 @@ groupdel === - + 用于删除指定的工作组 ## 补充说明 diff --git a/LinuxCommands/groupmod.md b/Linux_man_cn/groupmod.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/groupmod.md rename to Linux_man_cn/groupmod.md index b3ff2a7..f814738 --- a/LinuxCommands/groupmod.md +++ b/Linux_man_cn/groupmod.md @@ -1,6 +1,6 @@ groupmod === - + 更改群组识别码或名称 ## 补充说明 diff --git a/LinuxCommands/groups.md b/Linux_man_cn/groups.md similarity index 100% rename from LinuxCommands/groups.md rename to Linux_man_cn/groups.md diff --git a/LinuxCommands/grpck.md b/Linux_man_cn/grpck.md similarity index 100% rename from LinuxCommands/grpck.md rename to Linux_man_cn/grpck.md diff --git a/LinuxCommands/grpconv.md b/Linux_man_cn/grpconv.md similarity index 100% rename from LinuxCommands/grpconv.md rename to Linux_man_cn/grpconv.md diff --git a/LinuxCommands/grpunconv.md b/Linux_man_cn/grpunconv.md similarity index 100% rename from LinuxCommands/grpunconv.md rename to Linux_man_cn/grpunconv.md diff --git a/LinuxCommands/grub.md b/Linux_man_cn/grub.md similarity index 100% rename from LinuxCommands/grub.md rename to Linux_man_cn/grub.md diff --git a/LinuxCommands/gunzip.md b/Linux_man_cn/gunzip.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/gunzip.md rename to Linux_man_cn/gunzip.md diff --git a/LinuxCommands/gzexe.md b/Linux_man_cn/gzexe.md similarity index 100% rename from LinuxCommands/gzexe.md rename to Linux_man_cn/gzexe.md diff --git a/LinuxCommands/gzip.md b/Linux_man_cn/gzip.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/gzip.md rename to Linux_man_cn/gzip.md diff --git a/LinuxCommands/halt.md b/Linux_man_cn/halt.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/halt.md rename to Linux_man_cn/halt.md diff --git a/LinuxCommands/hdparm.md b/Linux_man_cn/hdparm.md similarity index 100% rename from LinuxCommands/hdparm.md rename to Linux_man_cn/hdparm.md diff --git a/LinuxCommands/head.md b/Linux_man_cn/head.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/head.md rename to Linux_man_cn/head.md diff --git a/LinuxCommands/help.md b/Linux_man_cn/help.md similarity index 100% rename from LinuxCommands/help.md rename to Linux_man_cn/help.md diff --git a/LinuxCommands/hexdump.md b/Linux_man_cn/hexdump.md similarity index 100% rename from LinuxCommands/hexdump.md rename to Linux_man_cn/hexdump.md diff --git a/LinuxCommands/history.md b/Linux_man_cn/history.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/history.md rename to Linux_man_cn/history.md diff --git a/LinuxCommands/host.md b/Linux_man_cn/host.md similarity index 100% rename from LinuxCommands/host.md rename to Linux_man_cn/host.md diff --git a/LinuxCommands/hostid.md b/Linux_man_cn/hostid.md similarity index 100% rename from LinuxCommands/hostid.md rename to Linux_man_cn/hostid.md diff --git a/LinuxCommands/hostname.md b/Linux_man_cn/hostname.md similarity index 100% rename from LinuxCommands/hostname.md rename to Linux_man_cn/hostname.md diff --git a/LinuxCommands/hping3.md b/Linux_man_cn/hping3.md similarity index 100% rename from LinuxCommands/hping3.md rename to Linux_man_cn/hping3.md diff --git a/LinuxCommands/htdigest.md b/Linux_man_cn/htdigest.md similarity index 100% rename from LinuxCommands/htdigest.md rename to Linux_man_cn/htdigest.md diff --git a/LinuxCommands/htop.md b/Linux_man_cn/htop.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/htop.md rename to Linux_man_cn/htop.md diff --git a/LinuxCommands/htpasswd.md b/Linux_man_cn/htpasswd.md similarity index 100% rename from LinuxCommands/htpasswd.md rename to Linux_man_cn/htpasswd.md diff --git a/LinuxCommands/hwclock.md b/Linux_man_cn/hwclock.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/hwclock.md rename to Linux_man_cn/hwclock.md diff --git a/LinuxCommands/iconv.md b/Linux_man_cn/iconv.md similarity index 100% rename from LinuxCommands/iconv.md rename to Linux_man_cn/iconv.md diff --git a/LinuxCommands/id.md b/Linux_man_cn/id.md similarity index 100% rename from LinuxCommands/id.md rename to Linux_man_cn/id.md diff --git a/LinuxCommands/ifcfg.md b/Linux_man_cn/ifcfg.md similarity index 100% rename from LinuxCommands/ifcfg.md rename to Linux_man_cn/ifcfg.md diff --git a/LinuxCommands/ifconfig.md b/Linux_man_cn/ifconfig.md similarity index 100% rename from LinuxCommands/ifconfig.md rename to Linux_man_cn/ifconfig.md diff --git a/LinuxCommands/ifdown.md b/Linux_man_cn/ifdown.md similarity index 100% rename from LinuxCommands/ifdown.md rename to Linux_man_cn/ifdown.md diff --git a/LinuxCommands/ifstat.md b/Linux_man_cn/ifstat.md similarity index 100% rename from LinuxCommands/ifstat.md rename to Linux_man_cn/ifstat.md diff --git a/LinuxCommands/iftop.md b/Linux_man_cn/iftop.md similarity index 100% rename from LinuxCommands/iftop.md rename to Linux_man_cn/iftop.md diff --git a/LinuxCommands/ifup.md b/Linux_man_cn/ifup.md similarity index 100% rename from LinuxCommands/ifup.md rename to Linux_man_cn/ifup.md diff --git a/LinuxCommands/indent.md b/Linux_man_cn/indent.md similarity index 100% rename from LinuxCommands/indent.md rename to Linux_man_cn/indent.md diff --git a/LinuxCommands/info.md b/Linux_man_cn/info.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/info.md rename to Linux_man_cn/info.md index 21bd5d7..be85092 --- a/LinuxCommands/info.md +++ b/Linux_man_cn/info.md @@ -1,6 +1,6 @@ info === - + Linux下info格式的帮助指令 ## 补充说明 diff --git a/LinuxCommands/init.md b/Linux_man_cn/init.md similarity index 100% rename from LinuxCommands/init.md rename to Linux_man_cn/init.md diff --git a/LinuxCommands/inotifywait.md b/Linux_man_cn/inotifywait.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/inotifywait.md rename to Linux_man_cn/inotifywait.md index 8641fc0..12da42d --- a/LinuxCommands/inotifywait.md +++ b/Linux_man_cn/inotifywait.md @@ -1,6 +1,6 @@ inotifywait === - + 异步文件系统监控机制 ## 补充说明 diff --git a/LinuxCommands/insmod.md b/Linux_man_cn/insmod.md similarity index 100% rename from LinuxCommands/insmod.md rename to Linux_man_cn/insmod.md diff --git a/LinuxCommands/install.md b/Linux_man_cn/install.md similarity index 100% rename from LinuxCommands/install.md rename to Linux_man_cn/install.md diff --git a/LinuxCommands/iostat.md b/Linux_man_cn/iostat.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/iostat.md rename to Linux_man_cn/iostat.md index 7353242..ddd84f7 --- a/LinuxCommands/iostat.md +++ b/Linux_man_cn/iostat.md @@ -1,6 +1,6 @@ iostat === - + 监视系统输入输出设备和CPU的使用情况 ## 补充说明 diff --git a/LinuxCommands/iotop.md b/Linux_man_cn/iotop.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/iotop.md rename to Linux_man_cn/iotop.md index 0ad7de3..b1e3802 --- a/LinuxCommands/iotop.md +++ b/Linux_man_cn/iotop.md @@ -1,6 +1,6 @@ iotop === - + 用来监视磁盘I/O使用状况的工具 ## 补充说明 diff --git a/LinuxCommands/ip.md b/Linux_man_cn/ip.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/ip.md rename to Linux_man_cn/ip.md index 740a9a3..efc3ef5 --- a/LinuxCommands/ip.md +++ b/Linux_man_cn/ip.md @@ -1,106 +1,106 @@ -ip -=== - -网络配置工具 - -## 补充说明 - -**ip命令** 用来显示或操纵Linux主机的路由、网络设备、策略路由和隧道,是Linux下较新的功能强大的网络配置工具。 - -### 语法 - -``` -ip(选项)(参数) -``` - -### 选项 - -``` --V:显示指令版本信息; --s:输出更详细的信息; --f:强制使用指定的协议族; --4:指定使用的网络层协议是IPv4协议; --6:指定使用的网络层协议是IPv6协议; --0:输出信息每条记录输出一行,即使内容较多也不换行显示; --r:显示主机时,不使用IP地址,而使用主机的域名。 -``` - -### 参数 - -``` -网络对象:指定要管理的网络对象; -具体操作:对指定的网络对象完成具体操作; -help:显示网络对象支持的操作命令的帮助信息。 -``` - -### 实例 - -```bash -ip route show # 显示系统路由 -ip route add default via 192.168.1.254 # 设置系统默认路由 -ip route delete 192.168.1.0/24 dev eth0 # 删除路由 -``` - -**用ip命令显示网络设备的运行状态** - -``` -[root@localhost ~]# ip link list -1: lo: mtu 16436 qdisc noqueue - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 -2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 - link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff -3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000 - link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff -``` - -**显示更加详细的设备信息** - -``` -[root@localhost ~]# ip -s link list -1: lo: mtu 16436 qdisc noqueue - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 - RX: bytes packets errors dropped overrun mcast - 5082831 56145 0 0 0 0 - TX: bytes packets errors dropped carrier collsns - 5082831 56145 0 0 0 0 -2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 - link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff - RX: bytes packets errors dropped overrun mcast - 3641655380 62027099 0 0 0 0 - TX: bytes packets errors dropped carrier collsns - 6155236 89160 0 0 0 0 -3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000 - link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff - RX: bytes packets errors dropped overrun mcast - 2562136822 488237847 0 0 0 0 - TX: bytes packets errors dropped carrier collsns - 3486617396 9691081 0 0 0 0 -``` - -**显示核心路由表** - -``` -[root@localhost ~]# ip route list -112.124.12.0/22 dev eth1 proto kernel scope link src 112.124.15.130 -10.160.0.0/20 dev eth0 proto kernel scope link src 10.160.7.81 -192.168.0.0/16 via 10.160.15.247 dev eth0 -172.16.0.0/12 via 10.160.15.247 dev eth0 -10.0.0.0/8 via 10.160.15.247 dev eth0 -default via 112.124.15.247 dev eth1 -``` - -**显示邻居表** - -``` -[root@localhost ~]# ip neigh list -112.124.15.247 dev eth1 lladdr 00:00:0c:9f:f3:88 REACHABLE -10.160.15.247 dev eth0 lladdr 00:00:0c:9f:f2:c0 STALE -``` - -**获取主机所有网络接口** - -``` -ip link | grep ^[0-9] | awk -F: '{print $2}' -``` - - +ip +=== + +网络配置工具 + +## 补充说明 + +**ip命令** 用来显示或操纵Linux主机的路由、网络设备、策略路由和隧道,是Linux下较新的功能强大的网络配置工具。 + +### 语法 + +``` +ip(选项)(参数) +``` + +### 选项 + +``` +-V:显示指令版本信息; +-s:输出更详细的信息; +-f:强制使用指定的协议族; +-4:指定使用的网络层协议是IPv4协议; +-6:指定使用的网络层协议是IPv6协议; +-0:输出信息每条记录输出一行,即使内容较多也不换行显示; +-r:显示主机时,不使用IP地址,而使用主机的域名。 +``` + +### 参数 + +``` +网络对象:指定要管理的网络对象; +具体操作:对指定的网络对象完成具体操作; +help:显示网络对象支持的操作命令的帮助信息。 +``` + +### 实例 + +```bash +ip route show # 显示系统路由 +ip route add default via 192.168.1.254 # 设置系统默认路由 +ip route delete 192.168.1.0/24 dev eth0 # 删除路由 +``` + +**用ip命令显示网络设备的运行状态** + +``` +[root@localhost ~]# ip link list +1: lo: mtu 16436 qdisc noqueue + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 + link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff +3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000 + link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff +``` + +**显示更加详细的设备信息** + +``` +[root@localhost ~]# ip -s link list +1: lo: mtu 16436 qdisc noqueue + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + RX: bytes packets errors dropped overrun mcast + 5082831 56145 0 0 0 0 + TX: bytes packets errors dropped carrier collsns + 5082831 56145 0 0 0 0 +2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 + link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff + RX: bytes packets errors dropped overrun mcast + 3641655380 62027099 0 0 0 0 + TX: bytes packets errors dropped carrier collsns + 6155236 89160 0 0 0 0 +3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000 + link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff + RX: bytes packets errors dropped overrun mcast + 2562136822 488237847 0 0 0 0 + TX: bytes packets errors dropped carrier collsns + 3486617396 9691081 0 0 0 0 +``` + +**显示核心路由表** + +``` +[root@localhost ~]# ip route list +112.124.12.0/22 dev eth1 proto kernel scope link src 112.124.15.130 +10.160.0.0/20 dev eth0 proto kernel scope link src 10.160.7.81 +192.168.0.0/16 via 10.160.15.247 dev eth0 +172.16.0.0/12 via 10.160.15.247 dev eth0 +10.0.0.0/8 via 10.160.15.247 dev eth0 +default via 112.124.15.247 dev eth1 +``` + +**显示邻居表** + +``` +[root@localhost ~]# ip neigh list +112.124.15.247 dev eth1 lladdr 00:00:0c:9f:f3:88 REACHABLE +10.160.15.247 dev eth0 lladdr 00:00:0c:9f:f2:c0 STALE +``` + +**获取主机所有网络接口** + +``` +ip link | grep ^[0-9] | awk -F: '{print $2}' +``` + + diff --git a/LinuxCommands/ip6tables-restore.md b/Linux_man_cn/ip6tables-restore.md old mode 100755 new mode 100644 similarity index 95% rename from LinuxCommands/ip6tables-restore.md rename to Linux_man_cn/ip6tables-restore.md index 29cefd1..a6638ee --- a/LinuxCommands/ip6tables-restore.md +++ b/Linux_man_cn/ip6tables-restore.md @@ -1,6 +1,6 @@ ip6tables-restore === - + 还原ip6tables表 ## 补充说明 diff --git a/LinuxCommands/ip6tables-save.md b/Linux_man_cn/ip6tables-save.md old mode 100755 new mode 100644 similarity index 95% rename from LinuxCommands/ip6tables-save.md rename to Linux_man_cn/ip6tables-save.md index fdea83a..3513d74 --- a/LinuxCommands/ip6tables-save.md +++ b/Linux_man_cn/ip6tables-save.md @@ -1,6 +1,6 @@ ip6tables-save === - + 保存ip6tables表配置 ## 补充说明 diff --git a/LinuxCommands/ip6tables.md b/Linux_man_cn/ip6tables.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/ip6tables.md rename to Linux_man_cn/ip6tables.md index 9ae53d6..ce10378 --- a/LinuxCommands/ip6tables.md +++ b/Linux_man_cn/ip6tables.md @@ -1,6 +1,6 @@ ip6tables === - + linux中防火墙软件 ## 补充说明 diff --git a/LinuxCommands/ipcalc.md b/Linux_man_cn/ipcalc.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ipcalc.md rename to Linux_man_cn/ipcalc.md index 5f3517c..9f39096 --- a/LinuxCommands/ipcalc.md +++ b/Linux_man_cn/ipcalc.md @@ -1,6 +1,6 @@ ipcalc === - + 简单的IP地址计算器 ## 补充说明 diff --git a/LinuxCommands/ipcrm.md b/Linux_man_cn/ipcrm.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ipcrm.md rename to Linux_man_cn/ipcrm.md index 53b57cc..71cc26f --- a/LinuxCommands/ipcrm.md +++ b/Linux_man_cn/ipcrm.md @@ -1,6 +1,6 @@ ipcrm === - + 删除消息队列、信号集、或者共享内存标识 ## 补充说明 diff --git a/LinuxCommands/ipcs.md b/Linux_man_cn/ipcs.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ipcs.md rename to Linux_man_cn/ipcs.md index 011450b..b8aa300 --- a/LinuxCommands/ipcs.md +++ b/Linux_man_cn/ipcs.md @@ -1,6 +1,6 @@ ipcs === - + 分析消息队列共享内存和信号量 ## 补充说明 diff --git a/LinuxCommands/iperf.md b/Linux_man_cn/iperf.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/iperf.md rename to Linux_man_cn/iperf.md index daa5c2c..56c090c --- a/LinuxCommands/iperf.md +++ b/Linux_man_cn/iperf.md @@ -1,6 +1,6 @@ iperf === - + 网络性能测试工具 ## 补充说明 diff --git a/LinuxCommands/iptables-restore.md b/Linux_man_cn/iptables-restore.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/iptables-restore.md rename to Linux_man_cn/iptables-restore.md index 98caf12..50fe6bb --- a/LinuxCommands/iptables-restore.md +++ b/Linux_man_cn/iptables-restore.md @@ -1,6 +1,6 @@ iptables-restore === - + 还原iptables表的配置 ## 补充说明 diff --git a/LinuxCommands/iptables-save.md b/Linux_man_cn/iptables-save.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/iptables-save.md rename to Linux_man_cn/iptables-save.md index 6b68032..74742b7 --- a/LinuxCommands/iptables-save.md +++ b/Linux_man_cn/iptables-save.md @@ -1,6 +1,6 @@ iptables-save === - + 备份iptables的表配置 ## 补充说明 diff --git a/LinuxCommands/iptables.md b/Linux_man_cn/iptables.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/iptables.md rename to Linux_man_cn/iptables.md diff --git a/LinuxCommands/iptraf.md b/Linux_man_cn/iptraf.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/iptraf.md rename to Linux_man_cn/iptraf.md index 0200f4e..c345aa4 --- a/LinuxCommands/iptraf.md +++ b/Linux_man_cn/iptraf.md @@ -1,6 +1,6 @@ iptraf === - + 实时地监视网卡流量 ## 补充说明 diff --git a/LinuxCommands/iptstate.md b/Linux_man_cn/iptstate.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/iptstate.md rename to Linux_man_cn/iptstate.md index 598b2d5..f464b0c --- a/LinuxCommands/iptstate.md +++ b/Linux_man_cn/iptstate.md @@ -1,6 +1,6 @@ iptstate === - + 显示iptables的工作状态 ## 补充说明 diff --git a/LinuxCommands/ispell.md b/Linux_man_cn/ispell.md similarity index 100% rename from LinuxCommands/ispell.md rename to Linux_man_cn/ispell.md diff --git a/LinuxCommands/jed.md b/Linux_man_cn/jed.md similarity index 100% rename from LinuxCommands/jed.md rename to Linux_man_cn/jed.md diff --git a/LinuxCommands/jobs.md b/Linux_man_cn/jobs.md similarity index 100% rename from LinuxCommands/jobs.md rename to Linux_man_cn/jobs.md diff --git a/LinuxCommands/joe.md b/Linux_man_cn/joe.md similarity index 100% rename from LinuxCommands/joe.md rename to Linux_man_cn/joe.md diff --git a/LinuxCommands/join.md b/Linux_man_cn/join.md similarity index 100% rename from LinuxCommands/join.md rename to Linux_man_cn/join.md diff --git a/LinuxCommands/jwhois.md b/Linux_man_cn/jwhois.md similarity index 100% rename from LinuxCommands/jwhois.md rename to Linux_man_cn/jwhois.md diff --git a/LinuxCommands/kernelversion.md b/Linux_man_cn/kernelversion.md similarity index 100% rename from LinuxCommands/kernelversion.md rename to Linux_man_cn/kernelversion.md diff --git a/LinuxCommands/kexec.md b/Linux_man_cn/kexec.md similarity index 100% rename from LinuxCommands/kexec.md rename to Linux_man_cn/kexec.md diff --git a/LinuxCommands/kill.md b/Linux_man_cn/kill.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/kill.md rename to Linux_man_cn/kill.md diff --git a/LinuxCommands/killall.md b/Linux_man_cn/killall.md similarity index 100% rename from LinuxCommands/killall.md rename to Linux_man_cn/killall.md diff --git a/LinuxCommands/last.md b/Linux_man_cn/last.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/last.md rename to Linux_man_cn/last.md index 96e3a9e..4f07127 --- a/LinuxCommands/last.md +++ b/Linux_man_cn/last.md @@ -1,6 +1,6 @@ last === - + 列出目前与过去登入系统的用户相关信息 ## 补充说明 diff --git a/LinuxCommands/lastb.md b/Linux_man_cn/lastb.md similarity index 100% rename from LinuxCommands/lastb.md rename to Linux_man_cn/lastb.md diff --git a/LinuxCommands/lastlog.md b/Linux_man_cn/lastlog.md similarity index 100% rename from LinuxCommands/lastlog.md rename to Linux_man_cn/lastlog.md diff --git a/LinuxCommands/ld.md b/Linux_man_cn/ld.md similarity index 100% rename from LinuxCommands/ld.md rename to Linux_man_cn/ld.md diff --git a/LinuxCommands/ldconfig.md b/Linux_man_cn/ldconfig.md similarity index 100% rename from LinuxCommands/ldconfig.md rename to Linux_man_cn/ldconfig.md diff --git a/LinuxCommands/ldd.md b/Linux_man_cn/ldd.md similarity index 100% rename from LinuxCommands/ldd.md rename to Linux_man_cn/ldd.md diff --git a/LinuxCommands/less.md b/Linux_man_cn/less.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/less.md rename to Linux_man_cn/less.md index 36e5641..ff42694 --- a/LinuxCommands/less.md +++ b/Linux_man_cn/less.md @@ -1,6 +1,6 @@ less === - + 分屏上下翻页浏览文件内容 ## 补充说明 diff --git a/LinuxCommands/let.md b/Linux_man_cn/let.md similarity index 100% rename from LinuxCommands/let.md rename to Linux_man_cn/let.md diff --git a/LinuxCommands/lftp.md b/Linux_man_cn/lftp.md similarity index 100% rename from LinuxCommands/lftp.md rename to Linux_man_cn/lftp.md diff --git a/LinuxCommands/lftpget.md b/Linux_man_cn/lftpget.md similarity index 100% rename from LinuxCommands/lftpget.md rename to Linux_man_cn/lftpget.md diff --git a/LinuxCommands/lha.md b/Linux_man_cn/lha.md similarity index 100% rename from LinuxCommands/lha.md rename to Linux_man_cn/lha.md diff --git a/LinuxCommands/lilo.md b/Linux_man_cn/lilo.md similarity index 100% rename from LinuxCommands/lilo.md rename to Linux_man_cn/lilo.md diff --git a/LinuxCommands/ln.md b/Linux_man_cn/ln.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ln.md rename to Linux_man_cn/ln.md index 698c7f1..638a885 --- a/LinuxCommands/ln.md +++ b/Linux_man_cn/ln.md @@ -1,120 +1,120 @@ -ln -=== - -用来为文件创件连接 - -## 补充说明 - -**ln命令** 用来为文件创件连接,连接类型分为硬连接和符号连接两种,默认的连接类型是硬连接。如果要创建符号连接必须使用"-s"选项。 - -注意:符号链接文件不是一个独立的文件,它的许多属性依赖于源文件,所以给符号链接文件设置存取权限是没有意义的。 - -软连接特点: -1.软连接的权限都是rwxrwxrwx,文件类型是l,时间值和原文件的时间值不同; -2.类似于windows中的快捷方式操作; -3.源文件和链接文件同步更新; -4支持跨文件系统创建链接文件; - -### 语法 - -``` -ln [选项]... [-T] 目标 链接名 (第一种格式) - 或:ln [选项]... 目标 (第二种格式) - 或:ln [选项]... 目标... 目录 (第三种格式) - 或:ln [选项]... -t 目录 目标... (第四种格式) -``` - -### 选项 - -``` --b或--backup:删除,覆盖目标文件之前的备份; --d或-F或——directory:建立目录的硬连接; --f或——force:强行建立文件或目录的连接,不论文件或目录是否存在; --i或——interactive:覆盖既有文件之前先询问用户; --n或--no-dereference:把符号连接的目的目录视为一般文件; --s或——symbolic:对源文件建立符号连接,而非硬连接; --S<字尾备份字符串>或--suffix=<字尾备份字符串>:用"-b"参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,预设的备份字符串是符号“~”,用户可通过“-S”参数来改变它; --v或——verbose:显示指令执行过程; --V<备份方式>或--version-control=<备份方式>:用“-b”参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,这个字符串不仅可用“-S”参数变更,当使用“-V”参数<备份方式>指定不同备份方式时,也会产生不同字尾的备份字符串; ---help:在线帮助; ---version:显示版本信息。 -``` - -### 参数 - -* 源文件:指定连接的源文件。如果使用`-s`选项创建符号连接,则“源文件”可以是文件或者目录。创建硬连接时,则“源文件”参数只能是文件; -* 目标文件:指定源文件的目标连接文件。 - -### 实例 - -将目录`/usr/mengqc/mub1`下的文件m2.c链接到目录`/usr/liu`下的文件a2.c - -``` -cd /usr/mengqc -ln /mub1/m2.c /usr/liu/a2.c -``` - -在执行ln命令之前,目录`/usr/liu`中不存在a2.c文件。执行ln之后,在`/usr/liu`目录中才有a2.c这一项,表明m2.c和a2.c链接起来(注意,二者在物理上是同一文件),利用`ls -l`命令可以看到链接数的变化。 - -在目录`/usr/liu`下建立一个符号链接文件abc,使它指向目录`/usr/mengqc/mub1` - -``` -ln -s /usr/mengqc/mub1 /usr/liu/abc -``` - -执行该命令后,`/usr/mengqc/mub1`代表的路径将存放在名为`/usr/liu/abc`的文件中。 - -## 扩展知识 - -Linux具有为一个文件起多个名字的功能,称为链接。被链接的文件可以存放在相同的目录下,但是必须有不同的文件名,而不用在硬盘上为同样的数据重复备份。另外,被链接的文件也可以有相同的文件名,但是存放在不同的目录下,这样只要对一个目录下的该文件进行修改,就可以完成对所有目录下同名链接文件的修改。对于某个文件的各链接文件,我们可以给它们指定不同的存取权限,以控制对信息的共享和增强安全性。 - -文件链接有两种形式,即硬链接和符号链接。 - -### 硬链接 - -硬链接特点: -1.源文件和硬链接文件的属性完全相同; -2.类似于cp -p 复制文件指令,不同之处是时间值不同; -3.硬链接是同步更新的; -4.硬链接不能跨文件系统,类似于跨分区....(实质上文件系统就是一个初始化后的分区,属于独立存储空间,同时在文件的逻辑结构上是隶属于根目录) - -建立硬链接时,在另外的目录或本目录中增加目标文件的一个目录项,这样,一个文件就登记在多个目录中。如图所示的m2.c文件就在目录mub1和liu中都建立了目录项。 - -创建硬链接后,己经存在的文件的I节点号(Inode)会被多个目录文件项使用。一个文件的硬链接数可以在目录的长列表格式的第二列中看到,无额外链接的文件的链接数为l。 - -在默认情况下,ln命令创建硬链接。ln命令会增加链接数,rm命令会减少链接数。一个文件除非链接数为0,否则不会从文件系统中被物理地删除。 - -对硬链接有如下限制: - -* 不能对目录文件做硬链接。 -* 不能在不同的文件系统之间做硬链接。就是说,链接文件和被链接文件必须位于同一个文件系统中。 - -### 软,硬链接不同点: -1.如果源文件被删除的话,软连接文件只是一个符号链接,因此软连接文件不可访问。硬链接文件是可以访问的,相当于源文件的一个拷贝,大小内容是一样的,同步更新。 - -为了更好的理解两者的不同点,下面来分析一下软硬链接的原理: -在Linux系统中最核心的部分是内核,其功能是负责处理几乎所有的事情,但处理过程中不能识别字母,只能识别数字,因此在处理的过程中要有一个数字标识来标记,我们称之为i节点;(uid ,gid ,pid 等数字标识)每个文件都有一个i节点,如果没有的话就没有办法访问目标文件; - -硬链接和源文件有相同的i节点--inode映射到了两个文件,删除一个就减掉一个映射,还有另一条映射因此不影响对文件的访问。内核查看inode都是相同的数字,同步在两个文件中写入,而且并不知道那个是源文件那个是硬链接文件,这就是硬链接为什么会同步更新; - -切记:i节点是内核调用的数字标识; - -### 符号链接 - -符号链接也称为软链接,是将一个路径名链接到一个文件。这些文件是一种特别类型的文件。事实上,它只是一个文本文件(如图中的abc文件),其中包含它提供链接的另一个文件的路径名,如图中虚线箭头所示。另一个文件是实际包含所有数据的文件。所有读、写文件内容的命令被用于符号链接时,将沿着链接方向前进来访问实际的文件。 - -符号连接与硬链接不同的是,符号链接确实是一个新文件,当然它具有不同的I节点号;而硬链接并没有建立新文件。 - -符号链接没有硬链接的限制,可以对目录文件做符号链接,也可以在不同文件系统之间做符号链接。 - -用`ln -s`命令建立符号链接时,源文件最好用绝对路径名。这样可以在任何工作目录下进行符号链接。而当源文件用相对路径时,如果当前的工作路径与要创建的符号链接文件所在路径不同,就不能进行链接。 - -符号链接保持了链接与源文件或目录之间的区别: - -* 删除源文件或目录,只删除了数据,不会删除链接。一旦以同样文件名创建了源文件,链接将继续指向该文件的新数据。 -* 在目录长列表中,符号链接作为一种特殊的文件类型显示出来,其第一个字母是l。 -* 符号链接的大小是其链接文件的路径名中的字节数。 -* 当用`ln -s`命令列出文件时,可以看到符号链接名后有一个箭头指向源文件或目录,例如`lrwxrwxrwx … 14 jun 20 10:20 /etc/motd->/original_file`其中,表示“文件大小”的数字“14”恰好说明源文件名`original_file`由14个字符构成。 - - - +ln +=== + +用来为文件创件连接 + +## 补充说明 + +**ln命令** 用来为文件创件连接,连接类型分为硬连接和符号连接两种,默认的连接类型是硬连接。如果要创建符号连接必须使用"-s"选项。 + +注意:符号链接文件不是一个独立的文件,它的许多属性依赖于源文件,所以给符号链接文件设置存取权限是没有意义的。 + +软连接特点: +1.软连接的权限都是rwxrwxrwx,文件类型是l,时间值和原文件的时间值不同; +2.类似于windows中的快捷方式操作; +3.源文件和链接文件同步更新; +4支持跨文件系统创建链接文件; + +### 语法 + +``` +ln [选项]... [-T] 目标 链接名 (第一种格式) + 或:ln [选项]... 目标 (第二种格式) + 或:ln [选项]... 目标... 目录 (第三种格式) + 或:ln [选项]... -t 目录 目标... (第四种格式) +``` + +### 选项 + +``` +-b或--backup:删除,覆盖目标文件之前的备份; +-d或-F或——directory:建立目录的硬连接; +-f或——force:强行建立文件或目录的连接,不论文件或目录是否存在; +-i或——interactive:覆盖既有文件之前先询问用户; +-n或--no-dereference:把符号连接的目的目录视为一般文件; +-s或——symbolic:对源文件建立符号连接,而非硬连接; +-S<字尾备份字符串>或--suffix=<字尾备份字符串>:用"-b"参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,预设的备份字符串是符号“~”,用户可通过“-S”参数来改变它; +-v或——verbose:显示指令执行过程; +-V<备份方式>或--version-control=<备份方式>:用“-b”参数备份目标文件后,备份文件的字尾会被加上一个备份字符串,这个字符串不仅可用“-S”参数变更,当使用“-V”参数<备份方式>指定不同备份方式时,也会产生不同字尾的备份字符串; +--help:在线帮助; +--version:显示版本信息。 +``` + +### 参数 + +* 源文件:指定连接的源文件。如果使用`-s`选项创建符号连接,则“源文件”可以是文件或者目录。创建硬连接时,则“源文件”参数只能是文件; +* 目标文件:指定源文件的目标连接文件。 + +### 实例 + +将目录`/usr/mengqc/mub1`下的文件m2.c链接到目录`/usr/liu`下的文件a2.c + +``` +cd /usr/mengqc +ln /mub1/m2.c /usr/liu/a2.c +``` + +在执行ln命令之前,目录`/usr/liu`中不存在a2.c文件。执行ln之后,在`/usr/liu`目录中才有a2.c这一项,表明m2.c和a2.c链接起来(注意,二者在物理上是同一文件),利用`ls -l`命令可以看到链接数的变化。 + +在目录`/usr/liu`下建立一个符号链接文件abc,使它指向目录`/usr/mengqc/mub1` + +``` +ln -s /usr/mengqc/mub1 /usr/liu/abc +``` + +执行该命令后,`/usr/mengqc/mub1`代表的路径将存放在名为`/usr/liu/abc`的文件中。 + +## 扩展知识 + +Linux具有为一个文件起多个名字的功能,称为链接。被链接的文件可以存放在相同的目录下,但是必须有不同的文件名,而不用在硬盘上为同样的数据重复备份。另外,被链接的文件也可以有相同的文件名,但是存放在不同的目录下,这样只要对一个目录下的该文件进行修改,就可以完成对所有目录下同名链接文件的修改。对于某个文件的各链接文件,我们可以给它们指定不同的存取权限,以控制对信息的共享和增强安全性。 + +文件链接有两种形式,即硬链接和符号链接。 + +### 硬链接 + +硬链接特点: +1.源文件和硬链接文件的属性完全相同; +2.类似于cp -p 复制文件指令,不同之处是时间值不同; +3.硬链接是同步更新的; +4.硬链接不能跨文件系统,类似于跨分区....(实质上文件系统就是一个初始化后的分区,属于独立存储空间,同时在文件的逻辑结构上是隶属于根目录) + +建立硬链接时,在另外的目录或本目录中增加目标文件的一个目录项,这样,一个文件就登记在多个目录中。如图所示的m2.c文件就在目录mub1和liu中都建立了目录项。 + +创建硬链接后,己经存在的文件的I节点号(Inode)会被多个目录文件项使用。一个文件的硬链接数可以在目录的长列表格式的第二列中看到,无额外链接的文件的链接数为l。 + +在默认情况下,ln命令创建硬链接。ln命令会增加链接数,rm命令会减少链接数。一个文件除非链接数为0,否则不会从文件系统中被物理地删除。 + +对硬链接有如下限制: + +* 不能对目录文件做硬链接。 +* 不能在不同的文件系统之间做硬链接。就是说,链接文件和被链接文件必须位于同一个文件系统中。 + +### 软,硬链接不同点: +1.如果源文件被删除的话,软连接文件只是一个符号链接,因此软连接文件不可访问。硬链接文件是可以访问的,相当于源文件的一个拷贝,大小内容是一样的,同步更新。 + +为了更好的理解两者的不同点,下面来分析一下软硬链接的原理: +在Linux系统中最核心的部分是内核,其功能是负责处理几乎所有的事情,但处理过程中不能识别字母,只能识别数字,因此在处理的过程中要有一个数字标识来标记,我们称之为i节点;(uid ,gid ,pid 等数字标识)每个文件都有一个i节点,如果没有的话就没有办法访问目标文件; + +硬链接和源文件有相同的i节点--inode映射到了两个文件,删除一个就减掉一个映射,还有另一条映射因此不影响对文件的访问。内核查看inode都是相同的数字,同步在两个文件中写入,而且并不知道那个是源文件那个是硬链接文件,这就是硬链接为什么会同步更新; + +切记:i节点是内核调用的数字标识; + +### 符号链接 + +符号链接也称为软链接,是将一个路径名链接到一个文件。这些文件是一种特别类型的文件。事实上,它只是一个文本文件(如图中的abc文件),其中包含它提供链接的另一个文件的路径名,如图中虚线箭头所示。另一个文件是实际包含所有数据的文件。所有读、写文件内容的命令被用于符号链接时,将沿着链接方向前进来访问实际的文件。 + +符号连接与硬链接不同的是,符号链接确实是一个新文件,当然它具有不同的I节点号;而硬链接并没有建立新文件。 + +符号链接没有硬链接的限制,可以对目录文件做符号链接,也可以在不同文件系统之间做符号链接。 + +用`ln -s`命令建立符号链接时,源文件最好用绝对路径名。这样可以在任何工作目录下进行符号链接。而当源文件用相对路径时,如果当前的工作路径与要创建的符号链接文件所在路径不同,就不能进行链接。 + +符号链接保持了链接与源文件或目录之间的区别: + +* 删除源文件或目录,只删除了数据,不会删除链接。一旦以同样文件名创建了源文件,链接将继续指向该文件的新数据。 +* 在目录长列表中,符号链接作为一种特殊的文件类型显示出来,其第一个字母是l。 +* 符号链接的大小是其链接文件的路径名中的字节数。 +* 当用`ln -s`命令列出文件时,可以看到符号链接名后有一个箭头指向源文件或目录,例如`lrwxrwxrwx … 14 jun 20 10:20 /etc/motd->/original_file`其中,表示“文件大小”的数字“14”恰好说明源文件名`original_file`由14个字符构成。 + + + diff --git a/LinuxCommands/lnstat.md b/Linux_man_cn/lnstat.md similarity index 100% rename from LinuxCommands/lnstat.md rename to Linux_man_cn/lnstat.md diff --git a/LinuxCommands/locale.md b/Linux_man_cn/locale.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/locale.md rename to Linux_man_cn/locale.md index 0be2d74..c054b1c --- a/LinuxCommands/locale.md +++ b/Linux_man_cn/locale.md @@ -1,26 +1,26 @@ -locale -=== - -```sh -locate [选择参数] [样式] -``` - -选项 - -```sh --e 将排除在寻找的范围之外。 --1 如果 是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到 的档案。这会始速度减慢,因为 locate 必须至实际的档案系统中取得档案的 权限资料。 --f 将特定的档案系统排除在外,例如我们没有到理要把 proc 档案系统中的档案 放在资料库中。 --q 安静模式,不会显示任何错误讯息。 --n 至多显示 n个输出。 --r 使用正规运算式 做寻找的条件。 --o 指定资料库存的名称。 --d 指定资料库的路径 --h 显示辅助讯息 --V 显示程式的版本讯息 -``` - -实例 - -显示所支持语系:locale - +locale +=== + +```sh +locate [选择参数] [样式] +``` + +选项 + +```sh +-e 将排除在寻找的范围之外。 +-1 如果 是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到 的档案。这会始速度减慢,因为 locate 必须至实际的档案系统中取得档案的 权限资料。 +-f 将特定的档案系统排除在外,例如我们没有到理要把 proc 档案系统中的档案 放在资料库中。 +-q 安静模式,不会显示任何错误讯息。 +-n 至多显示 n个输出。 +-r 使用正规运算式 做寻找的条件。 +-o 指定资料库存的名称。 +-d 指定资料库的路径 +-h 显示辅助讯息 +-V 显示程式的版本讯息 +``` + +实例 + +显示所支持语系:locale + diff --git a/LinuxCommands/locate.md b/Linux_man_cn/locate.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/locate.md rename to Linux_man_cn/locate.md diff --git a/LinuxCommands/logger.md b/Linux_man_cn/logger.md similarity index 100% rename from LinuxCommands/logger.md rename to Linux_man_cn/logger.md diff --git a/LinuxCommands/login.md b/Linux_man_cn/login.md similarity index 100% rename from LinuxCommands/login.md rename to Linux_man_cn/login.md diff --git a/LinuxCommands/logname.md b/Linux_man_cn/logname.md similarity index 100% rename from LinuxCommands/logname.md rename to Linux_man_cn/logname.md diff --git a/LinuxCommands/logout.md b/Linux_man_cn/logout.md similarity index 100% rename from LinuxCommands/logout.md rename to Linux_man_cn/logout.md diff --git a/LinuxCommands/logrotate.md b/Linux_man_cn/logrotate.md similarity index 100% rename from LinuxCommands/logrotate.md rename to Linux_man_cn/logrotate.md diff --git a/LinuxCommands/logsave.md b/Linux_man_cn/logsave.md similarity index 100% rename from LinuxCommands/logsave.md rename to Linux_man_cn/logsave.md diff --git a/LinuxCommands/logwatch.md b/Linux_man_cn/logwatch.md similarity index 100% rename from LinuxCommands/logwatch.md rename to Linux_man_cn/logwatch.md diff --git a/LinuxCommands/look.md b/Linux_man_cn/look.md similarity index 100% rename from LinuxCommands/look.md rename to Linux_man_cn/look.md diff --git a/LinuxCommands/losetup.md b/Linux_man_cn/losetup.md similarity index 100% rename from LinuxCommands/losetup.md rename to Linux_man_cn/losetup.md diff --git a/LinuxCommands/lp.md b/Linux_man_cn/lp.md similarity index 100% rename from LinuxCommands/lp.md rename to Linux_man_cn/lp.md diff --git a/LinuxCommands/lpadmin.md b/Linux_man_cn/lpadmin.md similarity index 100% rename from LinuxCommands/lpadmin.md rename to Linux_man_cn/lpadmin.md diff --git a/LinuxCommands/lpc.md b/Linux_man_cn/lpc.md similarity index 100% rename from LinuxCommands/lpc.md rename to Linux_man_cn/lpc.md diff --git a/LinuxCommands/lpq.md b/Linux_man_cn/lpq.md similarity index 100% rename from LinuxCommands/lpq.md rename to Linux_man_cn/lpq.md diff --git a/LinuxCommands/lpr.md b/Linux_man_cn/lpr.md similarity index 100% rename from LinuxCommands/lpr.md rename to Linux_man_cn/lpr.md diff --git a/LinuxCommands/lprm.md b/Linux_man_cn/lprm.md similarity index 100% rename from LinuxCommands/lprm.md rename to Linux_man_cn/lprm.md diff --git a/LinuxCommands/lpstat.md b/Linux_man_cn/lpstat.md similarity index 100% rename from LinuxCommands/lpstat.md rename to Linux_man_cn/lpstat.md diff --git a/LinuxCommands/ls.md b/Linux_man_cn/ls.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/ls.md rename to Linux_man_cn/ls.md diff --git a/LinuxCommands/lsattr.md b/Linux_man_cn/lsattr.md similarity index 100% rename from LinuxCommands/lsattr.md rename to Linux_man_cn/lsattr.md diff --git a/LinuxCommands/lsb_release.md b/Linux_man_cn/lsb_release.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/lsb_release.md rename to Linux_man_cn/lsb_release.md diff --git a/LinuxCommands/lsblk.md b/Linux_man_cn/lsblk.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/lsblk.md rename to Linux_man_cn/lsblk.md index 49c6cd3..5be088d --- a/LinuxCommands/lsblk.md +++ b/Linux_man_cn/lsblk.md @@ -1,6 +1,6 @@ lsblk === - + 列出块设备信息 ## 补充说明 diff --git a/LinuxCommands/lscpu.md b/Linux_man_cn/lscpu.md similarity index 100% rename from LinuxCommands/lscpu.md rename to Linux_man_cn/lscpu.md diff --git a/LinuxCommands/lsmod.md b/Linux_man_cn/lsmod.md similarity index 100% rename from LinuxCommands/lsmod.md rename to Linux_man_cn/lsmod.md diff --git a/LinuxCommands/lsof.md b/Linux_man_cn/lsof.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/lsof.md rename to Linux_man_cn/lsof.md index 7d4a0cf..23216ff --- a/LinuxCommands/lsof.md +++ b/Linux_man_cn/lsof.md @@ -1,6 +1,6 @@ lsof === - + 显示Linux系统当前已打开的所有文件列表 ## 补充说明 diff --git a/LinuxCommands/lspci.md b/Linux_man_cn/lspci.md similarity index 100% rename from LinuxCommands/lspci.md rename to Linux_man_cn/lspci.md diff --git a/LinuxCommands/lsusb.md b/Linux_man_cn/lsusb.md similarity index 100% rename from LinuxCommands/lsusb.md rename to Linux_man_cn/lsusb.md diff --git a/LinuxCommands/ltrace.md b/Linux_man_cn/ltrace.md similarity index 100% rename from LinuxCommands/ltrace.md rename to Linux_man_cn/ltrace.md diff --git a/LinuxCommands/lvcreate.md b/Linux_man_cn/lvcreate.md similarity index 100% rename from LinuxCommands/lvcreate.md rename to Linux_man_cn/lvcreate.md diff --git a/LinuxCommands/lvdisplay.md b/Linux_man_cn/lvdisplay.md similarity index 100% rename from LinuxCommands/lvdisplay.md rename to Linux_man_cn/lvdisplay.md diff --git a/LinuxCommands/lvextend.md b/Linux_man_cn/lvextend.md similarity index 100% rename from LinuxCommands/lvextend.md rename to Linux_man_cn/lvextend.md diff --git a/LinuxCommands/lvreduce.md b/Linux_man_cn/lvreduce.md similarity index 100% rename from LinuxCommands/lvreduce.md rename to Linux_man_cn/lvreduce.md diff --git a/LinuxCommands/lvremove.md b/Linux_man_cn/lvremove.md similarity index 100% rename from LinuxCommands/lvremove.md rename to Linux_man_cn/lvremove.md diff --git a/LinuxCommands/lvresize.md b/Linux_man_cn/lvresize.md similarity index 100% rename from LinuxCommands/lvresize.md rename to Linux_man_cn/lvresize.md diff --git a/LinuxCommands/lvscan.md b/Linux_man_cn/lvscan.md similarity index 100% rename from LinuxCommands/lvscan.md rename to Linux_man_cn/lvscan.md diff --git a/LinuxCommands/lynx.md b/Linux_man_cn/lynx.md similarity index 100% rename from LinuxCommands/lynx.md rename to Linux_man_cn/lynx.md diff --git a/LinuxCommands/mail.md b/Linux_man_cn/mail.md similarity index 100% rename from LinuxCommands/mail.md rename to Linux_man_cn/mail.md diff --git a/LinuxCommands/mailq.md b/Linux_man_cn/mailq.md similarity index 100% rename from LinuxCommands/mailq.md rename to Linux_man_cn/mailq.md diff --git a/LinuxCommands/mailstat.md b/Linux_man_cn/mailstat.md similarity index 100% rename from LinuxCommands/mailstat.md rename to Linux_man_cn/mailstat.md diff --git a/LinuxCommands/make.md b/Linux_man_cn/make.md similarity index 100% rename from LinuxCommands/make.md rename to Linux_man_cn/make.md diff --git a/LinuxCommands/man.md b/Linux_man_cn/man.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/man.md rename to Linux_man_cn/man.md index f18ff66..4ee6af7 --- a/LinuxCommands/man.md +++ b/Linux_man_cn/man.md @@ -1,140 +1,140 @@ -man -=== - -查看Linux中的指令帮助 - -## 补充说明 - -**man命令** 是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助、配置文件帮助和编程帮助等信息。 - -### 语法 - -``` - - man [OPTION...] [章节] 手册页... - - -C, --config-file=文件 使用该用户设置文件 - -d, --debug 输出调试信息 - -D, --default 将所有选项都重置为默认值 - --warnings[=警告] 开启 groff 的警告 - - 主要运行模式: - -f, --whatis 等同于 whatis - -k, --apropos 等同于 apropos - -K, --global-apropos search for text in all pages - -l, --local-file - 把“手册页”参数当成本地文件名来解读 - -w, --where, --path, --location - 输出手册页的物理位置 - -W, --where-cat, --location-cat - 输出 cat 文件的物理位置 - - -c, --catman 由 catman 使用,用来对过时的 cat - 页重新排版 - -R, --recode=编码 output source page encoded in ENCODING - - 寻找手册页: - -L, --locale=区域 - 定义本次手册页搜索所采用的区域设置 - -m, --systems=系统 use manual pages from other systems - -M, --manpath=路径 设置搜索手册页的路径为“路径” - - -S, -s, --sections=列表 使用以半角冒号分隔的章节列表 - - -e, --extension=扩展 - 将搜索限制在扩展类型为“扩展”的手册页之内 - - -i, --ignore-case 查找手册页时不区分大小写字母 - (默认) - -I, --match-case 查找手册页时区分大小写字母。 - - --regex show all pages matching regex - --wildcard show all pages matching wildcard - - --names-only make --regex and --wildcard match page names only, - not descriptions - - -a, --all 寻找所有匹配的手册页 - -u, --update 强制进行缓存一致性的检查 - - --no-subpages don't try subpages, e.g. 'man foo bar' => 'man - foo-bar' - - 控制格式化的输出: - -P, --pager=PAGER 使用 PAGER 程序显示输出文本 - -r, --prompt=字符串 给 less pager 提供一个提示行 - - -7, --ascii 显示某些 latin1 字符的 ASCII 翻译形式 - -E, --encoding=编码 use selected output encoding - --no-hyphenation, --nh turn off hyphenation - --no-justification, --nj turn off justification - -p, --preprocessor=字符串 字符串表示要运行哪些预处理器: - e - [n]eqn, p - pic, t - tbl, -g - grap, r - refer, v - vgrind - - -t, --troff 使用 groff 对手册页排版 - -T, --troff-device[=设备] 使用 groff 的指定设备 - - -H, --html[=浏览器] 使用 elinks 或指定浏览器显示 HTML - 输出 - -X, --gxditview[=分辨率] 使用 groff 并通过 gxditview (X11) - 来显示: - -X = -TX75, -X100 = -TX100, -X100-12 = -TX100-12 - -Z, --ditroff 使用 groff 并强制它生成 ditroff - - -?, --help give this help list - --usage give a short usage message - -V, --version print program version - -Mandatory or optional arguments to long options are also mandatory or optional -for any corresponding short options. -``` - -### 选项 - -``` --a:在所有的man帮助手册中搜索; --f:等价于whatis指令,显示给定关键字的简短描述信息; --P:指定内容时使用分页程序; --M:指定man手册搜索的路径。 -``` - -### 参数 - -* 数字:指定从哪本man手册中搜索帮助; -* 关键字:指定要搜索帮助的关键字。 - -### 数字代表内容 - -``` -1:用户在shell环境可操作的命令或执行文件; -2:系统内核可调用的函数与工具等 -3:一些常用的函数(function)与函数库(library),大部分为C的函数库(libc) -4:设备文件说明,通常在/dev下的文件 -5:配置文件或某些文件格式 -6:游戏(games) -7:惯例与协议等,如Linux文件系统,网络协议,ASCII code等说明 -8:系统管理员可用的管理命令 -9:跟kernel有关的文件 -``` - -### 实例 - -我们输入`man ls`,它会在最左上角显示“LS(1)”,在这里,“LS”表示手册名称,而“(1)”表示该手册位于第一节章,同样,我们输`man ifconfig`它会在最左上角显示“IFCONFIG(8)”。也可以这样输入命令:“man [章节号] 手册名称”。 - -man是按照手册的章节号的顺序进行搜索的,比如: - -``` -man sleep -``` - -只会显示sleep命令的手册,如果想查看库函数sleep,就要输入: - -``` -man 3 sleep -``` - - - - - +man +=== + +查看Linux中的指令帮助 + +## 补充说明 + +**man命令** 是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助、配置文件帮助和编程帮助等信息。 + +### 语法 + +``` + + man [OPTION...] [章节] 手册页... + + -C, --config-file=文件 使用该用户设置文件 + -d, --debug 输出调试信息 + -D, --default 将所有选项都重置为默认值 + --warnings[=警告] 开启 groff 的警告 + + 主要运行模式: + -f, --whatis 等同于 whatis + -k, --apropos 等同于 apropos + -K, --global-apropos search for text in all pages + -l, --local-file + 把“手册页”参数当成本地文件名来解读 + -w, --where, --path, --location + 输出手册页的物理位置 + -W, --where-cat, --location-cat + 输出 cat 文件的物理位置 + + -c, --catman 由 catman 使用,用来对过时的 cat + 页重新排版 + -R, --recode=编码 output source page encoded in ENCODING + + 寻找手册页: + -L, --locale=区域 + 定义本次手册页搜索所采用的区域设置 + -m, --systems=系统 use manual pages from other systems + -M, --manpath=路径 设置搜索手册页的路径为“路径” + + -S, -s, --sections=列表 使用以半角冒号分隔的章节列表 + + -e, --extension=扩展 + 将搜索限制在扩展类型为“扩展”的手册页之内 + + -i, --ignore-case 查找手册页时不区分大小写字母 + (默认) + -I, --match-case 查找手册页时区分大小写字母。 + + --regex show all pages matching regex + --wildcard show all pages matching wildcard + + --names-only make --regex and --wildcard match page names only, + not descriptions + + -a, --all 寻找所有匹配的手册页 + -u, --update 强制进行缓存一致性的检查 + + --no-subpages don't try subpages, e.g. 'man foo bar' => 'man + foo-bar' + + 控制格式化的输出: + -P, --pager=PAGER 使用 PAGER 程序显示输出文本 + -r, --prompt=字符串 给 less pager 提供一个提示行 + + -7, --ascii 显示某些 latin1 字符的 ASCII 翻译形式 + -E, --encoding=编码 use selected output encoding + --no-hyphenation, --nh turn off hyphenation + --no-justification, --nj turn off justification + -p, --preprocessor=字符串 字符串表示要运行哪些预处理器: + e - [n]eqn, p - pic, t - tbl, +g - grap, r - refer, v - vgrind + + -t, --troff 使用 groff 对手册页排版 + -T, --troff-device[=设备] 使用 groff 的指定设备 + + -H, --html[=浏览器] 使用 elinks 或指定浏览器显示 HTML + 输出 + -X, --gxditview[=分辨率] 使用 groff 并通过 gxditview (X11) + 来显示: + -X = -TX75, -X100 = -TX100, -X100-12 = -TX100-12 + -Z, --ditroff 使用 groff 并强制它生成 ditroff + + -?, --help give this help list + --usage give a short usage message + -V, --version print program version + +Mandatory or optional arguments to long options are also mandatory or optional +for any corresponding short options. +``` + +### 选项 + +``` +-a:在所有的man帮助手册中搜索; +-f:等价于whatis指令,显示给定关键字的简短描述信息; +-P:指定内容时使用分页程序; +-M:指定man手册搜索的路径。 +``` + +### 参数 + +* 数字:指定从哪本man手册中搜索帮助; +* 关键字:指定要搜索帮助的关键字。 + +### 数字代表内容 + +``` +1:用户在shell环境可操作的命令或执行文件; +2:系统内核可调用的函数与工具等 +3:一些常用的函数(function)与函数库(library),大部分为C的函数库(libc) +4:设备文件说明,通常在/dev下的文件 +5:配置文件或某些文件格式 +6:游戏(games) +7:惯例与协议等,如Linux文件系统,网络协议,ASCII code等说明 +8:系统管理员可用的管理命令 +9:跟kernel有关的文件 +``` + +### 实例 + +我们输入`man ls`,它会在最左上角显示“LS(1)”,在这里,“LS”表示手册名称,而“(1)”表示该手册位于第一节章,同样,我们输`man ifconfig`它会在最左上角显示“IFCONFIG(8)”。也可以这样输入命令:“man [章节号] 手册名称”。 + +man是按照手册的章节号的顺序进行搜索的,比如: + +``` +man sleep +``` + +只会显示sleep命令的手册,如果想查看库函数sleep,就要输入: + +``` +man 3 sleep +``` + + + + + diff --git a/LinuxCommands/md5sum.md b/Linux_man_cn/md5sum.md similarity index 100% rename from LinuxCommands/md5sum.md rename to Linux_man_cn/md5sum.md diff --git a/LinuxCommands/mesg.md b/Linux_man_cn/mesg.md similarity index 100% rename from LinuxCommands/mesg.md rename to Linux_man_cn/mesg.md diff --git a/LinuxCommands/mii-tool.md b/Linux_man_cn/mii-tool.md similarity index 100% rename from LinuxCommands/mii-tool.md rename to Linux_man_cn/mii-tool.md diff --git a/LinuxCommands/mkbootdisk.md b/Linux_man_cn/mkbootdisk.md similarity index 100% rename from LinuxCommands/mkbootdisk.md rename to Linux_man_cn/mkbootdisk.md diff --git a/LinuxCommands/mkdir.md b/Linux_man_cn/mkdir.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/mkdir.md rename to Linux_man_cn/mkdir.md index 86f943d..00e62a1 --- a/LinuxCommands/mkdir.md +++ b/Linux_man_cn/mkdir.md @@ -1,6 +1,6 @@ mkdir === - + 用来创建目录 ## 补充说明 diff --git a/LinuxCommands/mke2fs.md b/Linux_man_cn/mke2fs.md similarity index 100% rename from LinuxCommands/mke2fs.md rename to Linux_man_cn/mke2fs.md diff --git a/LinuxCommands/mkfs.md b/Linux_man_cn/mkfs.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/mkfs.md rename to Linux_man_cn/mkfs.md index baf6878..9927b45 --- a/LinuxCommands/mkfs.md +++ b/Linux_man_cn/mkfs.md @@ -1,6 +1,6 @@ mkfs === - + 用于在设备上创建Linux文件系统 ## 补充说明 diff --git a/LinuxCommands/mkfs.xfs.md b/Linux_man_cn/mkfs.xfs.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/mkfs.xfs.md rename to Linux_man_cn/mkfs.xfs.md diff --git a/LinuxCommands/mkinitrd.md b/Linux_man_cn/mkinitrd.md similarity index 100% rename from LinuxCommands/mkinitrd.md rename to Linux_man_cn/mkinitrd.md diff --git a/LinuxCommands/mkisofs.md b/Linux_man_cn/mkisofs.md similarity index 100% rename from LinuxCommands/mkisofs.md rename to Linux_man_cn/mkisofs.md diff --git a/LinuxCommands/mknod.md b/Linux_man_cn/mknod.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/mknod.md rename to Linux_man_cn/mknod.md index b68d4a8..6c8cc4b --- a/LinuxCommands/mknod.md +++ b/Linux_man_cn/mknod.md @@ -1,6 +1,6 @@ mknod === - + 创建字符设备文件和块设备文件 ## 补充说明 diff --git a/LinuxCommands/mkswap.md b/Linux_man_cn/mkswap.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/mkswap.md rename to Linux_man_cn/mkswap.md index ef3526a..87cc10d --- a/LinuxCommands/mkswap.md +++ b/Linux_man_cn/mkswap.md @@ -1,6 +1,6 @@ mkswap === - + 建立和设置SWAP交换分区 ## 补充说明 diff --git a/LinuxCommands/mktemp.md b/Linux_man_cn/mktemp.md similarity index 100% rename from LinuxCommands/mktemp.md rename to Linux_man_cn/mktemp.md diff --git a/LinuxCommands/modprobe.md b/Linux_man_cn/modprobe.md similarity index 100% rename from LinuxCommands/modprobe.md rename to Linux_man_cn/modprobe.md diff --git a/LinuxCommands/more.md b/Linux_man_cn/more.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/more.md rename to Linux_man_cn/more.md index 85c1fcd..bf6547d --- a/LinuxCommands/more.md +++ b/Linux_man_cn/more.md @@ -1,6 +1,6 @@ more === - + 显示文件内容,每次显示一屏 ## 补充说明 diff --git a/LinuxCommands/mount.md b/Linux_man_cn/mount.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/mount.md rename to Linux_man_cn/mount.md diff --git a/LinuxCommands/mpstat.md b/Linux_man_cn/mpstat.md similarity index 100% rename from LinuxCommands/mpstat.md rename to Linux_man_cn/mpstat.md diff --git a/LinuxCommands/mtools.md b/Linux_man_cn/mtools.md similarity index 100% rename from LinuxCommands/mtools.md rename to Linux_man_cn/mtools.md diff --git a/LinuxCommands/mv.md b/Linux_man_cn/mv.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/mv.md rename to Linux_man_cn/mv.md index ed7836f..b217fb7 --- a/LinuxCommands/mv.md +++ b/Linux_man_cn/mv.md @@ -1,6 +1,6 @@ mv === - + 用来对文件或目录重新命名 ## 补充说明 diff --git a/LinuxCommands/mysql.md b/Linux_man_cn/mysql.md similarity index 100% rename from LinuxCommands/mysql.md rename to Linux_man_cn/mysql.md diff --git a/LinuxCommands/mysqladmin.md b/Linux_man_cn/mysqladmin.md similarity index 100% rename from LinuxCommands/mysqladmin.md rename to Linux_man_cn/mysqladmin.md diff --git a/LinuxCommands/mysqldump.md b/Linux_man_cn/mysqldump.md similarity index 100% rename from LinuxCommands/mysqldump.md rename to Linux_man_cn/mysqldump.md diff --git a/LinuxCommands/mysqlimport.md b/Linux_man_cn/mysqlimport.md similarity index 100% rename from LinuxCommands/mysqlimport.md rename to Linux_man_cn/mysqlimport.md diff --git a/LinuxCommands/mysqlshow.md b/Linux_man_cn/mysqlshow.md similarity index 100% rename from LinuxCommands/mysqlshow.md rename to Linux_man_cn/mysqlshow.md diff --git a/LinuxCommands/named-checkzone.md b/Linux_man_cn/named-checkzone.md similarity index 100% rename from LinuxCommands/named-checkzone.md rename to Linux_man_cn/named-checkzone.md diff --git a/LinuxCommands/nano.md b/Linux_man_cn/nano.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/nano.md rename to Linux_man_cn/nano.md index b0237ff..cbe58bb --- a/LinuxCommands/nano.md +++ b/Linux_man_cn/nano.md @@ -1,6 +1,6 @@ nano === - + 字符终端文本编辑器 ## 补充说明 diff --git a/LinuxCommands/nc.md b/Linux_man_cn/nc.md similarity index 100% rename from LinuxCommands/nc.md rename to Linux_man_cn/nc.md diff --git a/LinuxCommands/ncftp.md b/Linux_man_cn/ncftp.md similarity index 100% rename from LinuxCommands/ncftp.md rename to Linux_man_cn/ncftp.md diff --git a/LinuxCommands/nethogs.md b/Linux_man_cn/nethogs.md similarity index 100% rename from LinuxCommands/nethogs.md rename to Linux_man_cn/nethogs.md diff --git a/LinuxCommands/netstat.md b/Linux_man_cn/netstat.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/netstat.md rename to Linux_man_cn/netstat.md diff --git a/LinuxCommands/newusers.md b/Linux_man_cn/newusers.md similarity index 100% rename from LinuxCommands/newusers.md rename to Linux_man_cn/newusers.md diff --git a/LinuxCommands/nfsstat.md b/Linux_man_cn/nfsstat.md similarity index 100% rename from LinuxCommands/nfsstat.md rename to Linux_man_cn/nfsstat.md diff --git a/LinuxCommands/ngrep.md b/Linux_man_cn/ngrep.md similarity index 100% rename from LinuxCommands/ngrep.md rename to Linux_man_cn/ngrep.md diff --git a/LinuxCommands/nice.md b/Linux_man_cn/nice.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/nice.md rename to Linux_man_cn/nice.md diff --git a/LinuxCommands/nisdomainname.md b/Linux_man_cn/nisdomainname.md similarity index 100% rename from LinuxCommands/nisdomainname.md rename to Linux_man_cn/nisdomainname.md diff --git a/LinuxCommands/nl.md b/Linux_man_cn/nl.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/nl.md rename to Linux_man_cn/nl.md index 4f7d827..bc91a50 --- a/LinuxCommands/nl.md +++ b/Linux_man_cn/nl.md @@ -1,6 +1,6 @@ nl === - + 在Linux系统中计算文件内容行号 ## 补充说明 diff --git a/LinuxCommands/nm.md b/Linux_man_cn/nm.md similarity index 100% rename from LinuxCommands/nm.md rename to Linux_man_cn/nm.md diff --git a/LinuxCommands/nmap.md b/Linux_man_cn/nmap.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/nmap.md rename to Linux_man_cn/nmap.md index bb558a6..36dd811 --- a/LinuxCommands/nmap.md +++ b/Linux_man_cn/nmap.md @@ -1,6 +1,6 @@ nmap === - + 网络探测和安全审核 ## 补充说明 diff --git a/LinuxCommands/nmcli.md b/Linux_man_cn/nmcli.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/nmcli.md rename to Linux_man_cn/nmcli.md diff --git a/LinuxCommands/nohup.md b/Linux_man_cn/nohup.md similarity index 100% rename from LinuxCommands/nohup.md rename to Linux_man_cn/nohup.md diff --git a/LinuxCommands/nologin.md b/Linux_man_cn/nologin.md similarity index 100% rename from LinuxCommands/nologin.md rename to Linux_man_cn/nologin.md diff --git a/LinuxCommands/nslookup.md b/Linux_man_cn/nslookup.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/nslookup.md rename to Linux_man_cn/nslookup.md index 7e5e911..212185a --- a/LinuxCommands/nslookup.md +++ b/Linux_man_cn/nslookup.md @@ -1,6 +1,6 @@ nslookup === - + 查询域名DNS信息的工具 ## 补充说明 diff --git a/LinuxCommands/ntpdate.md b/Linux_man_cn/ntpdate.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/ntpdate.md rename to Linux_man_cn/ntpdate.md index aeffc69..f8f9fe4 --- a/LinuxCommands/ntpdate.md +++ b/Linux_man_cn/ntpdate.md @@ -1,6 +1,6 @@ ntpdate === - + 使用网络计时协议(NTP)设置日期和时间 ## 补充说明 diff --git a/LinuxCommands/ntsysv.md b/Linux_man_cn/ntsysv.md similarity index 100% rename from LinuxCommands/ntsysv.md rename to Linux_man_cn/ntsysv.md diff --git a/LinuxCommands/objdump.md b/Linux_man_cn/objdump.md similarity index 100% rename from LinuxCommands/objdump.md rename to Linux_man_cn/objdump.md diff --git a/LinuxCommands/od.md b/Linux_man_cn/od.md similarity index 100% rename from LinuxCommands/od.md rename to Linux_man_cn/od.md diff --git a/LinuxCommands/openssl.md b/Linux_man_cn/openssl.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/openssl.md rename to Linux_man_cn/openssl.md index 4ca916f..36f4cba --- a/LinuxCommands/openssl.md +++ b/Linux_man_cn/openssl.md @@ -1,6 +1,6 @@ openssl === - + 强大的安全套接字层密码库 ## 补充说明 diff --git a/LinuxCommands/parted.md b/Linux_man_cn/parted.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/parted.md rename to Linux_man_cn/parted.md index 5bab7e8..fad6efe --- a/LinuxCommands/parted.md +++ b/Linux_man_cn/parted.md @@ -1,6 +1,6 @@ parted === - + 磁盘分区和分区大小调整工具 ## 补充说明 diff --git a/LinuxCommands/partprobe.md b/Linux_man_cn/partprobe.md similarity index 100% rename from LinuxCommands/partprobe.md rename to Linux_man_cn/partprobe.md diff --git a/LinuxCommands/passwd.md b/Linux_man_cn/passwd.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/passwd.md rename to Linux_man_cn/passwd.md index a51262d..b752629 --- a/LinuxCommands/passwd.md +++ b/Linux_man_cn/passwd.md @@ -1,6 +1,6 @@ passwd === - + 用于让用户可以更改自己的密码 ## 补充说明 diff --git a/LinuxCommands/paste.md b/Linux_man_cn/paste.md similarity index 100% rename from LinuxCommands/paste.md rename to Linux_man_cn/paste.md diff --git a/LinuxCommands/patch.md b/Linux_man_cn/patch.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/patch.md rename to Linux_man_cn/patch.md index 2692a2a..a1d71ec --- a/LinuxCommands/patch.md +++ b/Linux_man_cn/patch.md @@ -1,6 +1,6 @@ patch === - + 为开放源代码软件安装补丁程序 ## 补充说明 diff --git a/LinuxCommands/pathchk.md b/Linux_man_cn/pathchk.md similarity index 100% rename from LinuxCommands/pathchk.md rename to Linux_man_cn/pathchk.md diff --git a/LinuxCommands/perl.md b/Linux_man_cn/perl.md similarity index 100% rename from LinuxCommands/perl.md rename to Linux_man_cn/perl.md diff --git a/LinuxCommands/pfctl.md b/Linux_man_cn/pfctl.md similarity index 100% rename from LinuxCommands/pfctl.md rename to Linux_man_cn/pfctl.md diff --git a/LinuxCommands/pgrep.md b/Linux_man_cn/pgrep.md similarity index 100% rename from LinuxCommands/pgrep.md rename to Linux_man_cn/pgrep.md diff --git a/LinuxCommands/php.md b/Linux_man_cn/php.md similarity index 100% rename from LinuxCommands/php.md rename to Linux_man_cn/php.md diff --git a/LinuxCommands/pico.md b/Linux_man_cn/pico.md similarity index 100% rename from LinuxCommands/pico.md rename to Linux_man_cn/pico.md diff --git a/LinuxCommands/pidof.md b/Linux_man_cn/pidof.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/pidof.md rename to Linux_man_cn/pidof.md diff --git a/LinuxCommands/ping.md b/Linux_man_cn/ping.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/ping.md rename to Linux_man_cn/ping.md index 8e6abf6..cebd15e --- a/LinuxCommands/ping.md +++ b/Linux_man_cn/ping.md @@ -1,6 +1,6 @@ ping === - + 测试主机之间网络的连通性 ## 补充说明 diff --git a/LinuxCommands/pkill.md b/Linux_man_cn/pkill.md similarity index 100% rename from LinuxCommands/pkill.md rename to Linux_man_cn/pkill.md diff --git a/LinuxCommands/pmap.md b/Linux_man_cn/pmap.md similarity index 100% rename from LinuxCommands/pmap.md rename to Linux_man_cn/pmap.md diff --git a/LinuxCommands/popd.md b/Linux_man_cn/popd.md similarity index 100% rename from LinuxCommands/popd.md rename to Linux_man_cn/popd.md diff --git a/LinuxCommands/poweroff.md b/Linux_man_cn/poweroff.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/poweroff.md rename to Linux_man_cn/poweroff.md diff --git a/LinuxCommands/ppp-off.md b/Linux_man_cn/ppp-off.md similarity index 100% rename from LinuxCommands/ppp-off.md rename to Linux_man_cn/ppp-off.md diff --git a/LinuxCommands/pr.md b/Linux_man_cn/pr.md similarity index 100% rename from LinuxCommands/pr.md rename to Linux_man_cn/pr.md diff --git a/LinuxCommands/printf.md b/Linux_man_cn/printf.md similarity index 100% rename from LinuxCommands/printf.md rename to Linux_man_cn/printf.md diff --git a/LinuxCommands/protoize.md b/Linux_man_cn/protoize.md similarity index 100% rename from LinuxCommands/protoize.md rename to Linux_man_cn/protoize.md diff --git a/LinuxCommands/ps.md b/Linux_man_cn/ps.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/ps.md rename to Linux_man_cn/ps.md index fc94edd..a8ac2c0 --- a/LinuxCommands/ps.md +++ b/Linux_man_cn/ps.md @@ -1,104 +1,104 @@ -# **ps** - -## 说明 - -**ps命令** 用于报告当前系统的进程状态。可以搭配kill指令随时中断、删除不必要的程序。ps命令是最基本同时也是非常强大的进程查看命令,使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等,总之大部分信息都是可以通过执行该命令得到的。 - -## 语法 - -Usage: ps [options] - -## 选项 - -```sh -基本选项 --A, -e all processes --a all with tty, except session leaders - a all with tty, including other users --d 除了sessions之外的所有进程 --N, --deselect negate selection(显示所有的程序,除了执行ps指令终端机下的程序之外) - r only running processes - T all processes on this terminal - x processes without controlling ttys - -Selection by list: --C command name --G, --Group real group id or name --g, --group session or effective group name --p, p, --pid process id - --ppid parent process id --q, q, --quick-pid - process id (quick mode) --s, --sid session id --t, t, --tty terminal --u, U, --user effective user id or name --U, --User real user id or name - The selection options take as their argument either: - a comma-separated list e.g. '-u root,nobody' or - a blank-separated list e.g. '-p 123 4567' - -Output formats: --F extra full --f full-format, including command lines - f, --forest ascii art process tree --H show process hierarchy --j jobs format - j BSD job control format --l long format - l BSD long format --M, Z add security data (for SELinux) --O preloaded with default columns - O as -O, with BSD personality --o, o, --format - user-defined format - s signal format - u user-oriented format - v virtual memory format - X register format --y do not show flags, show rss vs. addr (used with-l) - --context display security context (for SELinux) - --headers repeat header lines, one per page - --no-headers do not print header at all - --cols, --columns, --width - set screen width - --rows, --lines - set screen height - -Show threads: - H as if they were processes --L possibly with LWP and NLWP columns --m, m after processes --T possibly with SPID column - -Miscellaneous options: --c show scheduling class with -l option - c show true command name - e show the environment after command - k, --sort specify sort order as: [+|-]key[,[+|-]key[,...]] - L show format specifiers - n display numeric uid and wchan - S, --cumulative include some dead child process data --y do not show flags, show rss (only with -l) --V, V, --version display version information and exit --w, w unlimited output width - --help - display help and exit -``` - -由于ps命令能够支持的系统类型相当的多,所以选项多的离谱! - -## 实例 - -```sh -# 按内存资源的使用量对进程进行排序 -ps aux | sort -rnk 4 - -# 按 CPU 资源的使用量对进程进行排序 -ps aux | sort -nk 3 - -# 最常用的查询指令; -ps -le or ps -aux 查看所有用户执行的进程的详细信息; -ps -aux --sort pid 可按照进程执行的时间,PID,UID等对进程进行排序; -ps -uU tangsir / ps -aux | grep tangsir查看系统中指定用户执行的进程; -pstree | more 进程树,非常直观的观察父子进程; -``` +# **ps** + +## 说明 + +**ps命令** 用于报告当前系统的进程状态。可以搭配kill指令随时中断、删除不必要的程序。ps命令是最基本同时也是非常强大的进程查看命令,使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等,总之大部分信息都是可以通过执行该命令得到的。 + +## 语法 + +Usage: ps [options] + +## 选项 + +```sh +基本选项 +-A, -e all processes +-a all with tty, except session leaders + a all with tty, including other users +-d 除了sessions之外的所有进程 +-N, --deselect negate selection(显示所有的程序,除了执行ps指令终端机下的程序之外) + r only running processes + T all processes on this terminal + x processes without controlling ttys + +Selection by list: +-C command name +-G, --Group real group id or name +-g, --group session or effective group name +-p, p, --pid process id + --ppid parent process id +-q, q, --quick-pid + process id (quick mode) +-s, --sid session id +-t, t, --tty terminal +-u, U, --user effective user id or name +-U, --User real user id or name + The selection options take as their argument either: + a comma-separated list e.g. '-u root,nobody' or + a blank-separated list e.g. '-p 123 4567' + +Output formats: +-F extra full +-f full-format, including command lines + f, --forest ascii art process tree +-H show process hierarchy +-j jobs format + j BSD job control format +-l long format + l BSD long format +-M, Z add security data (for SELinux) +-O preloaded with default columns + O as -O, with BSD personality +-o, o, --format + user-defined format + s signal format + u user-oriented format + v virtual memory format + X register format +-y do not show flags, show rss vs. addr (used with-l) + --context display security context (for SELinux) + --headers repeat header lines, one per page + --no-headers do not print header at all + --cols, --columns, --width + set screen width + --rows, --lines + set screen height + +Show threads: + H as if they were processes +-L possibly with LWP and NLWP columns +-m, m after processes +-T possibly with SPID column + +Miscellaneous options: +-c show scheduling class with -l option + c show true command name + e show the environment after command + k, --sort specify sort order as: [+|-]key[,[+|-]key[,...]] + L show format specifiers + n display numeric uid and wchan + S, --cumulative include some dead child process data +-y do not show flags, show rss (only with -l) +-V, V, --version display version information and exit +-w, w unlimited output width + --help + display help and exit +``` + +由于ps命令能够支持的系统类型相当的多,所以选项多的离谱! + +## 实例 + +```sh +# 按内存资源的使用量对进程进行排序 +ps aux | sort -rnk 4 + +# 按 CPU 资源的使用量对进程进行排序 +ps aux | sort -nk 3 + +# 最常用的查询指令; +ps -le or ps -aux 查看所有用户执行的进程的详细信息; +ps -aux --sort pid 可按照进程执行的时间,PID,UID等对进程进行排序; +ps -uU tangsir / ps -aux | grep tangsir查看系统中指定用户执行的进程; +pstree | more 进程树,非常直观的观察父子进程; +``` diff --git a/LinuxCommands/pssh.md b/Linux_man_cn/pssh.md similarity index 100% rename from LinuxCommands/pssh.md rename to Linux_man_cn/pssh.md diff --git a/LinuxCommands/pstack.md b/Linux_man_cn/pstack.md similarity index 100% rename from LinuxCommands/pstack.md rename to Linux_man_cn/pstack.md diff --git a/LinuxCommands/pstree.md b/Linux_man_cn/pstree.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/pstree.md rename to Linux_man_cn/pstree.md index b550871..9192d27 --- a/LinuxCommands/pstree.md +++ b/Linux_man_cn/pstree.md @@ -1,58 +1,58 @@ -pstree -=== - -以树状图的方式展现进程之间的派生关系 - -## 补充说明 - -**pstree命令** 以树状图的方式展现进程之间的派生关系,显示效果比较直观。 - -### 语法 - -``` -pstree(选项) -``` - -### 选项 - -``` --a:显示每个程序的完整指令,包含路径,参数或是常驻服务的标示; --c:不使用精简标示法; --G:使用VT100终端机的列绘图字符; --h:列出树状图时,特别标明现在执行的程序; --H<程序识别码>:此参数的效果和指定"-h"参数类似,但特别标明指定的程序; --l:采用长列格式显示树状图; --n:用程序识别码排序。预设是以程序名称来排序; --p:显示程序识别码; --u:显示用户名称; --U:使用UTF-8列绘图字符; --V:显示版本信息。 -``` - -### 实例 - -显示当前所有进程的进程号和进程id - -``` -pstree -p -``` - -显示所有进程的所有详细信息,遇到相同的进程名可以压缩显示。 - -```bash -pstree -a -``` - -获取 SSH 会话的 PID - -``` -pstree -p | grep ssh - -# |-sshd(1221)-+-sshd(2768)---bash(2770)-+-grep(2810) -# | `-sshd(2807)---sshd(2808) -``` - -从上方的输出中,你可以看到 sshd 进程与分支的树形图。sshd 的主进程是 sshd(1221),另两个分支分别为 sshd(2768) 和 sshd(2807)。 - - - +pstree +=== + +以树状图的方式展现进程之间的派生关系 + +## 补充说明 + +**pstree命令** 以树状图的方式展现进程之间的派生关系,显示效果比较直观。 + +### 语法 + +``` +pstree(选项) +``` + +### 选项 + +``` +-a:显示每个程序的完整指令,包含路径,参数或是常驻服务的标示; +-c:不使用精简标示法; +-G:使用VT100终端机的列绘图字符; +-h:列出树状图时,特别标明现在执行的程序; +-H<程序识别码>:此参数的效果和指定"-h"参数类似,但特别标明指定的程序; +-l:采用长列格式显示树状图; +-n:用程序识别码排序。预设是以程序名称来排序; +-p:显示程序识别码; +-u:显示用户名称; +-U:使用UTF-8列绘图字符; +-V:显示版本信息。 +``` + +### 实例 + +显示当前所有进程的进程号和进程id + +``` +pstree -p +``` + +显示所有进程的所有详细信息,遇到相同的进程名可以压缩显示。 + +```bash +pstree -a +``` + +获取 SSH 会话的 PID + +``` +pstree -p | grep ssh + +# |-sshd(1221)-+-sshd(2768)---bash(2770)-+-grep(2810) +# | `-sshd(2807)---sshd(2808) +``` + +从上方的输出中,你可以看到 sshd 进程与分支的树形图。sshd 的主进程是 sshd(1221),另两个分支分别为 sshd(2768) 和 sshd(2807)。 + + + diff --git a/LinuxCommands/pushd.md b/Linux_man_cn/pushd.md similarity index 100% rename from LinuxCommands/pushd.md rename to Linux_man_cn/pushd.md diff --git a/LinuxCommands/pv.md b/Linux_man_cn/pv.md similarity index 100% rename from LinuxCommands/pv.md rename to Linux_man_cn/pv.md diff --git a/LinuxCommands/pvchange.md b/Linux_man_cn/pvchange.md similarity index 100% rename from LinuxCommands/pvchange.md rename to Linux_man_cn/pvchange.md diff --git a/LinuxCommands/pvck.md b/Linux_man_cn/pvck.md similarity index 100% rename from LinuxCommands/pvck.md rename to Linux_man_cn/pvck.md diff --git a/LinuxCommands/pvcreate.md b/Linux_man_cn/pvcreate.md similarity index 100% rename from LinuxCommands/pvcreate.md rename to Linux_man_cn/pvcreate.md diff --git a/LinuxCommands/pvdisplay.md b/Linux_man_cn/pvdisplay.md similarity index 100% rename from LinuxCommands/pvdisplay.md rename to Linux_man_cn/pvdisplay.md diff --git a/LinuxCommands/pvremove.md b/Linux_man_cn/pvremove.md similarity index 100% rename from LinuxCommands/pvremove.md rename to Linux_man_cn/pvremove.md diff --git a/LinuxCommands/pvs.md b/Linux_man_cn/pvs.md similarity index 100% rename from LinuxCommands/pvs.md rename to Linux_man_cn/pvs.md diff --git a/LinuxCommands/pvscan.md b/Linux_man_cn/pvscan.md similarity index 100% rename from LinuxCommands/pvscan.md rename to Linux_man_cn/pvscan.md diff --git a/LinuxCommands/pwck.md b/Linux_man_cn/pwck.md similarity index 100% rename from LinuxCommands/pwck.md rename to Linux_man_cn/pwck.md diff --git a/LinuxCommands/pwconv.md b/Linux_man_cn/pwconv.md similarity index 100% rename from LinuxCommands/pwconv.md rename to Linux_man_cn/pwconv.md diff --git a/LinuxCommands/pwd.md b/Linux_man_cn/pwd.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/pwd.md rename to Linux_man_cn/pwd.md index a2baab5..1ec2f46 --- a/LinuxCommands/pwd.md +++ b/Linux_man_cn/pwd.md @@ -1,6 +1,6 @@ pwd === - + 绝对路径方式显示用户当前工作目录 ## 补充说明 diff --git a/LinuxCommands/pwunconv.md b/Linux_man_cn/pwunconv.md similarity index 100% rename from LinuxCommands/pwunconv.md rename to Linux_man_cn/pwunconv.md diff --git a/LinuxCommands/quota.md b/Linux_man_cn/quota.md similarity index 100% rename from LinuxCommands/quota.md rename to Linux_man_cn/quota.md diff --git a/LinuxCommands/quotacheck.md b/Linux_man_cn/quotacheck.md similarity index 100% rename from LinuxCommands/quotacheck.md rename to Linux_man_cn/quotacheck.md diff --git a/LinuxCommands/quotaoff.md b/Linux_man_cn/quotaoff.md similarity index 100% rename from LinuxCommands/quotaoff.md rename to Linux_man_cn/quotaoff.md diff --git a/LinuxCommands/quotaon.md b/Linux_man_cn/quotaon.md similarity index 100% rename from LinuxCommands/quotaon.md rename to Linux_man_cn/quotaon.md diff --git a/LinuxCommands/rcconf.md b/Linux_man_cn/rcconf.md similarity index 100% rename from LinuxCommands/rcconf.md rename to Linux_man_cn/rcconf.md diff --git a/LinuxCommands/rcp.md b/Linux_man_cn/rcp.md similarity index 100% rename from LinuxCommands/rcp.md rename to Linux_man_cn/rcp.md diff --git a/LinuxCommands/read.md b/Linux_man_cn/read.md similarity index 100% rename from LinuxCommands/read.md rename to Linux_man_cn/read.md diff --git a/LinuxCommands/readelf.md b/Linux_man_cn/readelf.md similarity index 100% rename from LinuxCommands/readelf.md rename to Linux_man_cn/readelf.md diff --git a/LinuxCommands/readonly.md b/Linux_man_cn/readonly.md similarity index 100% rename from LinuxCommands/readonly.md rename to Linux_man_cn/readonly.md diff --git a/LinuxCommands/reboot.md b/Linux_man_cn/reboot.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/reboot.md rename to Linux_man_cn/reboot.md diff --git a/LinuxCommands/reject.md b/Linux_man_cn/reject.md similarity index 100% rename from LinuxCommands/reject.md rename to Linux_man_cn/reject.md diff --git a/LinuxCommands/rename.md b/Linux_man_cn/rename.md similarity index 100% rename from LinuxCommands/rename.md rename to Linux_man_cn/rename.md diff --git a/LinuxCommands/renamemd.sh b/Linux_man_cn/renamemd.sh old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/renamemd.sh rename to Linux_man_cn/renamemd.sh diff --git a/LinuxCommands/renice.md b/Linux_man_cn/renice.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/renice.md rename to Linux_man_cn/renice.md index 4d2aa94..c0264c9 --- a/LinuxCommands/renice.md +++ b/Linux_man_cn/renice.md @@ -1,6 +1,6 @@ renice === - + 修改正在运行的进程的调度优先级 ## 补充说明 diff --git a/LinuxCommands/repquota.md b/Linux_man_cn/repquota.md similarity index 100% rename from LinuxCommands/repquota.md rename to Linux_man_cn/repquota.md diff --git a/LinuxCommands/resize.md b/Linux_man_cn/resize.md similarity index 100% rename from LinuxCommands/resize.md rename to Linux_man_cn/resize.md diff --git a/LinuxCommands/restore.md b/Linux_man_cn/restore.md similarity index 100% rename from LinuxCommands/restore.md rename to Linux_man_cn/restore.md diff --git a/LinuxCommands/restorecon.md b/Linux_man_cn/restorecon.md similarity index 100% rename from LinuxCommands/restorecon.md rename to Linux_man_cn/restorecon.md diff --git a/LinuxCommands/rev.md b/Linux_man_cn/rev.md similarity index 100% rename from LinuxCommands/rev.md rename to Linux_man_cn/rev.md diff --git a/LinuxCommands/rexec.md b/Linux_man_cn/rexec.md similarity index 100% rename from LinuxCommands/rexec.md rename to Linux_man_cn/rexec.md diff --git a/LinuxCommands/rlogin.md b/Linux_man_cn/rlogin.md similarity index 100% rename from LinuxCommands/rlogin.md rename to Linux_man_cn/rlogin.md diff --git a/LinuxCommands/rm.md b/Linux_man_cn/rm.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/rm.md rename to Linux_man_cn/rm.md index 41f9256..7e813ba --- a/LinuxCommands/rm.md +++ b/Linux_man_cn/rm.md @@ -1,6 +1,6 @@ rm === - + 用于删除给定的文件和目录 ## 补充说明 diff --git a/LinuxCommands/rmdir.md b/Linux_man_cn/rmdir.md similarity index 100% rename from LinuxCommands/rmdir.md rename to Linux_man_cn/rmdir.md diff --git a/LinuxCommands/rmmod.md b/Linux_man_cn/rmmod.md similarity index 100% rename from LinuxCommands/rmmod.md rename to Linux_man_cn/rmmod.md diff --git a/LinuxCommands/route.md b/Linux_man_cn/route.md similarity index 100% rename from LinuxCommands/route.md rename to Linux_man_cn/route.md diff --git a/LinuxCommands/rpm.md b/Linux_man_cn/rpm.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/rpm.md rename to Linux_man_cn/rpm.md index 312312f..c97548f --- a/LinuxCommands/rpm.md +++ b/Linux_man_cn/rpm.md @@ -1,6 +1,6 @@ rpm === - + RPM软件包的管理工具 ## 补充说明 diff --git a/LinuxCommands/rpm2cpio.md b/Linux_man_cn/rpm2cpio.md similarity index 100% rename from LinuxCommands/rpm2cpio.md rename to Linux_man_cn/rpm2cpio.md diff --git a/LinuxCommands/rpmbuild.md b/Linux_man_cn/rpmbuild.md similarity index 100% rename from LinuxCommands/rpmbuild.md rename to Linux_man_cn/rpmbuild.md diff --git a/LinuxCommands/rpmdb.md b/Linux_man_cn/rpmdb.md similarity index 100% rename from LinuxCommands/rpmdb.md rename to Linux_man_cn/rpmdb.md diff --git a/LinuxCommands/rpmquery.md b/Linux_man_cn/rpmquery.md similarity index 100% rename from LinuxCommands/rpmquery.md rename to Linux_man_cn/rpmquery.md diff --git a/LinuxCommands/rpmsign.md b/Linux_man_cn/rpmsign.md similarity index 100% rename from LinuxCommands/rpmsign.md rename to Linux_man_cn/rpmsign.md diff --git a/LinuxCommands/rpmverify.md b/Linux_man_cn/rpmverify.md similarity index 100% rename from LinuxCommands/rpmverify.md rename to Linux_man_cn/rpmverify.md diff --git a/LinuxCommands/rsh.md b/Linux_man_cn/rsh.md similarity index 100% rename from LinuxCommands/rsh.md rename to Linux_man_cn/rsh.md diff --git a/LinuxCommands/rsync.md b/Linux_man_cn/rsync.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/rsync.md rename to Linux_man_cn/rsync.md diff --git a/LinuxCommands/runlevel.md b/Linux_man_cn/runlevel.md similarity index 100% rename from LinuxCommands/runlevel.md rename to Linux_man_cn/runlevel.md diff --git a/LinuxCommands/sar.md b/Linux_man_cn/sar.md similarity index 100% rename from LinuxCommands/sar.md rename to Linux_man_cn/sar.md diff --git a/LinuxCommands/scp.md b/Linux_man_cn/scp.md similarity index 100% rename from LinuxCommands/scp.md rename to Linux_man_cn/scp.md diff --git a/LinuxCommands/screen.md b/Linux_man_cn/screen.md similarity index 100% rename from LinuxCommands/screen.md rename to Linux_man_cn/screen.md diff --git a/LinuxCommands/sed.md b/Linux_man_cn/sed.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/sed.md rename to Linux_man_cn/sed.md diff --git a/LinuxCommands/seinfo.md b/Linux_man_cn/seinfo.md similarity index 100% rename from LinuxCommands/seinfo.md rename to Linux_man_cn/seinfo.md diff --git a/LinuxCommands/semanage.md b/Linux_man_cn/semanage.md similarity index 100% rename from LinuxCommands/semanage.md rename to Linux_man_cn/semanage.md diff --git a/LinuxCommands/sendmail.md b/Linux_man_cn/sendmail.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/sendmail.md rename to Linux_man_cn/sendmail.md index a88a7e4..da9729b --- a/LinuxCommands/sendmail.md +++ b/Linux_man_cn/sendmail.md @@ -1,6 +1,6 @@ sendmail === - + 著名电子邮件服务器 ## 补充说明 diff --git a/LinuxCommands/seq.md b/Linux_man_cn/seq.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/seq.md rename to Linux_man_cn/seq.md index 3b2d72a..5cc1ae7 --- a/LinuxCommands/seq.md +++ b/Linux_man_cn/seq.md @@ -1,6 +1,6 @@ seq === - + 以指定增量从首数开始打印数字到尾数 ## 补充说明 diff --git a/LinuxCommands/service.md b/Linux_man_cn/service.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/service.md rename to Linux_man_cn/service.md index 9b9df78..d8291fb --- a/LinuxCommands/service.md +++ b/Linux_man_cn/service.md @@ -1,6 +1,6 @@ service === - + 控制系统服务的实用工具 ## 补充说明 diff --git a/LinuxCommands/sesearch.md b/Linux_man_cn/sesearch.md similarity index 100% rename from LinuxCommands/sesearch.md rename to Linux_man_cn/sesearch.md diff --git a/LinuxCommands/set.md b/Linux_man_cn/set.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/set.md rename to Linux_man_cn/set.md index 8a4fecf..46ad5fb --- a/LinuxCommands/set.md +++ b/Linux_man_cn/set.md @@ -1,6 +1,6 @@ set === - + 显示或设置shell特性及shell变量 ## 补充说明 diff --git a/LinuxCommands/setfacl.md b/Linux_man_cn/setfacl.md similarity index 100% rename from LinuxCommands/setfacl.md rename to Linux_man_cn/setfacl.md diff --git a/LinuxCommands/setpci.md b/Linux_man_cn/setpci.md similarity index 100% rename from LinuxCommands/setpci.md rename to Linux_man_cn/setpci.md diff --git a/LinuxCommands/setsebool.md b/Linux_man_cn/setsebool.md similarity index 100% rename from LinuxCommands/setsebool.md rename to Linux_man_cn/setsebool.md diff --git a/LinuxCommands/sftp-server.md b/Linux_man_cn/sftp-server.md similarity index 100% rename from LinuxCommands/sftp-server.md rename to Linux_man_cn/sftp-server.md diff --git a/LinuxCommands/sftp.md b/Linux_man_cn/sftp.md similarity index 100% rename from LinuxCommands/sftp.md rename to Linux_man_cn/sftp.md diff --git a/LinuxCommands/sh.md b/Linux_man_cn/sh.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/sh.md rename to Linux_man_cn/sh.md index 1800da8..abdc08d --- a/LinuxCommands/sh.md +++ b/Linux_man_cn/sh.md @@ -1,6 +1,6 @@ sh === - + shell命令解释器 ## 补充说明 diff --git a/LinuxCommands/shopt.md b/Linux_man_cn/shopt.md similarity index 100% rename from LinuxCommands/shopt.md rename to Linux_man_cn/shopt.md diff --git a/LinuxCommands/showmount.md b/Linux_man_cn/showmount.md similarity index 100% rename from LinuxCommands/showmount.md rename to Linux_man_cn/showmount.md diff --git a/LinuxCommands/shutdown.md b/Linux_man_cn/shutdown.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/shutdown.md rename to Linux_man_cn/shutdown.md index 8fd2433..5717f63 --- a/LinuxCommands/shutdown.md +++ b/Linux_man_cn/shutdown.md @@ -1,6 +1,6 @@ shutdown === - + 用来执行系统关机的命令 ## 补充说明 diff --git a/LinuxCommands/skill.md b/Linux_man_cn/skill.md similarity index 100% rename from LinuxCommands/skill.md rename to Linux_man_cn/skill.md diff --git a/LinuxCommands/slabtop.md b/Linux_man_cn/slabtop.md similarity index 100% rename from LinuxCommands/slabtop.md rename to Linux_man_cn/slabtop.md diff --git a/LinuxCommands/sleep.md b/Linux_man_cn/sleep.md similarity index 100% rename from LinuxCommands/sleep.md rename to Linux_man_cn/sleep.md diff --git a/LinuxCommands/slocate.md b/Linux_man_cn/slocate.md similarity index 100% rename from LinuxCommands/slocate.md rename to Linux_man_cn/slocate.md diff --git a/LinuxCommands/smbclient.md b/Linux_man_cn/smbclient.md similarity index 100% rename from LinuxCommands/smbclient.md rename to Linux_man_cn/smbclient.md diff --git a/LinuxCommands/smbpasswd.md b/Linux_man_cn/smbpasswd.md similarity index 100% rename from LinuxCommands/smbpasswd.md rename to Linux_man_cn/smbpasswd.md diff --git a/LinuxCommands/sort.md b/Linux_man_cn/sort.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/sort.md rename to Linux_man_cn/sort.md diff --git a/LinuxCommands/source.md b/Linux_man_cn/source.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/source.md rename to Linux_man_cn/source.md diff --git a/LinuxCommands/speedtest-cli.md b/Linux_man_cn/speedtest-cli.md similarity index 100% rename from LinuxCommands/speedtest-cli.md rename to Linux_man_cn/speedtest-cli.md diff --git a/LinuxCommands/spell.md b/Linux_man_cn/spell.md similarity index 100% rename from LinuxCommands/spell.md rename to Linux_man_cn/spell.md diff --git a/LinuxCommands/split.md b/Linux_man_cn/split.md similarity index 100% rename from LinuxCommands/split.md rename to Linux_man_cn/split.md diff --git a/LinuxCommands/squid.md b/Linux_man_cn/squid.md similarity index 100% rename from LinuxCommands/squid.md rename to Linux_man_cn/squid.md diff --git a/LinuxCommands/squidclient.md b/Linux_man_cn/squidclient.md similarity index 100% rename from LinuxCommands/squidclient.md rename to Linux_man_cn/squidclient.md diff --git a/LinuxCommands/ss.md b/Linux_man_cn/ss.md similarity index 100% rename from LinuxCommands/ss.md rename to Linux_man_cn/ss.md diff --git a/LinuxCommands/ssh-add.md b/Linux_man_cn/ssh-add.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ssh-add.md rename to Linux_man_cn/ssh-add.md index 1534da4..fa79059 --- a/LinuxCommands/ssh-add.md +++ b/Linux_man_cn/ssh-add.md @@ -1,6 +1,6 @@ ssh-add === - + 把专用密钥添加到ssh-agent的高速缓存中 ## 补充说明 diff --git a/LinuxCommands/ssh-agent.md b/Linux_man_cn/ssh-agent.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ssh-agent.md rename to Linux_man_cn/ssh-agent.md index 2147e58..1113456 --- a/LinuxCommands/ssh-agent.md +++ b/Linux_man_cn/ssh-agent.md @@ -1,6 +1,6 @@ ssh-agent === - + ssh密钥管理器 ## 补充说明 diff --git a/LinuxCommands/ssh-copy-id.md b/Linux_man_cn/ssh-copy-id.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/ssh-copy-id.md rename to Linux_man_cn/ssh-copy-id.md index ef86216..db75ba9 --- a/LinuxCommands/ssh-copy-id.md +++ b/Linux_man_cn/ssh-copy-id.md @@ -1,6 +1,6 @@ ssh-copy-id === - + 把本地的ssh公钥文件安装到远程主机对应的账户下 ## 补充说明 diff --git a/LinuxCommands/ssh-keygen.md b/Linux_man_cn/ssh-keygen.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/ssh-keygen.md rename to Linux_man_cn/ssh-keygen.md diff --git a/LinuxCommands/ssh-keyscan.md b/Linux_man_cn/ssh-keyscan.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/ssh-keyscan.md rename to Linux_man_cn/ssh-keyscan.md index cfffb06..3363d14 --- a/LinuxCommands/ssh-keyscan.md +++ b/Linux_man_cn/ssh-keyscan.md @@ -1,6 +1,6 @@ ssh-keyscan === - + 收集主机公钥的使用工具 ## 补充说明 diff --git a/LinuxCommands/ssh.md b/Linux_man_cn/ssh.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/ssh.md rename to Linux_man_cn/ssh.md index 7de73b7..68314b0 --- a/LinuxCommands/ssh.md +++ b/Linux_man_cn/ssh.md @@ -1,159 +1,159 @@ -ssh -=== - -openssh套件中的客户端连接工具 - -## 补充说明 - -**ssh命令** 是openssh套件中的客户端连接工具,可以给予ssh加密协议实现安全的远程登录服务器。 - -### 语法 - -``` -ssh(选项)(参数) -``` - -### 选项 - -``` --1:强制使用ssh协议版本1; --2:强制使用ssh协议版本2; --4:强制使用IPv4地址; --6:强制使用IPv6地址; --A:开启认证代理连接转发功能; --a:关闭认证代理连接转发功能; --b:使用本机指定地址作为对应连接的源ip地址; --C:请求压缩所有数据; --F:指定ssh指令的配置文件; --f:后台执行ssh指令; --g:允许远程主机连接主机的转发端口; --i:指定身份文件; --l:指定连接远程服务器登录用户名; --N:不执行远程指令; --o:指定配置选项; --p:指定远程服务器上的端口; --q:静默模式; --X:开启X11转发功能; --x:关闭X11转发功能; --y:开启信任X11转发功能。 -``` - -### 参数 - -* 远程主机:指定要连接的远程ssh服务器; -* 指令:要在远程ssh服务器上执行的指令。 - -### 实例 - -``` -# ssh 用户名@远程服务器地址 -ssh user1@172.24.210.101 -``` - -### 背后故事 - -> 英文:Tatu Ylonen -> 编译:Linux中国/kenxx -> 来源:https://linux.cn/article-8476-1.html - -为什么 SSH(安全终端)的端口号是 22 呢,这不是一个巧合,这其中有个我(Tatu Ylonen,SSH 协议的设计者)未曾诉说的故事。 - - -#### 将 SSH 协议端口号设为 22 的故事 - -1995 年春我编写了 SSH 协议的最初版本,那时候 telnet 和 FTP 正被广泛使用。 - -当时我设计 SSH 协议想着是为了替代 telnet(端口 23)和 ftp(端口21)两个协议的,而端口 22 是空闲的。我想当然地就选择了夹在 telnet 和 ftp 的端口中间的数字。我觉得端口号虽然是个小事但似乎又存在着某种信念。但我到底要怎么拿到那个端口号呢?我未曾拥有过任何一个端口号,但我却认识几个拥有端口号的人! - -在那时取得端口号的事情其实说来挺简单的。毕竟当时的因特网(Internet)并不是很大,是因特网爆炸的早期。端口号分配的活儿是 IANA(Internet Assigned Numbers Authority,互联网数字分配机构)干的。在那时这机构可相当于是因特网先驱 [Jon Postel](https://en.wikipedia.org/wiki/Jon_Postel) 和 [Joyce K. Reynolds](https://en.wikipedia.org/wiki/Joyce_K._Reynolds) 一般的存在。Jon 参与编写了多项主要的协议标准,例如 IP(RFC 791)、ICMP(RFC 792)和 TCP(RFC 793)等一些你应该早有耳闻的协议。 - -我可以说是敬畏 Jon 先生的,他参与编写了几乎所有主要的因特网标准文档(Internet RFC)! - -1995 年 7 月,就在我发布 ssh-1.0 前,我发送了一封邮件给 IANA: - -> From ylo Mon Jul 10 11:45:48 +0300 1995 -> From: Tatu Ylonen -> To: Internet Assigned Numbers Authority -> Subject: 请求取得一个端口号 -> Organization: 芬兰赫尔辛基理工大学 -> -> 亲爱的机构成员: -> -> 我写了个可以在不安全的网络环境中安全地从一台机器登录到另一台机器的程序。它主要是对现有的 telnet 协议以及 rlogin 协议的功能性提升和安全性改进。说的具体些,就是可以防御 IP、DNS > 或路由等欺骗行为。我打算将我的软件免费地发布在因特网上,以得到广泛地使用。 -> -> 我希望为该软件注册一个特权端口号,要是这个端口号在 1 到 255 > 之间就更好了,这样它就可以用在名字服务器的 WKS 字段中了。 -> -> 我在附件中附上了协议标准的草案。这个软件已经在本地运行了几个月了,我已准备在获得端口号后就发布。如果端口号分配一事安排的及时,我希望这周就将要发布的软件准备好。我目前在 beta 版测试时使用的端口号是 > 22,如果要是能够分配到这个端口,我就不用做什么更改了(目前这个端口在列表中还是空闲的)。 -> -> 软件中服务的名称叫 ssh(系 Secure Shell 的缩写)。 -> -> 您最真诚的, -> Tatu Ylonen - -(LCTT 译注:DNS 协议中的 WKS 记录类型意即“众所周知的业务描述”,是类似于 A、MX 这样的 DNS 记录类型,用于描述某个 IP 所提供的服务,目前鲜见使用。参见: https://docs.oracle.com/cd/E19683-01/806-4077/dnsintro-154/index.html 。) - -第二天,我就收到了 Joyce 发来的邮件: - -> Date: Mon, 10 Jul 1995 15:35:33 -0700 -> From: jkrey@ISI.EDU -> To: ylo@cs.hut.fi -> Subject: 回复:请求取得一个端口号 -> Cc: iana@ISI.EDU -> Tatu, -> 我们将端口号 22 分配给 ssh 服务了,你目前是该服务的主要联系人。 -> Joyce - -这就搞定了!SSH 的端口正式使用 22!!! - -1995 年 7 月 12 日上午 2 点 21 分,我给我在赫尔辛基理工大学的测试者们宣布了 SSH 的最后 beta 版本。当日下午 5 点 23 分,我给测试者们宣布了 ssh-1.0.0 版本。1995 年 7 月 12 日,下午 5 点 51 分,我将一份 SSH(安全终端)的宣告发给了 cypherpunks@toad.com 的邮件列表,此外我还将其发给了一些新闻组、邮件列表和一些在因特网上讨论相关话题的人们。 - -#### 如何更改 SSH 服务的端口号 - -SSH 服务器是默认运行在 22 号端口上的。然而,由于某些原因需要,它也可以运行在别的端口上。比如为了方便测试使用,又比如在同一个宿主机上运行多个不同的配置。当然,极少情况下,不使用 root 权限运行它也可以,比如某些必须运行在非特权的端口的情况(端口号大于等于 1024)。 - -端口号可以在配置文件 /etc/ssh/sshd_config 中将 Port 22 更改。也可以使用 -p 选项运行 sshd。SSH 客户端和 sftp 程序也可以使用 -p 选项。 - -#### 配置 SSH 协议穿越防火墙 - -SSH 是少数通常被许可穿越防火墙的协议之一。通常的做法是不限制出站的 SSH 连接,尤其常见于一些较小的或者比较技术型的组织中,而入站的 SSH 连接通常会限制到一台或者是少数几台服务器上。 - -#### 出站的 SSH 连接 - -在防火墙中配置出站的 SSH 连接十分简单。如果完全限制了外发连接,那么只需要创建一个允许 TCP 端口 22 可以外发的规则即可。如果你想限制目标地址,你可以限制该规则仅允许访问你的组织放在云端的外部服务器或保护该云端的跳板服务器即可。 - -#### 反向通道是有风险的 - -其实不限制出站的 SSH 连接虽然是可以的,但是是存在风险的,SSH 协议是支持 通道访问 的。最初的想法是在外部服务器搭建一个 SSH 服务监听来自各处的连接,将进入的连接转发到组织,并让这个连接可以访问某个内部服务器。 - -在某些场景下这当然非常的方便。开发者和系统管理员经常使用它打开一个通道以便于他们可以远程访问,比如在家里或者在旅行中使用笔记本电脑等场景。 - -然而通常来讲这些做法是违背安全策略的,跳过了防火墙管理员和安全团队保护的控制无疑是违背安全策略的,比如这些: PCI、HIPAA、NIST SP 800-53 等。它可以被黑客和外国情报机构用来在组织内留下后门。 - -CryptoAuditor 是一款可以控制通道穿过防火墙或者一组云端服务器入口的产品。该款产品可以配合 通用 SSH 密钥管理器(Universal SSH Key Manager) 来获得对 主机密钥(host keys)的访问,以在启用防火墙并阻挡未授权转发的场景中解密 SSH 会话。 - -#### 入站的 SSH 访问 - -对于入站访问而言,这里有几点需要说一下: - -配置防火墙,并转发所有去往 22 端口的连接只能流向到一个特定的内部网络 IP 地址或者一个 DMZ 主机。在该 IP 上运行 CryptoAuditor 或者跳板机来控制和审查所有访问该组织的连接。 -在防火墙上使用不同的端口访问不同的服务器。 -只允许使用 IPsec 协议这样的 VPN(虚拟专用网)登录后连接 SSH 服务。 - -#### 通过 iptables 服务限制 SSH 访问 - -iptables 是一款内建在 Linux 内核的宿主防火墙。通常配置用于保护服务器以防止被访问那些未明确开启的端口。 - -如果服务器上启用了 iptables,使用下面的命令将可以允许进入的 SSH 访问,当然命令需要以 root 身份运行。 - -``` -iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT -iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT -``` - -如果你想将上述命令创建的规则持久地保存,在某些系统版本中,可使用如下命令: - -``` -service iptables save -``` - - +ssh +=== + +openssh套件中的客户端连接工具 + +## 补充说明 + +**ssh命令** 是openssh套件中的客户端连接工具,可以给予ssh加密协议实现安全的远程登录服务器。 + +### 语法 + +``` +ssh(选项)(参数) +``` + +### 选项 + +``` +-1:强制使用ssh协议版本1; +-2:强制使用ssh协议版本2; +-4:强制使用IPv4地址; +-6:强制使用IPv6地址; +-A:开启认证代理连接转发功能; +-a:关闭认证代理连接转发功能; +-b:使用本机指定地址作为对应连接的源ip地址; +-C:请求压缩所有数据; +-F:指定ssh指令的配置文件; +-f:后台执行ssh指令; +-g:允许远程主机连接主机的转发端口; +-i:指定身份文件; +-l:指定连接远程服务器登录用户名; +-N:不执行远程指令; +-o:指定配置选项; +-p:指定远程服务器上的端口; +-q:静默模式; +-X:开启X11转发功能; +-x:关闭X11转发功能; +-y:开启信任X11转发功能。 +``` + +### 参数 + +* 远程主机:指定要连接的远程ssh服务器; +* 指令:要在远程ssh服务器上执行的指令。 + +### 实例 + +``` +# ssh 用户名@远程服务器地址 +ssh user1@172.24.210.101 +``` + +### 背后故事 + +> 英文:Tatu Ylonen +> 编译:Linux中国/kenxx +> 来源:https://linux.cn/article-8476-1.html + +为什么 SSH(安全终端)的端口号是 22 呢,这不是一个巧合,这其中有个我(Tatu Ylonen,SSH 协议的设计者)未曾诉说的故事。 + + +#### 将 SSH 协议端口号设为 22 的故事 + +1995 年春我编写了 SSH 协议的最初版本,那时候 telnet 和 FTP 正被广泛使用。 + +当时我设计 SSH 协议想着是为了替代 telnet(端口 23)和 ftp(端口21)两个协议的,而端口 22 是空闲的。我想当然地就选择了夹在 telnet 和 ftp 的端口中间的数字。我觉得端口号虽然是个小事但似乎又存在着某种信念。但我到底要怎么拿到那个端口号呢?我未曾拥有过任何一个端口号,但我却认识几个拥有端口号的人! + +在那时取得端口号的事情其实说来挺简单的。毕竟当时的因特网(Internet)并不是很大,是因特网爆炸的早期。端口号分配的活儿是 IANA(Internet Assigned Numbers Authority,互联网数字分配机构)干的。在那时这机构可相当于是因特网先驱 [Jon Postel](https://en.wikipedia.org/wiki/Jon_Postel) 和 [Joyce K. Reynolds](https://en.wikipedia.org/wiki/Joyce_K._Reynolds) 一般的存在。Jon 参与编写了多项主要的协议标准,例如 IP(RFC 791)、ICMP(RFC 792)和 TCP(RFC 793)等一些你应该早有耳闻的协议。 + +我可以说是敬畏 Jon 先生的,他参与编写了几乎所有主要的因特网标准文档(Internet RFC)! + +1995 年 7 月,就在我发布 ssh-1.0 前,我发送了一封邮件给 IANA: + +> From ylo Mon Jul 10 11:45:48 +0300 1995 +> From: Tatu Ylonen +> To: Internet Assigned Numbers Authority +> Subject: 请求取得一个端口号 +> Organization: 芬兰赫尔辛基理工大学 +> +> 亲爱的机构成员: +> +> 我写了个可以在不安全的网络环境中安全地从一台机器登录到另一台机器的程序。它主要是对现有的 telnet 协议以及 rlogin 协议的功能性提升和安全性改进。说的具体些,就是可以防御 IP、DNS > 或路由等欺骗行为。我打算将我的软件免费地发布在因特网上,以得到广泛地使用。 +> +> 我希望为该软件注册一个特权端口号,要是这个端口号在 1 到 255 > 之间就更好了,这样它就可以用在名字服务器的 WKS 字段中了。 +> +> 我在附件中附上了协议标准的草案。这个软件已经在本地运行了几个月了,我已准备在获得端口号后就发布。如果端口号分配一事安排的及时,我希望这周就将要发布的软件准备好。我目前在 beta 版测试时使用的端口号是 > 22,如果要是能够分配到这个端口,我就不用做什么更改了(目前这个端口在列表中还是空闲的)。 +> +> 软件中服务的名称叫 ssh(系 Secure Shell 的缩写)。 +> +> 您最真诚的, +> Tatu Ylonen + +(LCTT 译注:DNS 协议中的 WKS 记录类型意即“众所周知的业务描述”,是类似于 A、MX 这样的 DNS 记录类型,用于描述某个 IP 所提供的服务,目前鲜见使用。参见: https://docs.oracle.com/cd/E19683-01/806-4077/dnsintro-154/index.html 。) + +第二天,我就收到了 Joyce 发来的邮件: + +> Date: Mon, 10 Jul 1995 15:35:33 -0700 +> From: jkrey@ISI.EDU +> To: ylo@cs.hut.fi +> Subject: 回复:请求取得一个端口号 +> Cc: iana@ISI.EDU +> Tatu, +> 我们将端口号 22 分配给 ssh 服务了,你目前是该服务的主要联系人。 +> Joyce + +这就搞定了!SSH 的端口正式使用 22!!! + +1995 年 7 月 12 日上午 2 点 21 分,我给我在赫尔辛基理工大学的测试者们宣布了 SSH 的最后 beta 版本。当日下午 5 点 23 分,我给测试者们宣布了 ssh-1.0.0 版本。1995 年 7 月 12 日,下午 5 点 51 分,我将一份 SSH(安全终端)的宣告发给了 cypherpunks@toad.com 的邮件列表,此外我还将其发给了一些新闻组、邮件列表和一些在因特网上讨论相关话题的人们。 + +#### 如何更改 SSH 服务的端口号 + +SSH 服务器是默认运行在 22 号端口上的。然而,由于某些原因需要,它也可以运行在别的端口上。比如为了方便测试使用,又比如在同一个宿主机上运行多个不同的配置。当然,极少情况下,不使用 root 权限运行它也可以,比如某些必须运行在非特权的端口的情况(端口号大于等于 1024)。 + +端口号可以在配置文件 /etc/ssh/sshd_config 中将 Port 22 更改。也可以使用 -p 选项运行 sshd。SSH 客户端和 sftp 程序也可以使用 -p 选项。 + +#### 配置 SSH 协议穿越防火墙 + +SSH 是少数通常被许可穿越防火墙的协议之一。通常的做法是不限制出站的 SSH 连接,尤其常见于一些较小的或者比较技术型的组织中,而入站的 SSH 连接通常会限制到一台或者是少数几台服务器上。 + +#### 出站的 SSH 连接 + +在防火墙中配置出站的 SSH 连接十分简单。如果完全限制了外发连接,那么只需要创建一个允许 TCP 端口 22 可以外发的规则即可。如果你想限制目标地址,你可以限制该规则仅允许访问你的组织放在云端的外部服务器或保护该云端的跳板服务器即可。 + +#### 反向通道是有风险的 + +其实不限制出站的 SSH 连接虽然是可以的,但是是存在风险的,SSH 协议是支持 通道访问 的。最初的想法是在外部服务器搭建一个 SSH 服务监听来自各处的连接,将进入的连接转发到组织,并让这个连接可以访问某个内部服务器。 + +在某些场景下这当然非常的方便。开发者和系统管理员经常使用它打开一个通道以便于他们可以远程访问,比如在家里或者在旅行中使用笔记本电脑等场景。 + +然而通常来讲这些做法是违背安全策略的,跳过了防火墙管理员和安全团队保护的控制无疑是违背安全策略的,比如这些: PCI、HIPAA、NIST SP 800-53 等。它可以被黑客和外国情报机构用来在组织内留下后门。 + +CryptoAuditor 是一款可以控制通道穿过防火墙或者一组云端服务器入口的产品。该款产品可以配合 通用 SSH 密钥管理器(Universal SSH Key Manager) 来获得对 主机密钥(host keys)的访问,以在启用防火墙并阻挡未授权转发的场景中解密 SSH 会话。 + +#### 入站的 SSH 访问 + +对于入站访问而言,这里有几点需要说一下: + +配置防火墙,并转发所有去往 22 端口的连接只能流向到一个特定的内部网络 IP 地址或者一个 DMZ 主机。在该 IP 上运行 CryptoAuditor 或者跳板机来控制和审查所有访问该组织的连接。 +在防火墙上使用不同的端口访问不同的服务器。 +只允许使用 IPsec 协议这样的 VPN(虚拟专用网)登录后连接 SSH 服务。 + +#### 通过 iptables 服务限制 SSH 访问 + +iptables 是一款内建在 Linux 内核的宿主防火墙。通常配置用于保护服务器以防止被访问那些未明确开启的端口。 + +如果服务器上启用了 iptables,使用下面的命令将可以允许进入的 SSH 访问,当然命令需要以 root 身份运行。 + +``` +iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT +iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT +``` + +如果你想将上述命令创建的规则持久地保存,在某些系统版本中,可使用如下命令: + +``` +service iptables save +``` + + diff --git a/LinuxCommands/sshd.md b/Linux_man_cn/sshd.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/sshd.md rename to Linux_man_cn/sshd.md index a1562c0..5cd811f --- a/LinuxCommands/sshd.md +++ b/Linux_man_cn/sshd.md @@ -1,6 +1,6 @@ sshd === - + openssh软件套件中的服务器守护进程 ## 补充说明 diff --git a/LinuxCommands/startx.md b/Linux_man_cn/startx.md similarity index 100% rename from LinuxCommands/startx.md rename to Linux_man_cn/startx.md diff --git a/LinuxCommands/stat.md b/Linux_man_cn/stat.md similarity index 100% rename from LinuxCommands/stat.md rename to Linux_man_cn/stat.md diff --git a/LinuxCommands/strace.md b/Linux_man_cn/strace.md similarity index 100% rename from LinuxCommands/strace.md rename to Linux_man_cn/strace.md diff --git a/LinuxCommands/strings.md b/Linux_man_cn/strings.md similarity index 100% rename from LinuxCommands/strings.md rename to Linux_man_cn/strings.md diff --git a/LinuxCommands/stty.md b/Linux_man_cn/stty.md similarity index 100% rename from LinuxCommands/stty.md rename to Linux_man_cn/stty.md diff --git a/LinuxCommands/su.md b/Linux_man_cn/su.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/su.md rename to Linux_man_cn/su.md index 1c6b395..2ffb0ad --- a/LinuxCommands/su.md +++ b/Linux_man_cn/su.md @@ -1,6 +1,6 @@ su === - + 用于切换当前用户身份到其他用户身份 ## 补充说明 diff --git a/LinuxCommands/sudo.md b/Linux_man_cn/sudo.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/sudo.md rename to Linux_man_cn/sudo.md index 1072a28..35537f8 --- a/LinuxCommands/sudo.md +++ b/Linux_man_cn/sudo.md @@ -1,6 +1,6 @@ sudo === - + 以其他身份来执行命令 ## 补充说明 diff --git a/LinuxCommands/sum.md b/Linux_man_cn/sum.md similarity index 100% rename from LinuxCommands/sum.md rename to Linux_man_cn/sum.md diff --git a/LinuxCommands/swapoff.md b/Linux_man_cn/swapoff.md similarity index 100% rename from LinuxCommands/swapoff.md rename to Linux_man_cn/swapoff.md diff --git a/LinuxCommands/swapon.md b/Linux_man_cn/swapon.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/swapon.md rename to Linux_man_cn/swapon.md index 8f52e63..3b420de --- a/LinuxCommands/swapon.md +++ b/Linux_man_cn/swapon.md @@ -1,6 +1,6 @@ swapon === - + 激活Linux系统中交换空间 ## 补充说明 diff --git a/LinuxCommands/sync.md b/Linux_man_cn/sync.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/sync.md rename to Linux_man_cn/sync.md index 915922b..43468bc --- a/LinuxCommands/sync.md +++ b/Linux_man_cn/sync.md @@ -1,6 +1,6 @@ sync === - + 用于强制被改变的内容立刻写入磁盘 ## 补充说明 diff --git a/LinuxCommands/sysctl.md b/Linux_man_cn/sysctl.md similarity index 100% rename from LinuxCommands/sysctl.md rename to Linux_man_cn/sysctl.md diff --git a/LinuxCommands/syslog.md b/Linux_man_cn/syslog.md similarity index 100% rename from LinuxCommands/syslog.md rename to Linux_man_cn/syslog.md diff --git a/LinuxCommands/systemctl.md b/Linux_man_cn/systemctl.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/systemctl.md rename to Linux_man_cn/systemctl.md diff --git a/LinuxCommands/systool.md b/Linux_man_cn/systool.md similarity index 100% rename from LinuxCommands/systool.md rename to Linux_man_cn/systool.md diff --git a/LinuxCommands/tac.md b/Linux_man_cn/tac.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/tac.md rename to Linux_man_cn/tac.md index c46ab05..9ce5c21 --- a/LinuxCommands/tac.md +++ b/Linux_man_cn/tac.md @@ -1,6 +1,6 @@ tac === - + 将文件已行为单位的反序输出 ## 补充说明 diff --git a/LinuxCommands/tail.md b/Linux_man_cn/tail.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/tail.md rename to Linux_man_cn/tail.md index 2b0e201..b71a271 --- a/LinuxCommands/tail.md +++ b/Linux_man_cn/tail.md @@ -1,47 +1,47 @@ -tail -=== - -在屏幕上显示指定文件的末尾若干行 - -## 补充说明 - -**tail命令** 用于输入文件中的尾部内容。tail命令默认在屏幕上显示指定文件的末尾10行。如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题。如果没有指定文件或者文件名为“-”,则读取标准输入。 - -注意:如果表示字节或行数的N值之前有一个”+”号,则从文件开头的第N项开始显示,而不是显示文件的最后N项。N值后面可以有后缀:b表示512,k表示1024,m表示1 048576(1M)。 - -### 语法 - -``` -tail(选项)(参数) -``` - -### 选项 - -``` ---retry:即是在tail命令启动时,文件不可访问或者文件稍后变得不可访问,都始终尝试打开文件。使用此选项时需要与选项“——follow=name”连用; --c或——bytes=:输出文件尾部的N(N为整数)个字节内容; --f或;--follow:显示文件最新追加的内容。“name”表示以文件名的方式监视文件的变化。“-f”与“-fdescriptor”等效; --F:与选项“-follow=name”和“--retry"连用时功能相同; --n或——line=:输出文件的尾部N(N位数字)行内容。 ---pid=<进程号>:与“-f”选项连用,当指定的进程号的进程终止后,自动退出tail命令; --q或——quiet或——silent:当有多个文件参数时,不输出各个文件名; --s<秒数>或——sleep-interal=<秒数>:与“-f”选项连用,指定监视文件变化时间隔的秒数; --v或——verbose:当有多个文件参数时,总是输出各个文件名; ---help:显示指令的帮助信息; ---version:显示指令的版本信息。 -``` - -### 参数 - -文件列表:指定要显示尾部内容的文件列表。 - -### 实例 - -``` -tail file (显示文件file的最后10行) -tail -n +20 file (显示文件file的内容,从第20行至文件末尾) -tail -c 10 file (显示文件file的最后10个字符) -``` - - - +tail +=== + +在屏幕上显示指定文件的末尾若干行 + +## 补充说明 + +**tail命令** 用于输入文件中的尾部内容。tail命令默认在屏幕上显示指定文件的末尾10行。如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题。如果没有指定文件或者文件名为“-”,则读取标准输入。 + +注意:如果表示字节或行数的N值之前有一个”+”号,则从文件开头的第N项开始显示,而不是显示文件的最后N项。N值后面可以有后缀:b表示512,k表示1024,m表示1 048576(1M)。 + +### 语法 + +``` +tail(选项)(参数) +``` + +### 选项 + +``` +--retry:即是在tail命令启动时,文件不可访问或者文件稍后变得不可访问,都始终尝试打开文件。使用此选项时需要与选项“——follow=name”连用; +-c或——bytes=:输出文件尾部的N(N为整数)个字节内容; +-f或;--follow:显示文件最新追加的内容。“name”表示以文件名的方式监视文件的变化。“-f”与“-fdescriptor”等效; +-F:与选项“-follow=name”和“--retry"连用时功能相同; +-n或——line=:输出文件的尾部N(N位数字)行内容。 +--pid=<进程号>:与“-f”选项连用,当指定的进程号的进程终止后,自动退出tail命令; +-q或——quiet或——silent:当有多个文件参数时,不输出各个文件名; +-s<秒数>或——sleep-interal=<秒数>:与“-f”选项连用,指定监视文件变化时间隔的秒数; +-v或——verbose:当有多个文件参数时,总是输出各个文件名; +--help:显示指令的帮助信息; +--version:显示指令的版本信息。 +``` + +### 参数 + +文件列表:指定要显示尾部内容的文件列表。 + +### 实例 + +``` +tail file (显示文件file的最后10行) +tail -n +20 file (显示文件file的内容,从第20行至文件末尾) +tail -c 10 file (显示文件file的最后10个字符) +``` + + + diff --git a/LinuxCommands/tailf.md b/Linux_man_cn/tailf.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/tailf.md rename to Linux_man_cn/tailf.md diff --git a/LinuxCommands/talk.md b/Linux_man_cn/talk.md similarity index 100% rename from LinuxCommands/talk.md rename to Linux_man_cn/talk.md diff --git a/LinuxCommands/tar.md b/Linux_man_cn/tar.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/tar.md rename to Linux_man_cn/tar.md index 53d9844..19b7942 --- a/LinuxCommands/tar.md +++ b/Linux_man_cn/tar.md @@ -1,227 +1,227 @@ -# tar--Linux下的归档使用工具,用来打包和备份 - -## 补充说明 - -```sh -**tar命令** 可以为linux的文件和目录创建档案。利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件。tar最初被用来在磁带上创建档案,现在,用户可以在任何设备上创建档案。利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的。 - -首先要弄清两个概念:打包和压缩。打包是指将一大堆文件或目录变成一个总的文件;压缩则是将一个大的文件通过一些压缩算法变成一个小文件。 - -为什么要区分这两个概念呢?这源于Linux中很多压缩程序只能针对一个文件进行压缩,这样当你想要压缩一大堆文件时,你得先将这一大堆文件先打成一个包(tar命令),然后再用压缩程序进行压缩(gzip bzip2命令)。 -``` - -### 语法 - -```sh -tar(选项)(参数) -``` - -### 选项 - -```sh --A或--catenate:新增文件到以存在的备份文件; --B:设置区块大小; --c或--create:建立新的备份文件; --C <目录>:这个选项用在解压缩,若要在特定目录解压缩,可以使用这个选项。 --d:记录文件的差别; --x或--extract或--get:解压缩tar文件; --t或--list:列出备份文件的内容; --z或--gzip或--ungzip:通过gzip指令处理备份文件; --Z或--compress或--uncompress:通过compress指令处理备份文件; --f<备份文件>或--file=<备份文件>:指定备份文件; --v或--verbose:显示指令执行过程; --r:添加文件到已经压缩的文件; --u:添加改变了和现有的文件到已经存在的压缩文件; --j:支持bzip2解压文件; --v:显示操作过程; --l:文件系统边界设置; --k:保留原有文件不覆盖; --m:保留文件不被覆盖; --w:确认压缩文件的正确性; --p或--same-permissions:用原来的文件权限还原文件; --P或--absolute-names:文件名使用绝对名称,不移除文件名称前的“/”号; --N <日期格式> 或 --newer=<日期时间>:只将较指定日期更新的文件保存到备份文件里; ---exclude=<范本样式>:排除符合范本样式的文件。 -``` - -### 参数 - -文件或目录:指定要打包的文件或目录列表。 - -### 实例 - -```sh -- z:有gzip属性的 -- j:有bz2属性的 -- Z:有compress属性的 -- v:显示所有过程 -- O:将文件解开到标准输出 -``` - -下面的参数-f是必须的 - --f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。 - -```bash -tar -cf all.tar *.jpg -# 这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。 - -tar -rf all.tar *.gif -# 这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。 - -tar -uf all.tar logo.gif -# 这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。 - -tar -tf all.tar -# 这条命令是列出all.tar包中所有文件,-t是列出文件的意思 -``` - -#### zip格式 - -压缩: zip -r [目标文件名].zip [原文件/目录名] -解压: unzip [原文件名].zip -注:-r参数代表递归 - -#### tar格式(该格式仅仅打包,不压缩) - -打包:tar -cvf [目标文件名].tar [原文件名/目录名] -解包:tar -xvf [原文件名].tar -注:c参数代表create(创建),x参数代表extract(解包),v参数代表verbose(详细信息),f参数代表filename(文件名),所以f后必须接文件名。 - -#### tar.gz格式 - -方式一:利用前面已经打包好的tar文件,直接用压缩命令。 - -压缩:gzip [原文件名].tar -解压:gunzip [原文件名].tar.gz - -方式二:一次性打包并压缩、解压并解包 - -打包并压缩: tar -zcvf [目标文件名].tar.gz [原文件名/目录名] -解压并解包: tar -zxvf [原文件名].tar.gz -注:z代表用gzip算法来压缩/解压。 - -#### tar.bz2格式 - -方式一:利用已经打包好的tar文件,直接执行压缩命令: - -压缩:bzip2 [原文件名].tar -解压:bunzip2 [原文件名].tar.bz2 -方式二:一次性打包并压缩、解压并解包 - -打包并压缩: tar -jcvf [目标文件名].tar.bz2 [原文件名/目录名] -解压并解包: tar -jxvf [原文件名].tar.bz2 -注:小写j代表用bzip2算法来压缩/解压。 - -#### tar.xz格式 - -方式一:利用已经打包好的tar文件,直接用压缩命令: - -压缩:xz [原文件名].tar -解压:unxz [原文件名].tar.xz -方式二:一次性打包并压缩、解压并解包 - -打包并压缩: tar -Jcvf [目标文件名].tar.xz [原文件名/目录名] -解压并解包: tar -Jxvf [原文件名].tar.xz -注:大写J代表用xz算法来压缩/解压。 - -#### tar.Z格式(已过时) - -方式一:利用已经打包好的tar文件,直接用压缩命令: - -压缩:compress [原文件名].tar -解压:uncompress [原文件名].tar.Z -方式二:一次性打包并压缩、解压并解包 - -打包并压缩: tar -Zcvf [目标文件名].tar.Z [原文件名/目录名] -解压并解包: tar -Zxvf [原文件名].tar.Z -注:大写Z代表用ncompress算法来压缩/解压。另,ncompress是早期Unix系统的压缩格式,但由于ncompress的压缩率太低,现已过时。 - -#### jar格式 - -压缩:jar -cvf [目标文件名].jar [原文件名/目录名] -解压:jar -xvf [原文件名].jar -注:如果是打包的是Java类库,并且该类库中存在主类,那么需要写一个META-INF/MANIFEST.MF配置文件,内容如下: - -Manifest-Version: 1.0 -Created-By: 1.6.0_27 (Sun Microsystems Inc.) -Main-class: the_name_of_the_main_class_should_be_put_here -然后用如下命令打包: - -jar -cvfm [目标文件名].jar META-INF/MANIFEST.MF [原文件名/目录名] -这样以后就能用“java -jar [文件名].jar”命令直接运行主类中的public static void main方法了。 - -#### 7z格式 - -压缩:7z a [目标文件名].7z [原文件名/目录名] -解压:7z x [原文件名].7z -注:这个7z解压命令支持rar格式,即: - -7z x [原文件名].rar - -#### 其它例子 - - **将文件全部打包成tar包** : - -``` -tar -cvf log.tar log2012.log 仅打包,不压缩! -tar -zcvf log.tar.gz log2012.log 打包后,以 gzip 压缩 -tar -jcvf log.tar.bz2 log2012.log 打包后,以 bzip2 压缩 -``` - -在选项`f`之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 如果加`z`选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;如果加`j`选项,则以.tar.bz2来作为tar包名。 - - **查阅上述tar包内有哪些文件** : - -``` -tar -ztvf log.tar.gz -``` - -由于我们使用 gzip 压缩的log.tar.gz,所以要查阅log.tar.gz包内的文件时,就得要加上`z`这个选项了。 - - **将tar包解压缩** : - -``` -tar -zxvf /opt/soft/test/log.tar.gz -``` - -在预设的情况下,我们可以将压缩档在任何地方解开的 - - **只将tar内的部分文件解压出来** : - -``` -tar -zxvf /opt/soft/test/log30.tar.gz log2013.log -``` - -我可以透过`tar -ztvf`来查阅 tar 包内的文件名称,如果单只要一个文件,就可以透过这个方式来解压部分文件! - - **文件备份下来,并且保存其权限** : - -``` -tar -zcvpf log31.tar.gz log2014.log log2015.log log2016.log -``` - -这个`-p`的属性是很重要的,尤其是当您要保留原本文件的属性时。 - - **在文件夹当中,比某个日期新的文件才备份** : - -``` -tar -N "2012/11/13" -zcvf log17.tar.gz test -``` - - **备份文件夹内容是排除部分文件:** - -``` -tar --exclude scf/service -zcvf scf.tar.gz scf/* -``` - - **其实最简单的使用 tar 就只要记忆底下的方式即可:** - -``` -压 缩:tar -jcv -f filename.tar.bz2 要被压缩的文件或目录名称 -查 询:tar -jtv -f filename.tar.bz2 -解压缩:tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录 -``` - - - +# tar--Linux下的归档使用工具,用来打包和备份 + +## 补充说明 + +```sh +**tar命令** 可以为linux的文件和目录创建档案。利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件。tar最初被用来在磁带上创建档案,现在,用户可以在任何设备上创建档案。利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的。 + +首先要弄清两个概念:打包和压缩。打包是指将一大堆文件或目录变成一个总的文件;压缩则是将一个大的文件通过一些压缩算法变成一个小文件。 + +为什么要区分这两个概念呢?这源于Linux中很多压缩程序只能针对一个文件进行压缩,这样当你想要压缩一大堆文件时,你得先将这一大堆文件先打成一个包(tar命令),然后再用压缩程序进行压缩(gzip bzip2命令)。 +``` + +### 语法 + +```sh +tar(选项)(参数) +``` + +### 选项 + +```sh +-A或--catenate:新增文件到以存在的备份文件; +-B:设置区块大小; +-c或--create:建立新的备份文件; +-C <目录>:这个选项用在解压缩,若要在特定目录解压缩,可以使用这个选项。 +-d:记录文件的差别; +-x或--extract或--get:解压缩tar文件; +-t或--list:列出备份文件的内容; +-z或--gzip或--ungzip:通过gzip指令处理备份文件; +-Z或--compress或--uncompress:通过compress指令处理备份文件; +-f<备份文件>或--file=<备份文件>:指定备份文件; +-v或--verbose:显示指令执行过程; +-r:添加文件到已经压缩的文件; +-u:添加改变了和现有的文件到已经存在的压缩文件; +-j:支持bzip2解压文件; +-v:显示操作过程; +-l:文件系统边界设置; +-k:保留原有文件不覆盖; +-m:保留文件不被覆盖; +-w:确认压缩文件的正确性; +-p或--same-permissions:用原来的文件权限还原文件; +-P或--absolute-names:文件名使用绝对名称,不移除文件名称前的“/”号; +-N <日期格式> 或 --newer=<日期时间>:只将较指定日期更新的文件保存到备份文件里; +--exclude=<范本样式>:排除符合范本样式的文件。 +``` + +### 参数 + +文件或目录:指定要打包的文件或目录列表。 + +### 实例 + +```sh +- z:有gzip属性的 +- j:有bz2属性的 +- Z:有compress属性的 +- v:显示所有过程 +- O:将文件解开到标准输出 +``` + +下面的参数-f是必须的 + +-f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。 + +```bash +tar -cf all.tar *.jpg +# 这条命令是将所有.jpg的文件打成一个名为all.tar的包。-c是表示产生新的包,-f指定包的文件名。 + +tar -rf all.tar *.gif +# 这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。 + +tar -uf all.tar logo.gif +# 这条命令是更新原来tar包all.tar中logo.gif文件,-u是表示更新文件的意思。 + +tar -tf all.tar +# 这条命令是列出all.tar包中所有文件,-t是列出文件的意思 +``` + +#### zip格式 + +压缩: zip -r [目标文件名].zip [原文件/目录名] +解压: unzip [原文件名].zip +注:-r参数代表递归 + +#### tar格式(该格式仅仅打包,不压缩) + +打包:tar -cvf [目标文件名].tar [原文件名/目录名] +解包:tar -xvf [原文件名].tar +注:c参数代表create(创建),x参数代表extract(解包),v参数代表verbose(详细信息),f参数代表filename(文件名),所以f后必须接文件名。 + +#### tar.gz格式 + +方式一:利用前面已经打包好的tar文件,直接用压缩命令。 + +压缩:gzip [原文件名].tar +解压:gunzip [原文件名].tar.gz + +方式二:一次性打包并压缩、解压并解包 + +打包并压缩: tar -zcvf [目标文件名].tar.gz [原文件名/目录名] +解压并解包: tar -zxvf [原文件名].tar.gz +注:z代表用gzip算法来压缩/解压。 + +#### tar.bz2格式 + +方式一:利用已经打包好的tar文件,直接执行压缩命令: + +压缩:bzip2 [原文件名].tar +解压:bunzip2 [原文件名].tar.bz2 +方式二:一次性打包并压缩、解压并解包 + +打包并压缩: tar -jcvf [目标文件名].tar.bz2 [原文件名/目录名] +解压并解包: tar -jxvf [原文件名].tar.bz2 +注:小写j代表用bzip2算法来压缩/解压。 + +#### tar.xz格式 + +方式一:利用已经打包好的tar文件,直接用压缩命令: + +压缩:xz [原文件名].tar +解压:unxz [原文件名].tar.xz +方式二:一次性打包并压缩、解压并解包 + +打包并压缩: tar -Jcvf [目标文件名].tar.xz [原文件名/目录名] +解压并解包: tar -Jxvf [原文件名].tar.xz +注:大写J代表用xz算法来压缩/解压。 + +#### tar.Z格式(已过时) + +方式一:利用已经打包好的tar文件,直接用压缩命令: + +压缩:compress [原文件名].tar +解压:uncompress [原文件名].tar.Z +方式二:一次性打包并压缩、解压并解包 + +打包并压缩: tar -Zcvf [目标文件名].tar.Z [原文件名/目录名] +解压并解包: tar -Zxvf [原文件名].tar.Z +注:大写Z代表用ncompress算法来压缩/解压。另,ncompress是早期Unix系统的压缩格式,但由于ncompress的压缩率太低,现已过时。 + +#### jar格式 + +压缩:jar -cvf [目标文件名].jar [原文件名/目录名] +解压:jar -xvf [原文件名].jar +注:如果是打包的是Java类库,并且该类库中存在主类,那么需要写一个META-INF/MANIFEST.MF配置文件,内容如下: + +Manifest-Version: 1.0 +Created-By: 1.6.0_27 (Sun Microsystems Inc.) +Main-class: the_name_of_the_main_class_should_be_put_here +然后用如下命令打包: + +jar -cvfm [目标文件名].jar META-INF/MANIFEST.MF [原文件名/目录名] +这样以后就能用“java -jar [文件名].jar”命令直接运行主类中的public static void main方法了。 + +#### 7z格式 + +压缩:7z a [目标文件名].7z [原文件名/目录名] +解压:7z x [原文件名].7z +注:这个7z解压命令支持rar格式,即: + +7z x [原文件名].rar + +#### 其它例子 + + **将文件全部打包成tar包** : + +``` +tar -cvf log.tar log2012.log 仅打包,不压缩! +tar -zcvf log.tar.gz log2012.log 打包后,以 gzip 压缩 +tar -jcvf log.tar.bz2 log2012.log 打包后,以 bzip2 压缩 +``` + +在选项`f`之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 如果加`z`选项,则以.tar.gz或.tgz来代表gzip压缩过的tar包;如果加`j`选项,则以.tar.bz2来作为tar包名。 + + **查阅上述tar包内有哪些文件** : + +``` +tar -ztvf log.tar.gz +``` + +由于我们使用 gzip 压缩的log.tar.gz,所以要查阅log.tar.gz包内的文件时,就得要加上`z`这个选项了。 + + **将tar包解压缩** : + +``` +tar -zxvf /opt/soft/test/log.tar.gz +``` + +在预设的情况下,我们可以将压缩档在任何地方解开的 + + **只将tar内的部分文件解压出来** : + +``` +tar -zxvf /opt/soft/test/log30.tar.gz log2013.log +``` + +我可以透过`tar -ztvf`来查阅 tar 包内的文件名称,如果单只要一个文件,就可以透过这个方式来解压部分文件! + + **文件备份下来,并且保存其权限** : + +``` +tar -zcvpf log31.tar.gz log2014.log log2015.log log2016.log +``` + +这个`-p`的属性是很重要的,尤其是当您要保留原本文件的属性时。 + + **在文件夹当中,比某个日期新的文件才备份** : + +``` +tar -N "2012/11/13" -zcvf log17.tar.gz test +``` + + **备份文件夹内容是排除部分文件:** + +``` +tar --exclude scf/service -zcvf scf.tar.gz scf/* +``` + + **其实最简单的使用 tar 就只要记忆底下的方式即可:** + +``` +压 缩:tar -jcv -f filename.tar.bz2 要被压缩的文件或目录名称 +查 询:tar -jtv -f filename.tar.bz2 +解压缩:tar -jxv -f filename.tar.bz2 -C 欲解压缩的目录 +``` + + + diff --git a/LinuxCommands/tcpdump.md b/Linux_man_cn/tcpdump.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/tcpdump.md rename to Linux_man_cn/tcpdump.md index ea60ae5..d9af65d --- a/LinuxCommands/tcpdump.md +++ b/Linux_man_cn/tcpdump.md @@ -1,165 +1,165 @@ -tcpdump -=== - -一款sniffer工具,是Linux上的抓包工具,嗅探器。 - -## 补充说明 - -**tcpdump命令** 是一款抓包,嗅探器工具,它可以打印所有经过网络接口的数据包的头信息,也可以使用`-w`选项将数据包保存到文件中,方便以后分析。 - -### 语法 - -``` -tcpdump(选项) -``` - -### 选项 - -``` --a:尝试将网络和广播地址转换成名称; --c<数据包数目>:收到指定的数据包数目后,就停止进行倾倒操作; --d:把编译过的数据包编码转换成可阅读的格式,并倾倒到标准输出; --dd:把编译过的数据包编码转换成C语言的格式,并倾倒到标准输出; --ddd:把编译过的数据包编码转换成十进制数字的格式,并倾倒到标准输出; --e:在每列倾倒资料上显示连接层级的文件头; --f:用数字显示网际网络地址; --F<表达文件>:指定内含表达方式的文件; --i<网络界面>:使用指定的网络截面送出数据包; --l:使用标准输出列的缓冲区; --n:不把主机的网络地址转换成名字; --N:不列出域名; --O:不将数据包编码最佳化; --p:不让网络界面进入混杂模式; --q :快速输出,仅列出少数的传输协议信息; --r<数据包文件>:从指定的文件读取数据包数据; --s<数据包大小>:设置每个数据包的大小; --S:用绝对而非相对数值列出TCP关联数; --t:在每列倾倒资料上不显示时间戳记; --tt: 在每列倾倒资料上显示未经格式化的时间戳记; --T<数据包类型>:强制将表达方式所指定的数据包转译成设置的数据包类型; --v:详细显示指令执行过程; --vv:更详细显示指令执行过程; --x:用十六进制字码列出数据包资料; --w<数据包文件>:把数据包数据写入指定的文件。 -``` - -### 实例 - - **直接启动tcpdump将监视第一个网络接口上所有流过的数据包** - -``` -tcpdump -``` - - **监视指定网络接口的数据包** - -``` -tcpdump -i eth1 -``` - -如果不指定网卡,默认tcpdump只会监视第一个网络接口,一般是eth0,下面的例子都没有指定网络接口。 - - **监视指定主机的数据包** - -打印所有进入或离开sundown的数据包。 - -``` -tcpdump host sundown -``` - -也可以指定ip,例如截获所有210.27.48.1 的主机收到的和发出的所有的数据包 - -``` -tcpdump host 210.27.48.1 -``` - -打印helios 与 hot 或者与 ace 之间通信的数据包 - -``` -tcpdump host helios and \( hot or ace \) -``` - -截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信 - -``` -tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \) -``` - -打印ace与任何其他主机之间通信的IP 数据包, 但不包括与helios之间的数据包. - -``` -tcpdump ip host ace and not helios -``` - -如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令: - -``` -tcpdump ip host 210.27.48.1 and ! 210.27.48.2 -``` - -抓取eth0网卡上的包,使用: - -``` -sudo tcpdump -i eth0 -``` - -截获主机hostname发送的所有数据 - -``` -tcpdump -i eth0 src host hostname -``` - -监视所有送到主机hostname的数据包 - -``` -tcpdump -i eth0 dst host hostname -``` - - **监视指定主机和端口的数据包** - -如果想要获取主机210.27.48.1接收或发出的telnet包,使用如下命令 - -``` -tcpdump tcp port 23 host 210.27.48.1 -``` - -对本机的udp 123 端口进行监视 123 为ntp的服务端口 - -``` -tcpdump udp port 123 -``` - - **监视指定网络的数据包** - -打印本地主机与Berkeley网络上的主机之间的所有通信数据包 - -``` -tcpdump net ucb-ether -``` - -ucb-ether此处可理解为“Berkeley网络”的网络地址,此表达式最原始的含义可表达为:打印网络地址为ucb-ether的所有数据包 - -打印所有通过网关snup的ftp数据包 - -``` -tcpdump 'gateway snup and (port ftp or ftp-data)' -``` - -注意:表达式被单引号括起来了,这可以防止shell对其中的括号进行错误解析 - -打印所有源地址或目标地址是本地主机的IP数据包 - -``` -tcpdump ip and not net localnet -``` - -如果本地网络通过网关连到了另一网络,则另一网络并不能算作本地网络。 - -抓取80端口的HTTP报文,以文本形式展示: - -```bash -sudo tcpdump -i any port 80 -A -``` - - - +tcpdump +=== + +一款sniffer工具,是Linux上的抓包工具,嗅探器。 + +## 补充说明 + +**tcpdump命令** 是一款抓包,嗅探器工具,它可以打印所有经过网络接口的数据包的头信息,也可以使用`-w`选项将数据包保存到文件中,方便以后分析。 + +### 语法 + +``` +tcpdump(选项) +``` + +### 选项 + +``` +-a:尝试将网络和广播地址转换成名称; +-c<数据包数目>:收到指定的数据包数目后,就停止进行倾倒操作; +-d:把编译过的数据包编码转换成可阅读的格式,并倾倒到标准输出; +-dd:把编译过的数据包编码转换成C语言的格式,并倾倒到标准输出; +-ddd:把编译过的数据包编码转换成十进制数字的格式,并倾倒到标准输出; +-e:在每列倾倒资料上显示连接层级的文件头; +-f:用数字显示网际网络地址; +-F<表达文件>:指定内含表达方式的文件; +-i<网络界面>:使用指定的网络截面送出数据包; +-l:使用标准输出列的缓冲区; +-n:不把主机的网络地址转换成名字; +-N:不列出域名; +-O:不将数据包编码最佳化; +-p:不让网络界面进入混杂模式; +-q :快速输出,仅列出少数的传输协议信息; +-r<数据包文件>:从指定的文件读取数据包数据; +-s<数据包大小>:设置每个数据包的大小; +-S:用绝对而非相对数值列出TCP关联数; +-t:在每列倾倒资料上不显示时间戳记; +-tt: 在每列倾倒资料上显示未经格式化的时间戳记; +-T<数据包类型>:强制将表达方式所指定的数据包转译成设置的数据包类型; +-v:详细显示指令执行过程; +-vv:更详细显示指令执行过程; +-x:用十六进制字码列出数据包资料; +-w<数据包文件>:把数据包数据写入指定的文件。 +``` + +### 实例 + + **直接启动tcpdump将监视第一个网络接口上所有流过的数据包** + +``` +tcpdump +``` + + **监视指定网络接口的数据包** + +``` +tcpdump -i eth1 +``` + +如果不指定网卡,默认tcpdump只会监视第一个网络接口,一般是eth0,下面的例子都没有指定网络接口。 + + **监视指定主机的数据包** + +打印所有进入或离开sundown的数据包。 + +``` +tcpdump host sundown +``` + +也可以指定ip,例如截获所有210.27.48.1 的主机收到的和发出的所有的数据包 + +``` +tcpdump host 210.27.48.1 +``` + +打印helios 与 hot 或者与 ace 之间通信的数据包 + +``` +tcpdump host helios and \( hot or ace \) +``` + +截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信 + +``` +tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \) +``` + +打印ace与任何其他主机之间通信的IP 数据包, 但不包括与helios之间的数据包. + +``` +tcpdump ip host ace and not helios +``` + +如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令: + +``` +tcpdump ip host 210.27.48.1 and ! 210.27.48.2 +``` + +抓取eth0网卡上的包,使用: + +``` +sudo tcpdump -i eth0 +``` + +截获主机hostname发送的所有数据 + +``` +tcpdump -i eth0 src host hostname +``` + +监视所有送到主机hostname的数据包 + +``` +tcpdump -i eth0 dst host hostname +``` + + **监视指定主机和端口的数据包** + +如果想要获取主机210.27.48.1接收或发出的telnet包,使用如下命令 + +``` +tcpdump tcp port 23 host 210.27.48.1 +``` + +对本机的udp 123 端口进行监视 123 为ntp的服务端口 + +``` +tcpdump udp port 123 +``` + + **监视指定网络的数据包** + +打印本地主机与Berkeley网络上的主机之间的所有通信数据包 + +``` +tcpdump net ucb-ether +``` + +ucb-ether此处可理解为“Berkeley网络”的网络地址,此表达式最原始的含义可表达为:打印网络地址为ucb-ether的所有数据包 + +打印所有通过网关snup的ftp数据包 + +``` +tcpdump 'gateway snup and (port ftp or ftp-data)' +``` + +注意:表达式被单引号括起来了,这可以防止shell对其中的括号进行错误解析 + +打印所有源地址或目标地址是本地主机的IP数据包 + +``` +tcpdump ip and not net localnet +``` + +如果本地网络通过网关连到了另一网络,则另一网络并不能算作本地网络。 + +抓取80端口的HTTP报文,以文本形式展示: + +```bash +sudo tcpdump -i any port 80 -A +``` + + + diff --git a/LinuxCommands/tcpreplay.md b/Linux_man_cn/tcpreplay.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/tcpreplay.md rename to Linux_man_cn/tcpreplay.md index d7f78ab..bb53ee3 --- a/LinuxCommands/tcpreplay.md +++ b/Linux_man_cn/tcpreplay.md @@ -1,6 +1,6 @@ tcpreplay === - + 将PCAP包重新发送,用于性能或者功能测试 ## 补充说明 diff --git a/LinuxCommands/tee.md b/Linux_man_cn/tee.md similarity index 100% rename from LinuxCommands/tee.md rename to Linux_man_cn/tee.md diff --git a/LinuxCommands/telint.md b/Linux_man_cn/telint.md similarity index 100% rename from LinuxCommands/telint.md rename to Linux_man_cn/telint.md diff --git a/LinuxCommands/telnet.md b/Linux_man_cn/telnet.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/telnet.md rename to Linux_man_cn/telnet.md index bad1d35..97cecbc --- a/LinuxCommands/telnet.md +++ b/Linux_man_cn/telnet.md @@ -1,137 +1,137 @@ -telnet -=== - -登录远程主机和管理 - -## 补充说明 - -**telnet命令** 用于登录远程主机,对远程主机进行管理。telnet因为采用明文传送报文,安全性不好,很多Linux服务器都不开放telnet服务,而改用更安全的ssh方式了。但仍然有很多别的系统可能采用了telnet方式来提供远程登录,因此弄清楚telnet客户端的使用方式仍是很有必要的。 - -### 语法 - -``` -telnet(选项)(参数) -``` - -### 选项 - -``` --8:允许使用8位字符资料,包括输入与输出; --a:尝试自动登入远端系统; --b<主机别名>:使用别名指定远端主机名称; --c:不读取用户专属目录里的.telnetrc文件; --d:启动排错模式; --e<脱离字符>:设置脱离字符; --E:滤除脱离字符; --f:此参数的效果和指定"-F"参数相同; --F:使用Kerberos V5认证时,加上此参数可把本地主机的认证数据上传到远端主机; --k<域名>:使用Kerberos认证时,加上此参数让远端主机采用指定的领域名,而非该主机的域名; --K:不自动登入远端主机; --l<用户名称>:指定要登入远端主机的用户名称; --L:允许输出8位字符资料; --n<记录文件>:指定文件记录相关信息; --r:使用类似rlogin指令的用户界面; --S<服务类型>:设置telnet连线所需的ip TOS信息; --x:假设主机有支持数据加密的功能,就使用它; --X<认证形态>:关闭指定的认证形态。 -``` - -### 参数 - -* 远程主机:指定要登录进行管理的远程主机; -* 端口:指定TELNET协议使用的端口号。 - -### 实例 - -``` -$ telnet 192.168.2.10 -Trying 192.168.2.10... -Connected to 192.168.2.10 (192.168.2.10). -Escape character is '^]'. - - localhost (Linux release 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012) (1) - -login: root -Password: -Login incorrect -``` - -一般情况下不允许root从远程登录,可以先用普通账号登录,然后再用su -切到root用户。 - -``` -$ telnet 192.168.188.132 -Trying 192.168.188.132... -telnet: connect to address 192.168.188.132: Connection refused -telnet: Unable to connect to remote host -``` - -处理这种情况方法: - -1. 确认ip地址是否正确? -1. 确认ip地址对应的主机是否已经开机? -1. 如果主机已经启动,确认路由设置是否设置正确?(使用route命令查看) -1. 如果主机已经启动,确认主机上是否开启了telnet服务?(使用netstat命令查看,TCP的23端口是否有LISTEN状态的行) -1. 如果主机已经启动telnet服务,确认防火墙是否放开了23端口的访问?(使用iptables-save查看) - -**启动telnet服务** - -``` -service xinetd restart -``` - -配置参数,通常的配置如下: - -``` -service telnet -{ - disable = no #启用 - flags = REUSE #socket可重用 - socket_type = stream #连接方式为TCP - wait = no #为每个请求启动一个进程 - user = root #启动服务的用户为root - server = /usr/sbin/in.telnetd #要激活的进程 - log_on_failure += USERID #登录失败时记录登录用户名 -} -``` - -如果要配置允许登录的客户端列表,加入 -``` -only_from = 192.168.0.2 #只允许192.168.0.2登录 -``` -如果要配置禁止登录的客户端列表,加入 -``` -no_access = 192.168.0.{2,3,4} #禁止192.168.0.2、192.168.0.3、192.168.0.4登录 -``` -如果要设置开放时段,加入 -``` -access_times = 9:00-12:00 13:00-17:00 # 每天只有这两个时段开放服务(我们的上班时间:P) -``` - -如果你有两个IP地址,一个是私网的IP地址如192.168.0.2,一个是公网的IP地址如218.75.74.83,如果你希望用户只能从私网来登录telnet服务,那么加入 -``` -bind = 192.168.0.2 -``` - -各配置项具体的含义和语法可参考xined配置文件属性说明(man xinetd.conf) - -配置端口,修改services文件: - -``` -# vi /etc/services -``` - -找到以下两句 - -``` -telnet 23/tcp -telnet 23/udp -``` - -如果前面有#字符,就去掉它。telnet的默认端口是23,这个端口也是黑客端口扫描的主要对象,因此最好将这个端口修改掉,修改的方法很简单,就是将23这个数字修改掉,改成大一点的数字,比如61123。注意,1024以下的端口号是internet保留的端口号,因此最好不要用,还应该注意不要与其它服务的端口冲突。 - -启动服务: -``` -service xinetd restart -``` - - +telnet +=== + +登录远程主机和管理 + +## 补充说明 + +**telnet命令** 用于登录远程主机,对远程主机进行管理。telnet因为采用明文传送报文,安全性不好,很多Linux服务器都不开放telnet服务,而改用更安全的ssh方式了。但仍然有很多别的系统可能采用了telnet方式来提供远程登录,因此弄清楚telnet客户端的使用方式仍是很有必要的。 + +### 语法 + +``` +telnet(选项)(参数) +``` + +### 选项 + +``` +-8:允许使用8位字符资料,包括输入与输出; +-a:尝试自动登入远端系统; +-b<主机别名>:使用别名指定远端主机名称; +-c:不读取用户专属目录里的.telnetrc文件; +-d:启动排错模式; +-e<脱离字符>:设置脱离字符; +-E:滤除脱离字符; +-f:此参数的效果和指定"-F"参数相同; +-F:使用Kerberos V5认证时,加上此参数可把本地主机的认证数据上传到远端主机; +-k<域名>:使用Kerberos认证时,加上此参数让远端主机采用指定的领域名,而非该主机的域名; +-K:不自动登入远端主机; +-l<用户名称>:指定要登入远端主机的用户名称; +-L:允许输出8位字符资料; +-n<记录文件>:指定文件记录相关信息; +-r:使用类似rlogin指令的用户界面; +-S<服务类型>:设置telnet连线所需的ip TOS信息; +-x:假设主机有支持数据加密的功能,就使用它; +-X<认证形态>:关闭指定的认证形态。 +``` + +### 参数 + +* 远程主机:指定要登录进行管理的远程主机; +* 端口:指定TELNET协议使用的端口号。 + +### 实例 + +``` +$ telnet 192.168.2.10 +Trying 192.168.2.10... +Connected to 192.168.2.10 (192.168.2.10). +Escape character is '^]'. + + localhost (Linux release 2.6.18-274.18.1.el5 #1 SMP Thu Feb 9 12:45:44 EST 2012) (1) + +login: root +Password: +Login incorrect +``` + +一般情况下不允许root从远程登录,可以先用普通账号登录,然后再用su -切到root用户。 + +``` +$ telnet 192.168.188.132 +Trying 192.168.188.132... +telnet: connect to address 192.168.188.132: Connection refused +telnet: Unable to connect to remote host +``` + +处理这种情况方法: + +1. 确认ip地址是否正确? +1. 确认ip地址对应的主机是否已经开机? +1. 如果主机已经启动,确认路由设置是否设置正确?(使用route命令查看) +1. 如果主机已经启动,确认主机上是否开启了telnet服务?(使用netstat命令查看,TCP的23端口是否有LISTEN状态的行) +1. 如果主机已经启动telnet服务,确认防火墙是否放开了23端口的访问?(使用iptables-save查看) + +**启动telnet服务** + +``` +service xinetd restart +``` + +配置参数,通常的配置如下: + +``` +service telnet +{ + disable = no #启用 + flags = REUSE #socket可重用 + socket_type = stream #连接方式为TCP + wait = no #为每个请求启动一个进程 + user = root #启动服务的用户为root + server = /usr/sbin/in.telnetd #要激活的进程 + log_on_failure += USERID #登录失败时记录登录用户名 +} +``` + +如果要配置允许登录的客户端列表,加入 +``` +only_from = 192.168.0.2 #只允许192.168.0.2登录 +``` +如果要配置禁止登录的客户端列表,加入 +``` +no_access = 192.168.0.{2,3,4} #禁止192.168.0.2、192.168.0.3、192.168.0.4登录 +``` +如果要设置开放时段,加入 +``` +access_times = 9:00-12:00 13:00-17:00 # 每天只有这两个时段开放服务(我们的上班时间:P) +``` + +如果你有两个IP地址,一个是私网的IP地址如192.168.0.2,一个是公网的IP地址如218.75.74.83,如果你希望用户只能从私网来登录telnet服务,那么加入 +``` +bind = 192.168.0.2 +``` + +各配置项具体的含义和语法可参考xined配置文件属性说明(man xinetd.conf) + +配置端口,修改services文件: + +``` +# vi /etc/services +``` + +找到以下两句 + +``` +telnet 23/tcp +telnet 23/udp +``` + +如果前面有#字符,就去掉它。telnet的默认端口是23,这个端口也是黑客端口扫描的主要对象,因此最好将这个端口修改掉,修改的方法很简单,就是将23这个数字修改掉,改成大一点的数字,比如61123。注意,1024以下的端口号是internet保留的端口号,因此最好不要用,还应该注意不要与其它服务的端口冲突。 + +启动服务: +``` +service xinetd restart +``` + + diff --git a/LinuxCommands/tempfile.md b/Linux_man_cn/tempfile.md similarity index 100% rename from LinuxCommands/tempfile.md rename to Linux_man_cn/tempfile.md diff --git a/LinuxCommands/test.md b/Linux_man_cn/test.md similarity index 100% rename from LinuxCommands/test.md rename to Linux_man_cn/test.md diff --git a/LinuxCommands/tftp.md b/Linux_man_cn/tftp.md similarity index 100% rename from LinuxCommands/tftp.md rename to Linux_man_cn/tftp.md diff --git a/LinuxCommands/time.md b/Linux_man_cn/time.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/time.md rename to Linux_man_cn/time.md index d2bfd2c..453c1bb --- a/LinuxCommands/time.md +++ b/Linux_man_cn/time.md @@ -1,6 +1,6 @@ time === - + 统计给定命令所花费的总时间 ## 补充说明 diff --git a/LinuxCommands/tload.md b/Linux_man_cn/tload.md similarity index 100% rename from LinuxCommands/tload.md rename to Linux_man_cn/tload.md diff --git a/LinuxCommands/top.md b/Linux_man_cn/top.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/top.md rename to Linux_man_cn/top.md diff --git a/LinuxCommands/touch.md b/Linux_man_cn/touch.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/touch.md rename to Linux_man_cn/touch.md index 7c685b0..f38b1f3 --- a/LinuxCommands/touch.md +++ b/Linux_man_cn/touch.md @@ -1,6 +1,6 @@ touch === - + 创建新的空文件 ## 补充说明 diff --git a/LinuxCommands/tput.md b/Linux_man_cn/tput.md similarity index 100% rename from LinuxCommands/tput.md rename to Linux_man_cn/tput.md diff --git a/LinuxCommands/tr.md b/Linux_man_cn/tr.md similarity index 100% rename from LinuxCommands/tr.md rename to Linux_man_cn/tr.md diff --git a/LinuxCommands/tracepath.md b/Linux_man_cn/tracepath.md similarity index 100% rename from LinuxCommands/tracepath.md rename to Linux_man_cn/tracepath.md diff --git a/LinuxCommands/traceroute.md b/Linux_man_cn/traceroute.md similarity index 100% rename from LinuxCommands/traceroute.md rename to Linux_man_cn/traceroute.md diff --git a/LinuxCommands/trap.md b/Linux_man_cn/trap.md similarity index 100% rename from LinuxCommands/trap.md rename to Linux_man_cn/trap.md diff --git a/LinuxCommands/tree.md b/Linux_man_cn/tree.md similarity index 100% rename from LinuxCommands/tree.md rename to Linux_man_cn/tree.md diff --git a/LinuxCommands/tty.md b/Linux_man_cn/tty.md similarity index 100% rename from LinuxCommands/tty.md rename to Linux_man_cn/tty.md diff --git a/LinuxCommands/tune2fs.md b/Linux_man_cn/tune2fs.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/tune2fs.md rename to Linux_man_cn/tune2fs.md diff --git a/LinuxCommands/type.md b/Linux_man_cn/type.md similarity index 100% rename from LinuxCommands/type.md rename to Linux_man_cn/type.md diff --git a/LinuxCommands/ulimit.md b/Linux_man_cn/ulimit.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/ulimit.md rename to Linux_man_cn/ulimit.md index 593db05..054bf00 --- a/LinuxCommands/ulimit.md +++ b/Linux_man_cn/ulimit.md @@ -1,6 +1,6 @@ ulimit === - + 控制shell程序的资源 ## 补充说明 diff --git a/LinuxCommands/umask.md b/Linux_man_cn/umask.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/umask.md rename to Linux_man_cn/umask.md diff --git a/LinuxCommands/umount.md b/Linux_man_cn/umount.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/umount.md rename to Linux_man_cn/umount.md index 42aed99..4e521ce --- a/LinuxCommands/umount.md +++ b/Linux_man_cn/umount.md @@ -1,6 +1,6 @@ umount === - + 用于卸载已经加载的文件系统 ## 补充说明 diff --git a/LinuxCommands/unalias.md b/Linux_man_cn/unalias.md similarity index 100% rename from LinuxCommands/unalias.md rename to Linux_man_cn/unalias.md diff --git a/LinuxCommands/uname.md b/Linux_man_cn/uname.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/uname.md rename to Linux_man_cn/uname.md index 2134b6f..ccd00eb --- a/LinuxCommands/uname.md +++ b/Linux_man_cn/uname.md @@ -1,6 +1,6 @@ uname === - + 显示Linux系统信息 ## 补充说明 diff --git a/LinuxCommands/unarj.md b/Linux_man_cn/unarj.md similarity index 100% rename from LinuxCommands/unarj.md rename to Linux_man_cn/unarj.md diff --git a/LinuxCommands/uncompress.md b/Linux_man_cn/uncompress.md similarity index 100% rename from LinuxCommands/uncompress.md rename to Linux_man_cn/uncompress.md diff --git a/LinuxCommands/unexpand.md b/Linux_man_cn/unexpand.md similarity index 100% rename from LinuxCommands/unexpand.md rename to Linux_man_cn/unexpand.md diff --git a/LinuxCommands/uniq.md b/Linux_man_cn/uniq.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/uniq.md rename to Linux_man_cn/uniq.md index 71fc34c..23a20f8 --- a/LinuxCommands/uniq.md +++ b/Linux_man_cn/uniq.md @@ -1,6 +1,6 @@ uniq === - + 报告或忽略文件中的重复行 ## 补充说明 diff --git a/LinuxCommands/unlink.md b/Linux_man_cn/unlink.md similarity index 100% rename from LinuxCommands/unlink.md rename to Linux_man_cn/unlink.md diff --git a/LinuxCommands/unprotoize.md b/Linux_man_cn/unprotoize.md similarity index 100% rename from LinuxCommands/unprotoize.md rename to Linux_man_cn/unprotoize.md diff --git a/LinuxCommands/unset.md b/Linux_man_cn/unset.md similarity index 100% rename from LinuxCommands/unset.md rename to Linux_man_cn/unset.md diff --git a/LinuxCommands/unzip.md b/Linux_man_cn/unzip.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/unzip.md rename to Linux_man_cn/unzip.md index 3ebee0b..e3d7daf --- a/LinuxCommands/unzip.md +++ b/Linux_man_cn/unzip.md @@ -1,6 +1,6 @@ unzip === - + 用于解压缩由zip命令压缩的压缩包 ## 补充说明 diff --git a/LinuxCommands/updatedb.md b/Linux_man_cn/updatedb.md similarity index 100% rename from LinuxCommands/updatedb.md rename to Linux_man_cn/updatedb.md diff --git a/LinuxCommands/uptime.md b/Linux_man_cn/uptime.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/uptime.md rename to Linux_man_cn/uptime.md index 8fee4d9..610dd83 --- a/LinuxCommands/uptime.md +++ b/Linux_man_cn/uptime.md @@ -1,6 +1,6 @@ uptime === - + 查看Linux系统负载信息 ## 补充说明 diff --git a/LinuxCommands/useradd.md b/Linux_man_cn/useradd.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/useradd.md rename to Linux_man_cn/useradd.md index 3bb1671..a04b07b --- a/LinuxCommands/useradd.md +++ b/Linux_man_cn/useradd.md @@ -1,6 +1,6 @@ useradd === - + 创建的新的系统用户 ## 补充说明 diff --git a/LinuxCommands/userdel.md b/Linux_man_cn/userdel.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/userdel.md rename to Linux_man_cn/userdel.md index bd2efe0..705e62e --- a/LinuxCommands/userdel.md +++ b/Linux_man_cn/userdel.md @@ -1,6 +1,6 @@ userdel === - + 用于删除给定的用户以及与用户相关的文件 ## 补充说明 diff --git a/LinuxCommands/usermod.md b/Linux_man_cn/usermod.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/usermod.md rename to Linux_man_cn/usermod.md index fe45d44..832fa69 --- a/LinuxCommands/usermod.md +++ b/Linux_man_cn/usermod.md @@ -1,6 +1,6 @@ usermod === - + 用于修改用户的基本信息 ## 补充说明 diff --git a/LinuxCommands/usernetctl.md b/Linux_man_cn/usernetctl.md similarity index 100% rename from LinuxCommands/usernetctl.md rename to Linux_man_cn/usernetctl.md diff --git a/LinuxCommands/users.md b/Linux_man_cn/users.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/users.md rename to Linux_man_cn/users.md index 2f94e5f..99f1898 --- a/LinuxCommands/users.md +++ b/Linux_man_cn/users.md @@ -1,6 +1,6 @@ users === - + 显示当前登录系统的所有用户 ## 补充说明 diff --git a/LinuxCommands/uucico.md b/Linux_man_cn/uucico.md similarity index 100% rename from LinuxCommands/uucico.md rename to Linux_man_cn/uucico.md diff --git a/LinuxCommands/uupick.md b/Linux_man_cn/uupick.md similarity index 100% rename from LinuxCommands/uupick.md rename to Linux_man_cn/uupick.md diff --git a/LinuxCommands/vdfuse.md b/Linux_man_cn/vdfuse.md similarity index 100% rename from LinuxCommands/vdfuse.md rename to Linux_man_cn/vdfuse.md diff --git a/LinuxCommands/vgchange.md b/Linux_man_cn/vgchange.md similarity index 100% rename from LinuxCommands/vgchange.md rename to Linux_man_cn/vgchange.md diff --git a/LinuxCommands/vgconvert.md b/Linux_man_cn/vgconvert.md similarity index 100% rename from LinuxCommands/vgconvert.md rename to Linux_man_cn/vgconvert.md diff --git a/LinuxCommands/vgcreate.md b/Linux_man_cn/vgcreate.md similarity index 100% rename from LinuxCommands/vgcreate.md rename to Linux_man_cn/vgcreate.md diff --git a/LinuxCommands/vgdisplay.md b/Linux_man_cn/vgdisplay.md similarity index 100% rename from LinuxCommands/vgdisplay.md rename to Linux_man_cn/vgdisplay.md diff --git a/LinuxCommands/vgextend.md b/Linux_man_cn/vgextend.md similarity index 100% rename from LinuxCommands/vgextend.md rename to Linux_man_cn/vgextend.md diff --git a/LinuxCommands/vgreduce.md b/Linux_man_cn/vgreduce.md similarity index 100% rename from LinuxCommands/vgreduce.md rename to Linux_man_cn/vgreduce.md diff --git a/LinuxCommands/vgremove.md b/Linux_man_cn/vgremove.md similarity index 100% rename from LinuxCommands/vgremove.md rename to Linux_man_cn/vgremove.md diff --git a/LinuxCommands/vgrename.md b/Linux_man_cn/vgrename.md similarity index 100% rename from LinuxCommands/vgrename.md rename to Linux_man_cn/vgrename.md diff --git a/LinuxCommands/vgscan.md b/Linux_man_cn/vgscan.md similarity index 100% rename from LinuxCommands/vgscan.md rename to Linux_man_cn/vgscan.md diff --git a/LinuxCommands/vi.md b/Linux_man_cn/vi.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/vi.md rename to Linux_man_cn/vi.md index 2590fde..a64275a --- a/LinuxCommands/vi.md +++ b/Linux_man_cn/vi.md @@ -1,6 +1,6 @@ vi === - + 功能强大的纯文本编辑器 ## 补充说明 diff --git a/LinuxCommands/vmstat.md b/Linux_man_cn/vmstat.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/vmstat.md rename to Linux_man_cn/vmstat.md diff --git a/LinuxCommands/volname.md b/Linux_man_cn/volname.md similarity index 100% rename from LinuxCommands/volname.md rename to Linux_man_cn/volname.md diff --git a/LinuxCommands/w.md b/Linux_man_cn/w.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/w.md rename to Linux_man_cn/w.md index d22f890..dbbdc9e --- a/LinuxCommands/w.md +++ b/Linux_man_cn/w.md @@ -1,6 +1,6 @@ w === - + 显示目前登入系统的用户信息 ## 补充说明 diff --git a/LinuxCommands/wait.md b/Linux_man_cn/wait.md similarity index 100% rename from LinuxCommands/wait.md rename to Linux_man_cn/wait.md diff --git a/LinuxCommands/wall.md b/Linux_man_cn/wall.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/wall.md rename to Linux_man_cn/wall.md diff --git a/LinuxCommands/watch.md b/Linux_man_cn/watch.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/watch.md rename to Linux_man_cn/watch.md index a195e88..500a07b --- a/LinuxCommands/watch.md +++ b/Linux_man_cn/watch.md @@ -1,49 +1,49 @@ -watch -=== - -可以将命令的输出结果输出到标准输出设备,多用于周期性执行命令/定时执行命令 - -## 补充说明 - -**watch命令** 以周期性的方式执行给定的指令,指令输出以全屏方式显示。watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行。 - -### 语法 - -``` -watch(选项)(参数) -``` - -### 选项 - -```bash --n # 或--interval watch缺省每2秒运行一下程序,可以用-n或-interval来指定间隔的时间。 --d # 或--differences 用-d或--differences 选项watch 会高亮显示变化的区域。 而-d=cumulative选项会把变动过的地方(不管最近的那次有没有变动)都高亮显示出来。 --t # 或-no-title 会关闭watch命令在顶部的时间间隔,命令,当前时间的输出。 --h, --help # 查看帮助文档 -``` - -### 参数 - -指令:需要周期性执行的指令。 - -### 实例 - -```bash -watch -n 1 -d netstat -ant       # 命令:每隔一秒高亮显示网络链接数的变化情况 -watch -n 1 -d 'pstree|grep http' # 每隔一秒高亮显示http链接数的变化情况。 后面接的命令若带有管道符,需要加''将命令区域归整。 -watch 'netstat -an | grep:21 | \ grep<模拟攻击客户机的IP>| wc -l' # 实时查看模拟攻击客户机建立起来的连接数 -watch -d 'ls -l|grep scf' # 监测当前目录中 scf' 的文件的变化 -watch -n 10 'cat /proc/loadavg' # 10秒一次输出系统的平均负载 -watch uptime -watch -t uptime -watch -d -n 1 netstat -ntlp -watch -d 'ls -l | fgrep goface' # 监测goface的文件 -watch -t -differences=cumulative uptime -watch -n 60 from # 监控mail -watch -n 1 "df -i;df" # 监测磁盘inode和block数目变化情况 -``` - -FreeBSD和Linux下watch命令的不同,在Linux下,watch是周期性的执行下个程序,并全屏显示执行结果,如:`watch -n 1 -d netstat -ant`,而在FreeBSD下的watch命令是查看其它用户的正在运行的操作,watch允许你偷看其它terminal正在做什么,该命令只能让超级用户使用。 - - - +watch +=== + +可以将命令的输出结果输出到标准输出设备,多用于周期性执行命令/定时执行命令 + +## 补充说明 + +**watch命令** 以周期性的方式执行给定的指令,指令输出以全屏方式显示。watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行。 + +### 语法 + +``` +watch(选项)(参数) +``` + +### 选项 + +```bash +-n # 或--interval watch缺省每2秒运行一下程序,可以用-n或-interval来指定间隔的时间。 +-d # 或--differences 用-d或--differences 选项watch 会高亮显示变化的区域。 而-d=cumulative选项会把变动过的地方(不管最近的那次有没有变动)都高亮显示出来。 +-t # 或-no-title 会关闭watch命令在顶部的时间间隔,命令,当前时间的输出。 +-h, --help # 查看帮助文档 +``` + +### 参数 + +指令:需要周期性执行的指令。 + +### 实例 + +```bash +watch -n 1 -d netstat -ant       # 命令:每隔一秒高亮显示网络链接数的变化情况 +watch -n 1 -d 'pstree|grep http' # 每隔一秒高亮显示http链接数的变化情况。 后面接的命令若带有管道符,需要加''将命令区域归整。 +watch 'netstat -an | grep:21 | \ grep<模拟攻击客户机的IP>| wc -l' # 实时查看模拟攻击客户机建立起来的连接数 +watch -d 'ls -l|grep scf' # 监测当前目录中 scf' 的文件的变化 +watch -n 10 'cat /proc/loadavg' # 10秒一次输出系统的平均负载 +watch uptime +watch -t uptime +watch -d -n 1 netstat -ntlp +watch -d 'ls -l | fgrep goface' # 监测goface的文件 +watch -t -differences=cumulative uptime +watch -n 60 from # 监控mail +watch -n 1 "df -i;df" # 监测磁盘inode和block数目变化情况 +``` + +FreeBSD和Linux下watch命令的不同,在Linux下,watch是周期性的执行下个程序,并全屏显示执行结果,如:`watch -n 1 -d netstat -ant`,而在FreeBSD下的watch命令是查看其它用户的正在运行的操作,watch允许你偷看其它terminal正在做什么,该命令只能让超级用户使用。 + + + diff --git a/LinuxCommands/wc.md b/Linux_man_cn/wc.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/wc.md rename to Linux_man_cn/wc.md index cc452b0..31c532c --- a/LinuxCommands/wc.md +++ b/Linux_man_cn/wc.md @@ -1,66 +1,66 @@ -wc -=== - -统计文件的字节数、字数、行数 - -## 补充说明 - -**wc命令** 统计指定文件中的字节数、字数、行数,并将统计结果显示输出。利用wc指令我们可以计算文件的Byte数、字数或是列数,若不指定文件名称,或是所给予的文件名为“-”,则wc指令会从标准输入设备读取数据。wc同时也给出所指定文件的总统计数。 - -### 语法 - -``` -wc(选项)(参数) -``` - -### 选项 - -```bash --c # 统计字节数,或--bytes或——chars:只显示Bytes数;。 --l # 统计行数,或——lines:只显示列数;。 --m # 统计字符数。这个标志不能与 -c 标志一起使用。 --w # 统计字数,或——words:只显示字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。 --L # 打印最长行的长度。 --help # 显示帮助信息 ---version # 显示版本信息 -``` - -### 参数 - -文件:需要统计的文件列表。 - -## 例子 - -```bash -wc -l * # 统计当前目录下的所有文件行数 -wc -l *.js   # 统计当前目录下的所有 .js 后缀的文件行数 -find . * | xargs wc -l # 当前目录以及子目录的所有文件行数 -wc test.txt # 查看文件的字节数、字数、行数 -``` - -查看文件的字节数、字数、行数 - -```bash -wc test.txt -# 输出结果 -7 8 70 test.txt -行数 单词数 字节数 文件名 -``` - -用wc命令怎么做到只打印统计数字不打印文件名 - -```bash -wc -l test.txt -# 输出结果 -7 test.txt -``` - -用来统计当前目录下的文件数 - -```bash -ls -l | wc -l -# 输出结果 -8 -``` - - +wc +=== + +统计文件的字节数、字数、行数 + +## 补充说明 + +**wc命令** 统计指定文件中的字节数、字数、行数,并将统计结果显示输出。利用wc指令我们可以计算文件的Byte数、字数或是列数,若不指定文件名称,或是所给予的文件名为“-”,则wc指令会从标准输入设备读取数据。wc同时也给出所指定文件的总统计数。 + +### 语法 + +``` +wc(选项)(参数) +``` + +### 选项 + +```bash +-c # 统计字节数,或--bytes或——chars:只显示Bytes数;。 +-l # 统计行数,或——lines:只显示列数;。 +-m # 统计字符数。这个标志不能与 -c 标志一起使用。 +-w # 统计字数,或——words:只显示字数。一个字被定义为由空白、跳格或换行字符分隔的字符串。 +-L # 打印最长行的长度。 +-help # 显示帮助信息 +--version # 显示版本信息 +``` + +### 参数 + +文件:需要统计的文件列表。 + +## 例子 + +```bash +wc -l * # 统计当前目录下的所有文件行数 +wc -l *.js   # 统计当前目录下的所有 .js 后缀的文件行数 +find . * | xargs wc -l # 当前目录以及子目录的所有文件行数 +wc test.txt # 查看文件的字节数、字数、行数 +``` + +查看文件的字节数、字数、行数 + +```bash +wc test.txt +# 输出结果 +7 8 70 test.txt +行数 单词数 字节数 文件名 +``` + +用wc命令怎么做到只打印统计数字不打印文件名 + +```bash +wc -l test.txt +# 输出结果 +7 test.txt +``` + +用来统计当前目录下的文件数 + +```bash +ls -l | wc -l +# 输出结果 +8 +``` + + diff --git a/LinuxCommands/wget.md b/Linux_man_cn/wget.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/wget.md rename to Linux_man_cn/wget.md diff --git a/LinuxCommands/whatis.md b/Linux_man_cn/whatis.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/whatis.md rename to Linux_man_cn/whatis.md index a6606f4..f92f89c --- a/LinuxCommands/whatis.md +++ b/Linux_man_cn/whatis.md @@ -1,6 +1,6 @@ whatis === - + 查询一个命令执行什么功能 ## 补充说明 diff --git a/LinuxCommands/whereis.md b/Linux_man_cn/whereis.md old mode 100755 new mode 100644 similarity index 99% rename from LinuxCommands/whereis.md rename to Linux_man_cn/whereis.md index a0ff8c5..65a82ce --- a/LinuxCommands/whereis.md +++ b/Linux_man_cn/whereis.md @@ -1,6 +1,6 @@ whereis === - + 查找二进制程序、代码等相关文件路径 ## 补充说明 diff --git a/LinuxCommands/which.md b/Linux_man_cn/which.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/which.md rename to Linux_man_cn/which.md index 073ddd2..74690f9 --- a/LinuxCommands/which.md +++ b/Linux_man_cn/which.md @@ -1,51 +1,51 @@ -which -=== - -查找并显示给定命令的绝对路径 - -## 补充说明 - -**which命令** 用于查找并显示给定命令的绝对路径,环境变量PATH中保存了查找命令时需要遍历的目录。which指令会在环境变量$PATH设置的目录里查找符合条件的文件。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。 - -### 语法 - -``` -which(选项)(参数) -``` - -### 选项 - -``` --n<文件名长度>:制定文件名长度,指定的长度必须大于或等于所有文件中最长的文件名; --p<文件名长度>:与-n参数相同,但此处的<文件名长度>包含了文件的路径; --w:指定输出时栏位的宽度; --V:显示版本信息。 -``` - -### 参数 - -指令名:指令名列表。 - -### 实例 - -查找文件、显示命令路径: - -``` -[root@localhost ~]# which pwd -/bin/pwd - -[root@localhost ~]# which adduser -/usr/sbin/adduser -``` - -说明:which是根据使用者所配置的 PATH 变量内的目录去搜寻可运行档的!所以,不同的 PATH 配置内容所找到的命令当然不一样的! - -用 which 去找出 cd - -``` -[root@localhost ~]# which cd -cd: shell built-in command -``` -cd 这个常用的命令竟然找不到啊!为什么呢?这是因为 cd 是bash 内建的命令! 但是 which 默认是找 PATH 内所规范的目录,所以当然一定找不到的! - - +which +=== + +查找并显示给定命令的绝对路径 + +## 补充说明 + +**which命令** 用于查找并显示给定命令的绝对路径,环境变量PATH中保存了查找命令时需要遍历的目录。which指令会在环境变量$PATH设置的目录里查找符合条件的文件。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。 + +### 语法 + +``` +which(选项)(参数) +``` + +### 选项 + +``` +-n<文件名长度>:制定文件名长度,指定的长度必须大于或等于所有文件中最长的文件名; +-p<文件名长度>:与-n参数相同,但此处的<文件名长度>包含了文件的路径; +-w:指定输出时栏位的宽度; +-V:显示版本信息。 +``` + +### 参数 + +指令名:指令名列表。 + +### 实例 + +查找文件、显示命令路径: + +``` +[root@localhost ~]# which pwd +/bin/pwd + +[root@localhost ~]# which adduser +/usr/sbin/adduser +``` + +说明:which是根据使用者所配置的 PATH 变量内的目录去搜寻可运行档的!所以,不同的 PATH 配置内容所找到的命令当然不一样的! + +用 which 去找出 cd + +``` +[root@localhost ~]# which cd +cd: shell built-in command +``` +cd 这个常用的命令竟然找不到啊!为什么呢?这是因为 cd 是bash 内建的命令! 但是 which 默认是找 PATH 内所规范的目录,所以当然一定找不到的! + + diff --git a/LinuxCommands/who.md b/Linux_man_cn/who.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/who.md rename to Linux_man_cn/who.md index 7ea8c9b..dc124a3 --- a/LinuxCommands/who.md +++ b/Linux_man_cn/who.md @@ -1,6 +1,6 @@ who === - + 显示目前登录系统的用户信息 ## 补充说明 diff --git a/LinuxCommands/whoami.md b/Linux_man_cn/whoami.md old mode 100755 new mode 100644 similarity index 95% rename from LinuxCommands/whoami.md rename to Linux_man_cn/whoami.md index 3cd1c5e..e337830 --- a/LinuxCommands/whoami.md +++ b/Linux_man_cn/whoami.md @@ -1,6 +1,6 @@ whoami === - + 打印当前有效的用户名称 ## 补充说明 diff --git a/LinuxCommands/write.md b/Linux_man_cn/write.md similarity index 100% rename from LinuxCommands/write.md rename to Linux_man_cn/write.md diff --git a/LinuxCommands/xargs.md b/Linux_man_cn/xargs.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/xargs.md rename to Linux_man_cn/xargs.md index ef7ee41..31afb95 --- a/LinuxCommands/xargs.md +++ b/Linux_man_cn/xargs.md @@ -1,217 +1,217 @@ -xargs -=== - -给其他命令传递参数的一个过滤器 -### 语法 - -```sh -xargs [OPTION]... COMMAND INITIAL-ARGS... -Run COMMAND with arguments INITIAL-ARGS and more arguments read from input. - -Mandatory arguments to long options are mandatory for short options too. -Non-mandatory arguments are indicated by [square brackets] - -0, --null Items are separated by a null, not whitespace. - Disables quote and backslash processing - -a, --arg-file=FILE Read arguments from FILE, not standard input - -d, --delimiter=CHARACTER Input items are separated by CHARACTER, not by - blank space. Disables quote and backslash - processing - -E END If END occurs as a line of input, the rest of - the input is ignored. - -e [END], --eof[=END] Equivalent to -E END if END is specified. - Otherwise, there is no end-of-file string - --help Print a summary of the options to xargs. - -I R same as --replace=R (R must be specified) - -i,--replace=[R] Replace R in initial arguments with names - read from standard input. If R is - unspecified, assume {} - -L,-l, --max-lines=MAX-LINES Use at most MAX-LINES nonblank input lines per - command line - -l Use at most one nonblank input line per - command line - -n, --max-args=MAX-ARGS Use at most MAX-ARGS arguments per command - line - -P, --max-procs=MAX-PROCS Run up to max-procs processes at a time - -p, --interactive Prompt before running commands - --process-slot-var=VAR Set environment variable VAR in child - processes - -r, --no-run-if-empty If there are no arguments, run no command. - If this option is not given, COMMAND will be - run at least once. - -s, --max-chars=MAX-CHARS Limit commands to MAX-CHARS at most - --show-limits Show limits on command-line length. - -t, --verbose Print commands before executing them - --version Print the version number - -x, --exit Exit if the size (see -s) is exceeded - -``` - -## 补充说明 - -**xargs命令** 是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。它擅长将标准输入数据转换成命令行参数,xargs能够处理管道或者stdin并将其转换成特定命令的命令参数。xargs也可以将单行或多行文本输入转换为其他格式,例如多行变单行,单行变多行。xargs的默认命令是echo,空格是默认定界符。这意味着通过管道传递给xargs的输入将会包含换行和空白,不过通过xargs的处理,换行和空白将被空格取代。xargs是构建单行命令的重要组件之一。 - -### xargs命令用法 - -xargs用作替换工具,读取输入数据重新格式化后输出。 - -定义一个测试文件,内有多行文本数据: - -``` -cat test.txt - -a b c d e f g -h i j k l m n -o p q -r s t -u v w x y z - -``` - -多行输入单行输出: - -``` -cat test.txt | xargs - -a b c d e f g h i j k l m n o p q r s t u v w x y z -``` - - **-n选项** 多行输出: - -``` -cat test.txt | xargs -n3 - -a b c -d e f -g h i -j k l -m n o -p q r -s t u -v w x -y z -``` - - **-d选项** 可以自定义一个定界符: - -``` -echo "nameXnameXnameXname" | xargs -dX - -name name name name -``` - -结合 **-n选项** 使用: - -``` -echo "nameXnameXnameXname" | xargs -dX -n2 - -name name -name name -``` - - **读取stdin,将格式化后的参数传递给命令** - -假设一个命令为 sk.sh 和一个保存参数的文件arg.txt: - -``` -#!/bin/bash -#sk.sh命令内容,打印出所有参数。 - -echo $* - -``` - -arg.txt文件内容: - -``` -cat arg.txt - -aaa -bbb -ccc - -``` - -xargs的一个 **选项-I** ,使用-I指定一个替换字符串{},这个字符串在xargs扩展时会被替换掉,当-I与xargs结合使用,每一个参数命令都会被执行一次: - -``` -cat arg.txt | xargs -I {} ./sk.sh -p {} -l - --p aaa -l --p bbb -l --p ccc -l - -``` - -```sh -# 复制所有图片文件到 /data/images 目录 -ls *.jpg | xargs -n1 -I cp {} /data/images - - - -``` - - **xargs结合find使用** - -用rm 删除太多的文件时候,可能得到一个错误信息:/bin/rm Argument list too long. 用xargs去避免这个问题: - -``` -find . -type f -name "*.log" -print0 | xargs -0 rm -f -``` - -xargs -0将\0作为定界符。 - -统计一个源代码目录中所有php文件的行数: - -``` -find . -type f -name "*.php" -print0 | xargs -0 wc -l -``` - -查找所有的jpg 文件,并且压缩它们: - -``` -find . -type f -name "*.jpg" -print | xargs tar -czvf images.tar.gz - -``` - - **xargs其他应用** - -假如你有一个文件包含了很多你希望下载的URL,你能够使用xargs下载所有链接: - -``` -cat url-list.txt | xargs wget -c - -``` - -### 子Shell(Subshells) - -运行一个shell脚本时会启动另一个命令解释器.,就好像你的命令是在命令行提示下被解释的一样,类似于批处理文件里的一系列命令。每个shell脚本有效地运行在父shell(parent shell)的一个子进程里。这个父shell是指在一个控制终端或在一个xterm窗口中给你命令指示符的进程。 - -``` -cmd1 | ( cmd2; cmd3; cmd4 ) | cmd5 -``` - -如果cmd2 是cd /,那么就会改变子Shell的工作目录,这种改变只是局限于子shell内部,cmd5则完全不知道工作目录发生的变化。子shell是嵌在圆括号()内部的命令序列,子Shell内部定义的变量为局部变量。 - -子shell可用于为一组命令设定临时的环境变量: - -``` -COMMAND1 -COMMAND2 -COMMAND3 -( - IFS=: - PATH=/bin - unset TERMINFO - set -C - shift 5 - COMMAND4 - COMMAND5 - exit 3 # 只是从子shell退出。 -) -# 父shell不受影响,变量值没有更改。 -COMMAND6 -COMMAND7 -``` - - - +xargs +=== + +给其他命令传递参数的一个过滤器 +### 语法 + +```sh +xargs [OPTION]... COMMAND INITIAL-ARGS... +Run COMMAND with arguments INITIAL-ARGS and more arguments read from input. + +Mandatory arguments to long options are mandatory for short options too. +Non-mandatory arguments are indicated by [square brackets] + -0, --null Items are separated by a null, not whitespace. + Disables quote and backslash processing + -a, --arg-file=FILE Read arguments from FILE, not standard input + -d, --delimiter=CHARACTER Input items are separated by CHARACTER, not by + blank space. Disables quote and backslash + processing + -E END If END occurs as a line of input, the rest of + the input is ignored. + -e [END], --eof[=END] Equivalent to -E END if END is specified. + Otherwise, there is no end-of-file string + --help Print a summary of the options to xargs. + -I R same as --replace=R (R must be specified) + -i,--replace=[R] Replace R in initial arguments with names + read from standard input. If R is + unspecified, assume {} + -L,-l, --max-lines=MAX-LINES Use at most MAX-LINES nonblank input lines per + command line + -l Use at most one nonblank input line per + command line + -n, --max-args=MAX-ARGS Use at most MAX-ARGS arguments per command + line + -P, --max-procs=MAX-PROCS Run up to max-procs processes at a time + -p, --interactive Prompt before running commands + --process-slot-var=VAR Set environment variable VAR in child + processes + -r, --no-run-if-empty If there are no arguments, run no command. + If this option is not given, COMMAND will be + run at least once. + -s, --max-chars=MAX-CHARS Limit commands to MAX-CHARS at most + --show-limits Show limits on command-line length. + -t, --verbose Print commands before executing them + --version Print the version number + -x, --exit Exit if the size (see -s) is exceeded + +``` + +## 补充说明 + +**xargs命令** 是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。它擅长将标准输入数据转换成命令行参数,xargs能够处理管道或者stdin并将其转换成特定命令的命令参数。xargs也可以将单行或多行文本输入转换为其他格式,例如多行变单行,单行变多行。xargs的默认命令是echo,空格是默认定界符。这意味着通过管道传递给xargs的输入将会包含换行和空白,不过通过xargs的处理,换行和空白将被空格取代。xargs是构建单行命令的重要组件之一。 + +### xargs命令用法 + +xargs用作替换工具,读取输入数据重新格式化后输出。 + +定义一个测试文件,内有多行文本数据: + +``` +cat test.txt + +a b c d e f g +h i j k l m n +o p q +r s t +u v w x y z + +``` + +多行输入单行输出: + +``` +cat test.txt | xargs + +a b c d e f g h i j k l m n o p q r s t u v w x y z +``` + + **-n选项** 多行输出: + +``` +cat test.txt | xargs -n3 + +a b c +d e f +g h i +j k l +m n o +p q r +s t u +v w x +y z +``` + + **-d选项** 可以自定义一个定界符: + +``` +echo "nameXnameXnameXname" | xargs -dX + +name name name name +``` + +结合 **-n选项** 使用: + +``` +echo "nameXnameXnameXname" | xargs -dX -n2 + +name name +name name +``` + + **读取stdin,将格式化后的参数传递给命令** + +假设一个命令为 sk.sh 和一个保存参数的文件arg.txt: + +``` +#!/bin/bash +#sk.sh命令内容,打印出所有参数。 + +echo $* + +``` + +arg.txt文件内容: + +``` +cat arg.txt + +aaa +bbb +ccc + +``` + +xargs的一个 **选项-I** ,使用-I指定一个替换字符串{},这个字符串在xargs扩展时会被替换掉,当-I与xargs结合使用,每一个参数命令都会被执行一次: + +``` +cat arg.txt | xargs -I {} ./sk.sh -p {} -l + +-p aaa -l +-p bbb -l +-p ccc -l + +``` + +```sh +# 复制所有图片文件到 /data/images 目录 +ls *.jpg | xargs -n1 -I cp {} /data/images + + + +``` + + **xargs结合find使用** + +用rm 删除太多的文件时候,可能得到一个错误信息:/bin/rm Argument list too long. 用xargs去避免这个问题: + +``` +find . -type f -name "*.log" -print0 | xargs -0 rm -f +``` + +xargs -0将\0作为定界符。 + +统计一个源代码目录中所有php文件的行数: + +``` +find . -type f -name "*.php" -print0 | xargs -0 wc -l +``` + +查找所有的jpg 文件,并且压缩它们: + +``` +find . -type f -name "*.jpg" -print | xargs tar -czvf images.tar.gz + +``` + + **xargs其他应用** + +假如你有一个文件包含了很多你希望下载的URL,你能够使用xargs下载所有链接: + +``` +cat url-list.txt | xargs wget -c + +``` + +### 子Shell(Subshells) + +运行一个shell脚本时会启动另一个命令解释器.,就好像你的命令是在命令行提示下被解释的一样,类似于批处理文件里的一系列命令。每个shell脚本有效地运行在父shell(parent shell)的一个子进程里。这个父shell是指在一个控制终端或在一个xterm窗口中给你命令指示符的进程。 + +``` +cmd1 | ( cmd2; cmd3; cmd4 ) | cmd5 +``` + +如果cmd2 是cd /,那么就会改变子Shell的工作目录,这种改变只是局限于子shell内部,cmd5则完全不知道工作目录发生的变化。子shell是嵌在圆括号()内部的命令序列,子Shell内部定义的变量为局部变量。 + +子shell可用于为一组命令设定临时的环境变量: + +``` +COMMAND1 +COMMAND2 +COMMAND3 +( + IFS=: + PATH=/bin + unset TERMINFO + set -C + shift 5 + COMMAND4 + COMMAND5 + exit 3 # 只是从子shell退出。 +) +# 父shell不受影响,变量值没有更改。 +COMMAND6 +COMMAND7 +``` + + + diff --git a/LinuxCommands/xauth.md b/Linux_man_cn/xauth.md similarity index 100% rename from LinuxCommands/xauth.md rename to Linux_man_cn/xauth.md diff --git a/LinuxCommands/xclip.md b/Linux_man_cn/xclip.md similarity index 100% rename from LinuxCommands/xclip.md rename to Linux_man_cn/xclip.md diff --git a/LinuxCommands/xfs_admin.md b/Linux_man_cn/xfs_admin.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/xfs_admin.md rename to Linux_man_cn/xfs_admin.md diff --git a/LinuxCommands/xfs_info.md b/Linux_man_cn/xfs_info.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/xfs_info.md rename to Linux_man_cn/xfs_info.md diff --git a/LinuxCommands/xfs_repair.md b/Linux_man_cn/xfs_repair.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/xfs_repair.md rename to Linux_man_cn/xfs_repair.md diff --git a/LinuxCommands/xfsdump.md b/Linux_man_cn/xfsdump.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/xfsdump.md rename to Linux_man_cn/xfsdump.md diff --git a/LinuxCommands/xfsrestore.md b/Linux_man_cn/xfsrestore.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/xfsrestore.md rename to Linux_man_cn/xfsrestore.md diff --git a/LinuxCommands/xhost.md b/Linux_man_cn/xhost.md similarity index 100% rename from LinuxCommands/xhost.md rename to Linux_man_cn/xhost.md diff --git a/LinuxCommands/xinit.md b/Linux_man_cn/xinit.md similarity index 100% rename from LinuxCommands/xinit.md rename to Linux_man_cn/xinit.md diff --git a/LinuxCommands/xlsatoms.md b/Linux_man_cn/xlsatoms.md similarity index 100% rename from LinuxCommands/xlsatoms.md rename to Linux_man_cn/xlsatoms.md diff --git a/LinuxCommands/xlsclients.md b/Linux_man_cn/xlsclients.md similarity index 100% rename from LinuxCommands/xlsclients.md rename to Linux_man_cn/xlsclients.md diff --git a/LinuxCommands/xlsfonts.md b/Linux_man_cn/xlsfonts.md similarity index 100% rename from LinuxCommands/xlsfonts.md rename to Linux_man_cn/xlsfonts.md diff --git a/LinuxCommands/xset.md b/Linux_man_cn/xset.md similarity index 100% rename from LinuxCommands/xset.md rename to Linux_man_cn/xset.md diff --git a/LinuxCommands/xz.md b/Linux_man_cn/xz.md old mode 100755 new mode 100644 similarity index 100% rename from LinuxCommands/xz.md rename to Linux_man_cn/xz.md diff --git a/LinuxCommands/yes.md b/Linux_man_cn/yes.md similarity index 100% rename from LinuxCommands/yes.md rename to Linux_man_cn/yes.md diff --git a/LinuxCommands/ypdomainname.md b/Linux_man_cn/ypdomainname.md similarity index 100% rename from LinuxCommands/ypdomainname.md rename to Linux_man_cn/ypdomainname.md diff --git a/LinuxCommands/yum.md b/Linux_man_cn/yum.md old mode 100755 new mode 100644 similarity index 96% rename from LinuxCommands/yum.md rename to Linux_man_cn/yum.md index 77c3c0e..847e13b --- a/LinuxCommands/yum.md +++ b/Linux_man_cn/yum.md @@ -1,106 +1,106 @@ -yum -=== - -基于RPM的软件包管理器 - -## 补充说明 - -**yum命令** 是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。 - -yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。 - -### 语法 - -``` -yum(选项)(参数) -``` - -### 选项 - -``` --h:显示帮助信息; --y:对所有的提问都回答“yes”; --c:指定配置文件; --q:安静模式; --v:详细模式; --d:设置调试等级(0-10); --e:设置错误等级(0-10); --R:设置yum处理一个命令的最大等待时间; --C:完全从缓存中运行,而不去下载或者更新任何头文件。 -``` - -### 参数 - -``` -install:安装rpm软件包; -update:更新rpm软件包; -check-update:检查是否有可用的更新rpm软件包; -remove:删除指定的rpm软件包; -list:显示软件包的信息; -search:检查软件包的信息; -info:显示指定的rpm软件包的描述信息和概要信息; -clean:清理yum过期的缓存; -shell:进入yum的shell提示符; -resolvedep:显示rpm软件包的依赖关系; -localinstall:安装本地的rpm软件包; -localupdate:显示本地rpm软件包进行更新; -deplist:显示rpm软件包的所有依赖关系。 -``` - -### 实例 - -部分常用的命令包括: - -* 自动搜索最快镜像插件:`yum install yum-fastestmirror` -* 安装yum图形窗口插件:`yum install yumex` -* 查看可能批量安装的列表:`yum grouplist` - -**安装** - -```bash -yum install #全部安装 -yum install package1 #安装指定的安装包package1 -yum groupinsall group1 #安装程序组group1 -``` - -**更新和升级** - -```bash -yum update #全部更新 -yum update package1 #更新指定程序包package1 -yum check-update #检查可更新的程序 -yum upgrade package1 #升级指定程序包package1 -yum groupupdate group1 #升级程序组group1 -``` - -**查找和显示** - -```bash -# 检查 MySQL 是否已安装 -yum list installed | grep mysql -yum list installed mysql* - -yum info package1 #显示安装包信息package1 -yum list #显示所有已经安装和可以安装的程序包 -yum list package1 #显示指定程序包安装情况package1 -yum groupinfo group1 #显示程序组group1信息yum search string 根据关键字string查找安装包 -``` - -**删除程序** - -```bash -yum remove | erase package1 #删除程序包package1 -yum groupremove group1 #删除程序组group1 -yum deplist package1 #查看程序package1依赖情况 -``` - -**清除缓存** - -```bash -yum clean packages #清除缓存目录下的软件包 -yum clean headers #清除缓存目录下的 headers -yum clean oldheaders #清除缓存目录下旧的 headers -``` - - - +yum +=== + +基于RPM的软件包管理器 + +## 补充说明 + +**yum命令** 是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。 + +yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。 + +### 语法 + +``` +yum(选项)(参数) +``` + +### 选项 + +``` +-h:显示帮助信息; +-y:对所有的提问都回答“yes”; +-c:指定配置文件; +-q:安静模式; +-v:详细模式; +-d:设置调试等级(0-10); +-e:设置错误等级(0-10); +-R:设置yum处理一个命令的最大等待时间; +-C:完全从缓存中运行,而不去下载或者更新任何头文件。 +``` + +### 参数 + +``` +install:安装rpm软件包; +update:更新rpm软件包; +check-update:检查是否有可用的更新rpm软件包; +remove:删除指定的rpm软件包; +list:显示软件包的信息; +search:检查软件包的信息; +info:显示指定的rpm软件包的描述信息和概要信息; +clean:清理yum过期的缓存; +shell:进入yum的shell提示符; +resolvedep:显示rpm软件包的依赖关系; +localinstall:安装本地的rpm软件包; +localupdate:显示本地rpm软件包进行更新; +deplist:显示rpm软件包的所有依赖关系。 +``` + +### 实例 + +部分常用的命令包括: + +* 自动搜索最快镜像插件:`yum install yum-fastestmirror` +* 安装yum图形窗口插件:`yum install yumex` +* 查看可能批量安装的列表:`yum grouplist` + +**安装** + +```bash +yum install #全部安装 +yum install package1 #安装指定的安装包package1 +yum groupinsall group1 #安装程序组group1 +``` + +**更新和升级** + +```bash +yum update #全部更新 +yum update package1 #更新指定程序包package1 +yum check-update #检查可更新的程序 +yum upgrade package1 #升级指定程序包package1 +yum groupupdate group1 #升级程序组group1 +``` + +**查找和显示** + +```bash +# 检查 MySQL 是否已安装 +yum list installed | grep mysql +yum list installed mysql* + +yum info package1 #显示安装包信息package1 +yum list #显示所有已经安装和可以安装的程序包 +yum list package1 #显示指定程序包安装情况package1 +yum groupinfo group1 #显示程序组group1信息yum search string 根据关键字string查找安装包 +``` + +**删除程序** + +```bash +yum remove | erase package1 #删除程序包package1 +yum groupremove group1 #删除程序组group1 +yum deplist package1 #查看程序package1依赖情况 +``` + +**清除缓存** + +```bash +yum clean packages #清除缓存目录下的软件包 +yum clean headers #清除缓存目录下的 headers +yum clean oldheaders #清除缓存目录下旧的 headers +``` + + + diff --git a/LinuxCommands/zcat.md b/Linux_man_cn/zcat.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/zcat.md rename to Linux_man_cn/zcat.md index 68f4dc2..5d4b92d --- a/LinuxCommands/zcat.md +++ b/Linux_man_cn/zcat.md @@ -1,6 +1,6 @@ zcat === - + 显示压缩包中文件的内容 ## 补充说明 diff --git a/LinuxCommands/zfore.md b/Linux_man_cn/zfore.md similarity index 100% rename from LinuxCommands/zfore.md rename to Linux_man_cn/zfore.md diff --git a/LinuxCommands/zip.md b/Linux_man_cn/zip.md old mode 100755 new mode 100644 similarity index 97% rename from LinuxCommands/zip.md rename to Linux_man_cn/zip.md index bf76019..4157ecd --- a/LinuxCommands/zip.md +++ b/Linux_man_cn/zip.md @@ -1,94 +1,94 @@ -zip -=== - -可以用来解压缩文件 - -## 补充说明 - -**zip命令** 可以用来解压缩文件,或者对文件进行打包操作。zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有“.zip”扩展名的压缩文件。 - -### 语法 - -``` -zip(选项)(参数) -``` - -### 选项 - -``` --A:调整可执行的自动解压缩文件; --b<工作目录>:指定暂时存放文件的目录; --c:替每个被压缩的文件加上注释; --d:从压缩文件内删除指定的文件; --D:压缩文件内不建立目录名称; --f:此参数的效果和指定“-u”参数类似,但不仅更新既有文件,如果某些文件原本不存在于压缩文件内,使用本参数会一并将其加入压缩文件中; --F:尝试修复已损坏的压缩文件; --g:将文件压缩后附加在已有的压缩文件之后,而非另行建立新的压缩文件; --h:在线帮助; --i<范本样式>:只压缩符合条件的文件; --j:只保存文件名称及其内容,而不存放任何目录名称; --J:删除压缩文件前面不必要的数据; --k:使用MS-DOS兼容格式的文件名称; --l:压缩文件时,把LF字符置换成LF+CR字符; --ll:压缩文件时,把LF+cp字符置换成LF字符; --L:显示版权信息; --m:将文件压缩并加入压缩文件后,删除原始文件,即把文件移到压缩文件中; --n<字尾字符串>:不压缩具有特定字尾字符串的文件; --o:以压缩文件内拥有最新更改时间的文件为准,将压缩文件的更改时间设成和该文件相同; --q:不显示指令执行过程; --r:递归处理,将指定目录下的所有文件和子目录一并处理; --S:包含系统和隐藏文件; --t<日期时间>:把压缩文件的日期设成指定的日期; --T:检查备份文件内的每个文件是否正确无误; --u:更换较新的文件到压缩文件内; --v:显示指令执行过程或显示版本信息; --V:保存VMS操作系统的文件属性; --w:在文件名称里假如版本编号,本参数仅在VMS操作系统下有效; --x<范本样式>:压缩时排除符合条件的文件; --X:不保存额外的文件属性; --y:直接保存符号连接,而非该链接所指向的文件,本参数仅在UNIX之类的系统下有效; --z:替压缩文件加上注释; --$:保存第一个被压缩文件所在磁盘的卷册名称; --<压缩效率>:压缩效率是一个介于1~9的数值。 -``` - -### 参数 - -* zip压缩包:指定要创建的zip压缩包; -* 文件列表:指定要压缩的文件列表。 - -### 实例 - -将`/home/Blinux/html/`这个目录下所有文件和文件夹打包为当前目录下的html.zip: - -``` -zip -q -r html.zip /home/Blinux/html -``` - -上面的命令操作是将绝对地址的文件及文件夹进行压缩,以下给出压缩相对路径目录,比如目前在Bliux这个目录下,执行以下操作可以达到以上同样的效果: - -``` -zip -q -r html.zip html -``` - -比如现在我的html目录下,我操作的zip压缩命令是: - -``` -zip -q -r html.zip * -``` - -### 问题解决 - -CentOS7中命令找不到 - -``` --Bash: Unzip: Command Not Found -``` - -解决方法 - -```bash -yum install -y unzip zip -``` - - +zip +=== + +可以用来解压缩文件 + +## 补充说明 + +**zip命令** 可以用来解压缩文件,或者对文件进行打包操作。zip是个使用广泛的压缩程序,文件经它压缩后会另外产生具有“.zip”扩展名的压缩文件。 + +### 语法 + +``` +zip(选项)(参数) +``` + +### 选项 + +``` +-A:调整可执行的自动解压缩文件; +-b<工作目录>:指定暂时存放文件的目录; +-c:替每个被压缩的文件加上注释; +-d:从压缩文件内删除指定的文件; +-D:压缩文件内不建立目录名称; +-f:此参数的效果和指定“-u”参数类似,但不仅更新既有文件,如果某些文件原本不存在于压缩文件内,使用本参数会一并将其加入压缩文件中; +-F:尝试修复已损坏的压缩文件; +-g:将文件压缩后附加在已有的压缩文件之后,而非另行建立新的压缩文件; +-h:在线帮助; +-i<范本样式>:只压缩符合条件的文件; +-j:只保存文件名称及其内容,而不存放任何目录名称; +-J:删除压缩文件前面不必要的数据; +-k:使用MS-DOS兼容格式的文件名称; +-l:压缩文件时,把LF字符置换成LF+CR字符; +-ll:压缩文件时,把LF+cp字符置换成LF字符; +-L:显示版权信息; +-m:将文件压缩并加入压缩文件后,删除原始文件,即把文件移到压缩文件中; +-n<字尾字符串>:不压缩具有特定字尾字符串的文件; +-o:以压缩文件内拥有最新更改时间的文件为准,将压缩文件的更改时间设成和该文件相同; +-q:不显示指令执行过程; +-r:递归处理,将指定目录下的所有文件和子目录一并处理; +-S:包含系统和隐藏文件; +-t<日期时间>:把压缩文件的日期设成指定的日期; +-T:检查备份文件内的每个文件是否正确无误; +-u:更换较新的文件到压缩文件内; +-v:显示指令执行过程或显示版本信息; +-V:保存VMS操作系统的文件属性; +-w:在文件名称里假如版本编号,本参数仅在VMS操作系统下有效; +-x<范本样式>:压缩时排除符合条件的文件; +-X:不保存额外的文件属性; +-y:直接保存符号连接,而非该链接所指向的文件,本参数仅在UNIX之类的系统下有效; +-z:替压缩文件加上注释; +-$:保存第一个被压缩文件所在磁盘的卷册名称; +-<压缩效率>:压缩效率是一个介于1~9的数值。 +``` + +### 参数 + +* zip压缩包:指定要创建的zip压缩包; +* 文件列表:指定要压缩的文件列表。 + +### 实例 + +将`/home/Blinux/html/`这个目录下所有文件和文件夹打包为当前目录下的html.zip: + +``` +zip -q -r html.zip /home/Blinux/html +``` + +上面的命令操作是将绝对地址的文件及文件夹进行压缩,以下给出压缩相对路径目录,比如目前在Bliux这个目录下,执行以下操作可以达到以上同样的效果: + +``` +zip -q -r html.zip html +``` + +比如现在我的html目录下,我操作的zip压缩命令是: + +``` +zip -q -r html.zip * +``` + +### 问题解决 + +CentOS7中命令找不到 + +``` +-Bash: Unzip: Command Not Found +``` + +解决方法 + +```bash +yum install -y unzip zip +``` + + diff --git a/LinuxCommands/zipinfo.md b/Linux_man_cn/zipinfo.md old mode 100755 new mode 100644 similarity index 98% rename from LinuxCommands/zipinfo.md rename to Linux_man_cn/zipinfo.md index d54c43b..5747e96 --- a/LinuxCommands/zipinfo.md +++ b/Linux_man_cn/zipinfo.md @@ -1,6 +1,6 @@ zipinfo === - + 用来列出压缩文件信息 ## 补充说明 diff --git a/LinuxCommands/zipsplit.md b/Linux_man_cn/zipsplit.md similarity index 100% rename from LinuxCommands/zipsplit.md rename to Linux_man_cn/zipsplit.md diff --git a/LinuxCommands/znew.md b/Linux_man_cn/znew.md similarity index 100% rename from LinuxCommands/znew.md rename to Linux_man_cn/znew.md