Linux零基础急速入门_第1页
Linux零基础急速入门_第2页
Linux零基础急速入门_第3页
Linux零基础急速入门_第4页
Linux零基础急速入门_第5页
已阅读5页,还剩70页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Linux零基础急速入门第1看,[root@cloudcs~~#井子符号:代表当前用户为本地超管UID=0(用户名为$符号:代表普通用户UID不为0注意:linuxUIDuserid0谁就是老大,你名字叫不叫root都没所谓。[root@cloudcs~]#useradd[root@cloudcs~]#echoredhat|passwd--stdinhenryChangingpasswordforuserhenry.passwd:allauthenticationtokensupdatedsuccessfully.[root@cloudcs~]#grep-E"root|henry"/etc/passwd[root@cloudcs~]#vi/etc/passwd[root@cloudcs~]#grep-E"root|henry"/etc/passwd[root@cloudcs/]$su-henryLastlogin:ThuMay2517:00:43CST2023onpts/0[henry@cloudcs~]#使用init0[root@cloudcs~]#init使用poweroff[root@cloudcs~]#使用shutdown-hnow执行关机[root@cloudcs~]#shutdown-hshutdown-h5执行5分钟后关机[root@cloudcs~]#shutdown-hShutdownscheduledforSun2023-04-2810:33:16CST,use'shutdown-c'toshutdown-c执行取消关机[root@cloudcs~]#shutdown-使用init6[root@cloudcs~]#init使用reboot[root@cloudcs~]#使用shutdown-rnow执行重启[root@cloudcs~]#shutdown-rshutdown-r5执行5分钟后重启[root@cloudcs~]#shutdown-rShutdownscheduledforSun2023-04-2810:38:56CST,use'shutdown-c'toshutdown-c执行取消重启[root@cloudcs~]#shutdown-CD进入根目录[root@cloudcs~cd[root@cloudcs/]#mnt[root@cloudcs/]#cd/mnt/[root@cloudcsmnt]#tmp[root@cloudcsmnt]#cd/tmp/[root@cloudcstmp]#etc[root@cloudcstmp]#cd/etc/[root@cloudcsetc]#etc目录下面的sysconfig目录下面的network-[root@cloudcsetc]#cd/etc/sysconfig/network-scripts/[root@cloudcsnetwork-scripts]#[root@cloudcsnetwork-scripts]#cd-bash:cd:/etc/passwd:Notadirectory<哥们儿!能不能好好看看提示的是啥?[root@cloudcsnetwork-scripts]#cd/etc/shadow-bash:cd:/etc/shadow:Notacd..返回上一级目录etc目录下面的sysconfig目录下面的network-[root@cloudcs~]#cd/etc/sysconfig/network-scripts/[root@cloudcsnetwork-scripts]#cd[root@cloudcsnetwork-scripts]#cd..[root@cloudcssysconfig]#cd..[root@cloudcsetc]#cd..[root@cloudcs/]#mnt[root@cloudcs/]#cd/mnt/[root@cloudcsmnt]#tmp[root@cloudcsmnt]#cd/tmp/[root@cloudcstmp]#cd[root@cloudcstmp]#cd[root@cloudcsmnt]#cd[root@cloudcstmp]#cd不管在哪个目录中,直接cd[root@cloudcs~cd/etc/sysconfig/network-scripts/[root@cloudcsnetwork-scripts]#cd[root@cloudcsLS[root@cloudcs~]#lsbinbootdevetchomeliblib64mediamntoptprocrootrunsbinsrvsystmpusrtmp[root@cloudcs~]#lsvmware-root_929-3980167385vmware-root_973-ls5lathr)ls-l以长模式显示[root@cloudcs~]#ls-l/total20lrwxrwxrwx.1rootroot7Jun222021bin->dr-xr-xr-x.5rootroot4096Mar1319:33drwxr-xr-x.20rootroot3180May2514:08[root@cloudcs~]#ll/total20lrwxrwxrwx.1rootroot7Jun222021bin->dr-xr-xr-x.5rootroot4096Mar1319:33drwxr-xr-x.20rootroot3180May2514:08[root@cloudcs~]#ls-latotal32dr-xr-x.2rootroot151May2514:18dr-xr-xr-x.17rootroot224Mar1319:31-rw.1rootroot1069Mar1319:35anaconda--rw.1rootroot764May2517:00-rw-r--r--.1rootroot18May112019-rwxr-xr-x.1rootroot51May2514:18-rw-r--r--.1rootroot129May112019显示家目录内容[root@cloudcs~lslattotal32-rw.1rootroot764May2517:00dr-xr-x.2rootroot151May2514:18-rwxr-xr-x.1rootroot51May2514:18-rw.1rootroot1069Mar1319:35anaconda-dr-xr-xr-x.17rootroot224Mar1319:31-rw-r--r--.1rootroot18May112019[root@cloudcs~]#ls-latrtotal32-rw-r--r--.1rootroot129May112019-rw-r--r--.1rootroot100May112019-rw-r--r--.1rootroot176May112019-rw-r--r--.1rootroot176May112019-rw-r--r--.1rootroot18May112019dr-xr-xr-x.17rootroot224Mar1319:31-rw.1rootroot1069Mar1319:35anaconda--rwxr-xr-x.1rootroot51May2514:18dr-xr-x.2rootroot151May2514:18-rw.1rootroot764May2517:00[root@cloudcs~]#ls-lathrtotal32K-rw-r--r--.1rootroot129May112019-rw-r--r--.1rootroot100May112019-rw-r--r--.1rootroot176May112019-rw-r--r--.1rootroot176May112019-rw-r--r--.1rootroot18May112019dr-xr-xr-x.17rootroot224Mar1319:31-rw.1rootroot1.1KMar1319:35anaconda--rwxr-xr-x.1rootroot51May2514:18dr-xr-x.2rootroot151May2514:18-rw.1rootroot764May2517:00PWD[root@cloudcsnetwork-scripts]#[root@cloudcsnetwork-scripts]#cd/tmp/[root@cloudcstmp]#pwdPASSWDpasswd[root@cloudcs~]#passwdhenryChangingpasswordforuserhenry.Newpassword:新密码BADPASSWORD:Thepasswordfailsthedictionarycheck-itdoesnotcontainenoughDIFFERENTcharactersRetypenewpassword:passwd:allauthenticationtokensupdatedsuccessfully.[root@cloudcs~]#echoHuawei12#$|passwd--stdinhenryChangingpasswordforuserpasswd:allauthenticationtokensupdatedCAT[root@cloudcs~]#catlocalhostlocalhost.localdomainlocalhost4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6[root@cloudcs~]#cat/etc/passwd[root@cloudcs~]#catcat:/etc/selinux/:IsaTOUCH[root@cloudcs~]#touchabc[root@cloudcs~]#touchabc1abc2abc3[root@cloudcs~]#touchHOSTNAMECTL[root@cloudcs~]#hostnamectlset-hostnameVIM(重要[root@cloudcs~]#viiINSERT输入:wq:x:q!:wq:x只有内容发生变化才会更新yy命令进行复制(仅复制光标所在行在命令行模式下执行p命令进行粘贴(会在光标所在行的下一行进行粘贴5yy命令进行复制(复制光标所在行及下面4行udd命令进行删除(仅删除光标所在行5dd命令进行复制(删除光标所在行及下面4行ggShift+go在命令行模式下执行:setnu在命令行模式下执行:setnonu在命令行模式下执行:1,2m3命令把1到2行剪切到第3在命令行模式下执行/abc命令进行abcn命令显示下一个(配合/搜索使用Shift+n命令显示上一个(配合/搜索使用在命令行模式下执行:s/123/666/g命令将光标所在行的123替换为在命令行模式下执行:%s/666/888/gc命令将当前整个文件的666替换为E486:Patternnotfound:MKDIRmkdir[root@cloudcs~]#cd/[root@cloudcsmkdirabc[root@cloudcs/]#lsabcbootetclibmediaoptrootsbinsysusrbindevhomelib64mntprocrunsrvtmpvar[root@cloudcs/]#mkdirmkdir:cannotcreatedirectory‘abc/bbb/ccc/ddd’:Nosuchfileordirectory[root@cloudcs/]#mkdir-pabc/bbb/ccc/dddCPcp[root@cloudcscpaaa/tmp/[root@cloudcs/]#ls/tmp/aaa[root@cloudcs/]#cpabc/cp:-rnotspecified;omittingdirectory'abc/'[root@cloudcs/]#cp-rabc//tmp/[root@cloudcs/]#ls[root@cloudcs/]#cp-aaaaMV[root@cloudcs/]#mvabc//mnt/[root@cloudcs/]#mv/mnt/abc//mnt/bbb[root@cloudcs/]#ls/mnt/bbb[root@cloudcs/]#mvaaaccc[root@cloudcs/]#mvccc/tmp/MOUNT将光盘挂载到根下的mnt目录里[root@cloudcs~mount/dev/cdrom/mnt[root@cloudcs~]#mount/dev/sr0/mnt/把某个分区挂载到根下面的abc[root@cloudcs~]#mount/dev/sdb1RPM[root@cloudcs~]#rpm-ivhgcc-c++-4.8.3--i:install-v:verbose-h:humanbinTAR[root@cloudcs~]#tar-cvfaaa.tara1a2a3[root@cloudcs~]#tar-cvfa2.taraaa-c:create-v:verbose-f:filetar(.tar格式)[root@cloudcs~tarxvfaaa.tar-x:extract-v:verbose-f:filetar(.tar.gz格式)[root@cloudcs~tarzcvfaaa.tar.gzaaatar(.tar.gz格式)[root@cloudcs~tarzxvfaaa.tar.gztar(.bzipbzip2格式)[root@cloudcs~tarjcvfaaa.bzip2a1a2a3[root@cloudcs~tar-jxvfaaa.bzip2ZIP[root@cloudcs~]#zipabc.zipa1a2a3adding:a1(stored0%)adding:a2(stored0%)adding:a3(stored0%)unzip[root@cloudcs~]#unzipMAN[root@cloudcs~]#manmv[root@cloudcs~]#man\h第2Linux70halt0,否则电脑一开机1SingleusermoderootWindows2Multiuser,withoutNFS3FullMultiusermode24unused5X11X-Window6Reboot6,否则电脑一开机就进入重启模式会一直不ServerwithGUI5init3init5命令进行运行级别的切换。[root@henry~]#cat/etc/inittab#inittabisnolongerused.#ADDINGCONFIGURATIONHEREWILLHAVENOEFFECTONYOUR#Ctrl-Alt-Deleteishandledby/usr/lib/systemd/system/ctrl-alt-#systemduses'targets'insteadofrunlevels.Bydefault,therearetwomain#multi-user.target:analogoustorunlevel3#graphical.target:analogoustorunlevel5#Toviewcurrentdefaulttarget,run:#systemctlget-#Tosetadefaulttarget,#systemctlset-default系统用户1<=UID<=999,一般都是由程序创建,用于程序或者服务运行时候[root@henry~]#vim/etc/login.defsLinux用户创建:useradd用户查看:id用户切换:su用户删除:userdelr[root@henry~]#compgenu[root@henry~]#compgen-[root@henry~]#[root@henry~]#iduid=1000(henry)gid=1000(henry)groups=1000(henry)[root@henry~]#usermod-groothenry[root@henry~]#iduid=1000(henry)gid=0(root)groups=0(root)[root@henry~]#usermod-ghenryhenry[root@henry~]#idhenryuid=1000(henry)gid=1000(henry)groups=1000(henry)[root@henry~]#idrootuid=0(root)gid=0(root)groups=0(root)[root@henry~]#usermod-a-Ghenryroot[root@henry~]#idrootuid=0(root)gid=0(root)groups=0(root),1000(henry)[root@henry~]#gpasswd-droothenryRemovinguserrootfromgrouphenry[root@henry~]#idrootuid=0(root)gid=0(root)读权限read对于文件,用户可以读取内容;对于目录,用户可以针对目录里面的内容进行列表操作写权限wGroup(G):文件或目录的所属组[root@henry~]#ll-rw-r--r--.1rootroot0May2920:12aaa.txt[root@henry~]#chmodu=rwx,g=r-x,o=rwxaaa.txt[root@henry~]#llaaa.txt-rwxr--rwx.1rootroot0May2920:12[root@henry~]#chmodo-waaa.txt[root@henry~]#llaaa.txt-rwxr--r-x.1rootroot0May2920:12aaa.txt[root@henry~]#chmodg+xaaa.txt[root@henry~]#ll-rwxr-xr-x.1rootroot0May2920:12aaa.txtchown修改角色[root@henry~]#chownhenryaaa.txt[root@henry~]#llaaa.txt-rwxr-xr-x.1henryroot0May2920:12aaa.txt[root@henry~]#chown:rootaaa.txt[root@henry~]#chown.rootaaa.txt[root@henry~]#llaaa.txt-rwxr-xr-x.1henryroot0May2920:12aaa.txt[root@henry~]#chownroot:rootaaa.txt[root@henry~]#llaaa.txt-rwxr-xr-x.1rootroot0May2920:12aaa.txtchgrp修改用户组[root@henry~]#chgrphenryaaa.txt[root@henry~]#llaaa.txt-rwxr-xr-x.1roothenry0May2920:12inode硬链接(Hardlink)inode文件的访问可以通过多个文件名进行。与之相对的,还有一种软链接(Symboliclink),它[root@henryhehe]#lnaaa.txt/tmp/aaaaa.txt[root@henryhehe]#ls-litotal34795765drwxr-xr-x.3rootroot17May2921:1767744770-rw-r--r--.2rootroot0May3015:27aaa.txt[root@henryhehe]#ls-li/tmp/aaaaa.txt67744770-rw-r--r--.2rootroot0May3015:27/tmp/aaaaa.txt[root@henry~]#ln-shehehehe_linkrwx:执行权限为10:---1:--2:-w-3:-wx4:r-5:r-x6:rw-7:rwuser/group/other[root@henry~]#chmod644aaa.txt[root@henry~]#chmod777aaa.txt[root@henry~]#chmod-R777hehehe第3章YUMYUM(全称为YellowdogUpdater,Modified)是一个在Fedora和RedHat以及CentOS中的ShellRPMRPM系统默认安装好之后,会在/etc/yum.repos.drepo[root@henry~]#lsCentOS-Stream-AppStream.repoCentOS-Stream-Media.repoCentOS-Stream-BaseOS.repoCentOS-Stream-NFV.repoCentOS-Stream-Debuginfo.repoCentOS-Stream-PowerTools.repoCentOS-Stream-Extras-common.repoCentOS-Stream-RealTime.repoCentOS-Stream-Extras.repoCentOS-Stream-ResilientStorage.repoCentOS-Stream-HighAvailability.repoCentOS-Stream-yum[root@henry~]#cd/etc/yum.repos.d/[root@henryyum.repos.d]#mkdirbak[root@henryyum.repos.d]#mv*.repobak/[root@henryyum.repos.d]#vimhenry.repo[root@henryyum.repos.d]#cathenry.reponame=baseurl=file:///mnt/BaseOSgpgcheck=0name=appbaseurl=file:///mnt/AppStreamgpgcheck=0[root@henryyum.repos.d]#yumclean29files[root@henryyum.repos.d]#yumrepolistallrepoidreponamestatusappappenabledososenable[root@henryyum.repos.d]#mount/dev/cdrommount:/mnt:WARNING:devicewrite-protected,mountedread-only.[root@henryyum.repos.d]#yuminstallreadline*[root@henryyum.repos.d]#yuminstallreadline*os0.0B/s|0B00:00Errorsduringdownloadingmetadataforrepository-Curlerror(37):Couldn'treadafile://fileforfile:///mnt/BaseOS/repodata/repomd.xml[Couldn'topenfileError:Failedtodownloadmetadataforrepo'os':Cannotdownloadrepomd.xml:Cannotdownloadrepodata/repomd.xml:Allmirrorsweretried\h阿里源|\h华为源第4/sys:linux2.62.6系统sysfs。sysfs3procdevfsdevpts/devDeviceLinuxLinux/mediawindowsUlinux该被删掉或清除。如果你的系统上有/var/run目录,应该让它指向run。/usr:windowsprogramfiles目录下第5章LVMLVMlvmLinuxLVMLVM使用LVM管理磁盘空间的主要优点是,它可以帮助管理员更好地利用硬盘空间,而无需在不LVM因此,为了更好地解决硬盘空间的管理问题,LVM作而不需要对数据进行备份和恢复,从而实现了更灵活和可靠的磁盘空间管理。此外,LVMLVLinux:OracleEnterpriseLinux(OEL[root@oel8202[root@oel8202~]#fdisk-[root@oel8202~]#fdiskWelcometofdisk(util-linuxChangeswillremaininmemoryonly,untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.Devicedoesnotcontainarecognizedpartitiontable.CreatedanewDOSdisklabelwithdiskidentifier0xdd4fd772.Command(mforhelp):nPartitiontype primary(0primary,0extended,4 extended(containerforlogicalpartitions)Select(defaultp):Usingdefaultresponsep.Partitionnumber(1-4,default1):Firstsector(2048-41943039,defaultLastsector,+sectorsor+size{K,M,G,T,P}(2048-41943039,default41943039):Createdanewpartition1oftype'Linux'andofsize5Command(mforhelp):tSelectedpartition1Hexcode(typeLtolistallcodes):Changedtypeofpartition'Linux'to'LinuxCommand(mforhelp):Disk/dev/nvme0n2:20GiB,21474836480bytes,41943040Units:sectorsof1*512=512Sectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:BootEndSectorsSizeId204810487807 5G8eLinuxCommand(mforhelp):Thepartitiontablehasbeenaltered.Callingioctl()tore-readpartitiontable.Syncingdisks.[root@oel8202[root@oel8202~]#fdisk-Disk/dev/nvme0n1:50GiB,53687091200bytes,104857600Units:sectorsof1*512=512Sectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:Disk/dev/nvme0n2:20GiB,21474836480bytes,41943040Units:sectorsof1*512=512Sectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:BootEndSectorsSizeId204810487807 5G8eLinuxswap/创建物理卷[root@oel8202[root@oel8202~]#pvcreatePhysicalvolume"/dev/nvme0n2p1"successfully lvm25.00gVGFmtAttrPSize[root@oel8202~]#PVAllocatedFreeTotalPE5.00VGPVPV[root@oel8202~]#"/dev/nvme0n2p1"isanewphysicalvolumeof"5.00NEWPhysicalvolume--创建卷组[root@oel8202[root@oel8202~]#vgcreatevg1/dev/nvme0n2p1Volumegroup"vg1"successfullycreatedCurActVG<5.00PE4.00TotalAllocPE/0/FreePE/1279/<5.00VG[root@oel8202~]#VG#PV#LV#SNAttr VSizeVFree 0wz--n-<5.00g<5.00g[root@oel8202~]#Volumegroup--VGSystemMetadataMetadataSequenceNoVGMaxVGMAXCurOpen创建逻辑卷[root@oel8202[root@oel8202~]#lvcreate-L+500M-nlv1vg1Logicalvolume"lv1"created.LVLV500.00CurrentReadahead-currentlysetBlock[root@oel8202~]# VGAttr PoolOriginData%Meta%MoveLogCpy%SyncConvertlv1vg1-wi-a500.00m#LVLVCreationhost,timeoel8202,2022-01-3020:54:29LVWriteLVVGLVLV[root@oel8202~]#Logicalvolume--[root@oel8202~]#agcount=4,agsize=32000attr=2,finobt=1,sparse=1, blocks=128000,swidth=0=versionascii-ci=0,=internalblocks=1368,sunit=0blks,lazy-blocks=0,[root@oel8202[root@oel8202~]#mkdirMounted[root@oel8202[root@oel8202~]#mount/dev/vg1/lv1[root@oel8202~]#df-/dev/mapper/vg1-lv1 29M 6%[root@oel8202[root@oel8202~]#blkid/dev/vg1/lv1:UUID="d8ea8946-c4ee-4423-8114-896e455bb201"TYPE="xfs"[root@oel8202~]#vim/etc/fstab[root@oel8202~]#cat###CreatedbyanacondaonSunOct1021:50:50#Accessiblefilesystems,byreference,aremaintainedunder#Seemanpagesfstab(5),findfs(8),mount(8)and/orblkid(8)formoreinfo.#Aftereditingthisfile,run'systemctldaemon-reload'toupdatesystemd#unitsgeneratedfromthisfile.00 0UUID=d8ea8946-c4ee-4423-8114-896e455bb201/data1 00[root@oel8202~]#mount-aLV[root@oel8202[root@oel8202~]# VGAttr PoolOriginData%Meta%MoveLogCpy%SyncConvertlv1vg1-wi-ao500.00m[root@oel8202~]#lvextend-L+500MSizeoflogicalvolumevg1/lv1changedfrom500.00MiB(125extents)to1000.00MiB(250Logicalvolumevg1/lv1successfully[root@oel8202~]#xfs_growfs agcount=4,agsize=32000 attr=2, finobt=1,sparse=1, blocks=128000, swidth=0blks =version2 ascii-ci=0,ftype=1 =internal blocks=1368, sunit=0blks,lazy-count=1realtime=none blocks=0,rtextents=0datablockschangedfrom128000to[root@oel8202~]#df- Mounted /dev/mapper/vg1-lv1 33M 4%[root@oel8202~]# VGAttr PoolOriginData%Meta%MoveLogCpy%SyncConvertlv1vg1-wi-ao1000.00mVG[root@oel8202~]#fdiskWelcometofdisk(util-linuxChangeswillremaininmemoryonly,untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.Command(mforhelp):Disk/dev/nvme0n2:20GiB,21474836480bytes,41943040Units:sectorsof1*512=512Sectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier: Boot EndSectorsSizeId 204810487807 5G8eLinuxCommand(mforhelp):nPartitiontype primary(1primary,0extended,3 extended(containerforlogicalpartitions)Select(defaultp):Usingdefaultresponsep.Partitionnumber(2-4,default2):Firstsector(10487808-41943039,defaultLastsector,+sectorsor+size{K,M,G,T,P}(10487808-41943039,default41943039):Createdanewpartition2oftype'Linux'andofsize10TheThepartitiontablehasbeenSyncingCommand(mforhelp):10487808314593272097152010G8eLinux204810487807 5G8eLinuxEndSectorsSizeId Command(mforhelp):Disk/dev/nvme0n2:20GiB,21474836480bytes,41943040Units:sectorsof1*512=512Sectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:Changedtypeofpartition'Linux'to'LinuxCommand(mforhelp):Partitionnumber(1,2,defaultHexcode(typeLtolistallcodes):[root@oel8202~]#partprobe[root@oel8202~]#partprobe[root@oel8202~]#MAJ:MINRMSIZEROTYPE 20G01000part0part0part├─├─nvme0n2p2└─nvme0n2p1└─vg1-lv1 0000lvm创建PV[root@oel8202[root@oel8202~]#pvcreatePhysicalvolume"/dev/nvme0n2p2"successfully扩展VG[root@oel8202[root@oel8202~]#vgextendvg1/dev/nvme0n2p2Volumegroup"vg1"successfullyextended查看VG[root@oel8202[root@oel8202~]#Volumegroup--VGSystemMetadataMetadataSequenceNoVGVGMAXCurOpenMaxCurActVG14.99[root@oel8202[root@oel8202~]#VG#PV#LV#SNAttr VSizeVFree 0wz--n-14.99g<14.02gVG3588/<14.02FreePE/250/1000.00AllocPE/Total4.00PE第6第7章SHELL重定向输入输出:cat<<EOF>/tmp/abc.txt这个EOFcat<<MEMEDA>a.txtecho12345>echo12345>>--stdin--stdinecho12345|passwd--stdin||ls|grep"txt"grep1a.txtifconfig|grepinet&&&&ls&&ls-laa&&ls-||||aa||ls-[root@gausspri~]#[-d/abc][root@gausspri~]#echo$?[root@gausspri~]#lsbinbootdevetchomeliblib64mediamntoptprocrootrunsbinsrvsystmpusr[root@gausspri~]#[-d/bin][root@gausspri~]#echo$?[-f/abc.txt]||touch[-f/abc.txt]||touch/abc.txt&&lsegrep/grep过滤egrep"(henry|root)"cat/etc/passwd|grep-E"(operator|root)"grep-E"(operator|root)"/etc/passwdgrep-v"^#"grep-v"^#"/etc/passwd|grep-v"^$"cat/etc/passwd|grep-Ev"(^#|^$)"egrep-v"(^#|^$)"/etc/passwdfindfind/-nameecho$变量名称[root@gausspri~]#[root@gausspri~]#echo$aexport[root@gausspri~]#a=1[root@gausspri~]#echo$a[root@gausspri~]#exportb=666[root@gausspri~]#bash[root@gausspri~]#echo$a[root@gausspri~]#echo$b[root@gausspri~]#vim.bashrc[root@gausspri~]#vim.bash_profile[root@gausspri~]#env[root@gausspri~]#echo$b[root@gausspri~]#unsetb[root@gausspri~]#echo了解[root@gausspri~]#echo[root@gausspri~]#find/-name[root@gausspri~]#/usr/sbin/fdisk-l[root@gausspri~]#fdisk-l自定义$PATH[root@gausspri~]#vimabc.sh[root@gausspri~]#catabc.shecho"helloworld!"[root@gausspri~]#chmod+xabc.sh[root@gausspri~]#llabc.sh-rwxr-xr-x1rootroot32Jun614:24abc.sh[root@gausspri~]#abc.sh-bash:abc.sh:commandnotfound[root@gausspri~]#pwd[root@gausspri~]#PATH=$PATH:/root[root@gausspri~]#abc.shhelloworld![root@gausspri~]#IF[-d/rootf/etc/passwd[$NAME=='test']:判断变量echo$?00ifthenifcondition1condition1[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shif[$NAME=='aaa']echo$NAME[root@gausspri~]#shabc1.sh[root@gausspri~]#echo$?[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shif[$NAME=='abc']echo$NAME[root@gausspri~]#shabc1.shifelsethen,elseif1[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shif[$NAME=='abc1']echo$NAMEecho"error"[root@gausspri~]#shifelifelseelifif1123[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shif[$NAME=='abc1'];thenecho$NAMEelif[$NAME=='abc2'];thenecho"mynameis$NAME"elif[$NAME=='abc3'];thenecho"mynameis$NAME"echo"error"[root@gausspri~]#shabc1.sh-eq-lt-gtmantest来查看[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shif[$NAME=='abc'];thenecho$NAMEif[$AGE-lt30];thenecho"$AGE<30"echo"$AGE>=30"[root@gausspri~]#shabc1.sh20<CASEcaseLinuxshell[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shecho"Pleaseinputnum1-readnumcase$numinechoechoechoechoechoechoechoecho"Error!Pleaseinputnum1-7[root@gausspri~]#shabc1.shPleaseinputnum1-7:case的数字不在1-7范围内,则会输出错误提示信息。FORforiin123echo$i[root@gausspri~]#vimabc1.sh[root@gausspri~]#catforiin123echo$i[root@gausspri~]#shabc1.sh[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shfordirin/etc/tmp/mnttouch$dir/hehe.txtls-l$dir/hehe.txt[root@gausspri~]#sh-rw-r--r--1rootroot0Jun615:52-rw-r--r--1rootroot0Jun615:52-rw-r--r--1rootroot0Jun615:52forLinuxshell[root@gausspri~]#mkdirabc[root@gausspri~]#touchabcabc/abc1.shabc.sh[root@gausspri~]#touchabc/{a,b,c}{1,2,3}.txt[root@gausspri~]#lsabc/a1.txta2.txta3.txtb1.txtb2.txtb3.txtc1.txtc2.txt[root@gausspri~]#vimabc1.sh[root@gausspri~]#catabc1.shecho"Pleaseinputdirectoryname:"readpathecho"Pleaseinputprefix:"readprefixforfilein$(ls$path/)if[-f"$path/$file"]mv"$path/$file"echo"rename$path/$fileis$path/$prefix$file."echo"Rename[root@gausspri~]#shabc1.shPleaseinputdirectoryname:Pleaseinputrename/abc/a1.txtis/abc/hehea1.txt.rename/abc/a2.txtis/abc/hehea2.txt.rename/abc/a3.txtis/abc/hehea3.txt.rename/abc/b1.txtis/abc/heheb1.txt.rename/abc/b2.txtis/abc/heheb2.txt.rename/abc/b3.txtis/abc/heheb3.txt.rename/abc/c1.txtis/abc/hehec1.txt.rename/abc/c2.txtis/abc/hehec2.txt.rename/abc/c3.txtis/abc/hehec3.txt.Renamecompleted!脚本会先要求用户输入要重命名的文件夹路径和要添加的前缀,然后使用for循环遍历该文mvforLinuxshell[root@gausspri~]#vimbbb.sh[root@gausspri~]#catbbb.shforiin{1..9}forjin{1..9}if[$j-le$i]echo-n"$j*$i=$((j*i))"echo""[root@gausspri~]#shbbb.sh1*2=21*3=32*3=61*4=42*4=83*4=121*5=52*5=103*5=154*5=201*6=62*6=123*6=184*6=245*6=301*7=72*7=143*7=214*7=285*7=356*7=421*8=82*8=163*8=244*8=325*8=406*8=487*8=561*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=72脚本使用两个嵌套的for循环,外层循环控制乘法表的行数,内层循环控制列数。其中,为echoWHILEwhileLinuxshell1-100while[root@gausspri~]#vimwhile.sh[root@gausspri~]#catwhile.shechoecho"Pleaseinputnumbetween1-100:"while[$guess-ne$num]readif[$guess-lt$num]echo"small...again"elif[$guess-gt$num]echo"bigger...again"echo"Congratulations!"echo"GuessLinuxshell,$RANDOM0-32767为了得到1-100之间的随机整数,可以使用$RANDOM%100+1的表达式,该表达式会先将$RANDOM1000-991100[root@gausspri~]#shPleaseinputnumbetween1-GuessTimes:5AWKawk是一种文本处理工具,可以用于对文本文件进行处理、分析和格式化输出。它最初是由AlfredAho、PeterWeinbergerBrianKernighan1977awk(pattern)和动作(action)来对文本进行处理。模式用于匹配文本中的某些部分,动作用于对匹配到的部分进行处理。awk命令的基本语法如下:awk'pattern{action}'其中,patternaction,filenamepatternawkactionpattern,awkaction行内容用$0print。awk‘{print$n}’mynameishenryawknamename$2[root@gausspri~]#echo"myna

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论