linux-bash手册

    技术2026-02-28  8

    bash手册

    一、man帮助

    #man命令详解 [root@172-0-0-2 ~]$ man man NAME man - an interface to the on-line reference manuals ------------------------------------------------------------------------- 1. Name #显示命令名和一段简短的描述 2. Synopsis #命令的语法 3. Configuration #命令的配置信息 4. Description #命令的一般性描述 5. Options #命令选项描述 6. Exit Status #命令的退出状态指示 7. Return Value #命令的返回值 8. Errors #命令的错误消息 9. Environment #描述所使用的环境变量 10.Files #命令用到的文件 11.Versions #命令的版本信息 12.Conforming TO #命令所遵从的标准 13.Notes #其他有帮助的资料 14.Bugs #提供提交BUG的途径 15.Example #展示命令的用法 16.Authors #命令开发人员的信息 17.Copyright #命令源代码的版本信息 18.See Also #与该命令类似的其他命令 ------------------------------------------------------------------------ 总结:不记得命令名怎么办?可以使用关键字搜素手册页。语法:man -k 关键字 ------------------------------------------------------------------------ 区域号 所涵盖的内容 ------------------------------------------------------------------------ 1 #可执行程序或shell命令 2 #系统调用 3 #库调用 4 #特殊文件 5 #文件格式与约定 6 #游戏 7 #概览、约定及杂项 8 #超级用户和系统管理员命令 9 #内核例程 #man工具通常提供的是命令所对应的最低编号内容。对手册页中的第一部而已,就是输入man 1 hostname 。对于手册页中的第7部分,就是输入man 7 hostname #手册页不是唯一的参考资料,还有一种叫作info页面的信息.可以输入info info 来了解info页面相关内容 #另外大多数内容都可以接受 -help 或 --help 例如:hostname -help了解具体内容

    二、目录结构

    #常见Linux目录名称 ———————————————————————————————————————————————————————————————————————— 目录 用途 ———————————————————————————————————————————————————————————————————————— 1. / #虚拟目录的跟目录。通常不会再这里存储文件 2. /bin #二进制目录,存放许多用户级的GNU工具 3. /boot #启动目录,存放启动文件 4. /dev #设备目录,Linux在这里创建设备节点 5. /etc #系统配置文件目录 6. /home #主目录,Linux在这里创建用户目录 7. /lib #库目录,存放系统和应用程序的库文件 8. /media #媒体目录,可移动媒体设备的常用挂载点 9. /mnt #挂载目录,另一个可移动媒体设备的常用挂载点 10./opt #可选目录,常用于存放第三方软件包和数据文件 11./proc #进程目录,存放现有硬件及当前进程的相关信息 12./root #root用户的主目录 13./sbin #系统二进制目录,存放许多GNU管理员级工具 14./run #运行目录,存放系统运作时的运行数据 15./srv #服务目录,存放本地服务的相关文件 16./tmp #临时目录,可以在该目录中创建和删除临时工作文件 17./usr #用户二进制目录,大量用户级的GNU工具和数据文件都存储在这里 18./var #可变目录,用以存放经常变化的文件,比如日志文件 #常见的目录名均基于文件系统层级标准。官方主页:http://www.pathname.com/fhs

    三、目录基本命令

    #在Linux系统上可以使用切换目录命令cd将shell会话切换到另一个目录 语法:cd destination #目的地 destination参数可选择两种方式表示:一种是绝对路径,另一种是相对路径 绝对路径:定义了在虚拟目录结构中该目录的确切位置,相当于[目录全名] 相对路径:允许用户指定一个基于当前位置的目标文件路径 #查询当前工作目录 [root@172-0-0-2 ~]# man pwd NAME pwd - print name of current/working directory SYNOPSIS pwd [OPTION]... DESCRIPTION Print the full filename of the current working directory. -L, --logical use PWD from environment, even if it contains symlinks -P, --physical avoid all symlinks --help display this help and exit --version output version information and exit NOTE: your shell may have its own version of pwd, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report pwd translation bugs to <http://translationproject.org/team/> ___________________________________________________________________________________________ 单点符(.),表示当前目录 双点符(..),表示当前目录的父目录 ___________________________________________________________________________________________ #列出文件内容 [root@172-0-0-2 ~]# man ls NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alpha‐ betically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. #查询文件类型 ls -l #过滤输出列表--通配符 问号(?)代表一个字符 星号(*)代表零个或多个字符 中括号([])在特定的位置上可能出现的两种字符或指定字符范围,例如[ai][a - i] 感叹号(!)将不需要的内容排除在外 [root@172-0-0-2 ~]# ls anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates Desktop Downloads Music Public Videos [root@172-0-0-2 ~]# ls -l init* -rw-r--r--. 1 root root 1716 Jun 29 00:51 initial-setup-ks.cfg [root@172-0-0-2 ~]# ls -l initial-setup-ks.cf? -rw-r--r--. 1 root root 1716 Jun 29 00:51 initial-setup-ks.cfg [root@172-0-0-2 ~]# ll init[ti]* -rw-r--r--. 1 root root 1716 Jun 29 00:51 initial-setup-ks.cfg [root@172-0-0-2 ~]# ls anaconda-ks.cfg Documents f1 f3 Music Public Videos Desktop Downloads f2 initial-setup-ks.cfg Pictures Templates [root@172-0-0-2 ~]# ll f[1-5] -rw-r--r--. 1 root root 0 Jul 5 20:54 f1 -rw-r--r--. 1 root root 0 Jul 5 20:54 f2 -rw-r--r--. 1 root root 0 Jul 5 20:54 f3 [root@172-0-0-2 ~]# ll f[!1] -rw-r--r--. 1 root root 0 Jul 5 20:54 f2 -rw-r--r--. 1 root root 0 Jul 5 20:54 f3 #处理文件 [root@172-0-0-2 ~]# man touch #创建空文件或修改文件时间 NAME touch - change file timestamps SYNOPSIS touch [OPTION]... FILE... [root@172-0-0-2 ~]# ll --time=atime f1 #查看文件访问的时间 -rw-r--r--. 1 root root 0 Jul 6 02:23 f1 #复制文件 [root@172-0-0-2 ~]# man cp NAME cp - copy files and directories #复制文件或目录 SYNOPSIS cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... #链接文件 [root@172-0-0-2 ~]# man ln NAME ln - make links between files SYNOPSIS ln [OPTION]... [-T] TARGET LINK_NAME (1st form) #ln 目标 连接名 ln [OPTION]... TARGET (2nd form) #ln[option]目标 ln [OPTION]... TARGET... DIRECTORY (3rd form) #ln[option]目标 目录 ln [OPTION]... -t DIRECTORY TARGET... (4th form) #ln[option] -t 目录 目标 #重命名文件 [root@172-0-0-2 ~]# man mv NAME mv - move (rename) files SYNOPSIS mv [OPTION]... [-T] SOURCE DEST mv [OPTION]... SOURCE... DIRECTORY mv [OPTION]... -t DIRECTORY SOURCE... #删除文件 [root@172-0-0-2 ~]# man rm NAME rm - remove files or directories SYNOPSIS rm [OPTION]... FILE... #处理目录(创建目录) [root@172-0-0-2 ~]# man mkdir NAME mkdir - make directories SYNOPSIS mkdir [OPTION]... DIRECTORY... #删除目录 [root@172-0-0-2 ~]# man rmdir NAME rmdir - remove empty directories #删除空目录 SYNOPSIS rmdir [OPTION]... DIRECTORY... #使用file命令查询文件类型 语法:file [option] file #查看整个文件 #在Linux上有3个不同命令可以完成此任务。 1、cat command NAME cat - concatenate files and print on the standard output SYNOPSIS cat [OPTION]... [FILE]... 2、more command NAME more - file perusal filter for crt viewing SYNOPSIS more [options] file [...] 3、less command NAME less - opposite of more SYNOPSIS less -? less --help less -V less --version less [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~] [-b space] [-h lines] [-j line] [-k keyfile] [-{oO} logfile] [-p pattern] [-P prompt] [-t tag] [-T tagsfile] [-x tab,...] [-y lines] [-[z] lines] [-# shift] [+[+]cmd] [--] [filename]... (See the OPTIONS section for alternate option syntax with long option names.) #查看文件部分内容命令 #tail command :会显示文件最后几行的内容 NAME tail - output the last part of files SYNOPSIS tail [OPTION]... [FILE]... #head command :会显示文件开头那些行的内容 NAME head - output the first part of files SYNOPSIS head [OPTION]... [FILE]...
    Processed: 0.020, SQL: 9