Linux知识库
Linux基础知识!
Linux格式化硬盘以及格式化分区
linux基础常用知识
linux更换yum源
linux挂载windows SMB共享目录
linux开机启动级别
linux网卡配置
linux配置SMB服务
CentOS 8 firewalld配置
Linux软件管理:RPM软件包与YUM管理
Linux用户与组概念
Linux文件与目录权限基础
Linux计划任务管理
Linux中文本文件内容的查看
Linux基础-服务(service)和systemd管理服务
Vim编辑器基本操作
apt更换国内源
Linux程序服务!
Code-server在线编程服务器部署
Cloudreve网盘搭建
Emby多媒体影音系统搭建
chevereto图床搭建教程
Frp内网穿透服务器搭建
FTP服务器搭建
gitlab服务器搭建
Plex搭建
syncthing同步服务器搭建
Wordpress博客搭建
Typecho博客搭建
zabbix搭建(失败)
Aria2离线下载服务器搭建
KMS激活服务器搭建
CentOS搭建NTP服务
Grafana部署与Zabbix集成,部署开源IT系统监控平台
Linux应用环境搭建配置!
nginx编译安装
PHP8编译安装
Linux 关闭selinux
yum安装redis数据库
宝塔环境无法删除.user.ini
宝塔面板安装
mysql8.0.29编译安装
nginx安装(yum方式)
Linux系统基础知识
Linux命令行基础知识
使用Cerbot申请免费证书
ModSecurity 安装编译与连接nginx
Zabbix6.4.8安装部署
本文档使用 MrDoc 发布
-
+
首页
Linux命令行基础知识
## Linux命令行 Linux使用命令行与操作系统进行交互,通过在命令行输入命令进行程序运行、文件创建与编辑、查询系统信息等,命令行是Linux的精髓呢。默认我们通过命令行登录运行的程序是Shell(壳程序),我们通过在shell上输入命令进行操作。 之前我们已经大概了解了Linux系统一些常识,以及通过虚拟机安装了Linux系统进行学习,现在开始学习下在Linux中执行命令实现交互。 ## 基本命令操作 首先看下登录到系统是什么样子,分为几个部分。 ```linux [root@localhost ~]# root:当前登录用户 localhost:服务器的计算机名称,和windows的计算机名一致 ~ :当前目录,这个~代表默认用户家目录 # :这个代表当前是root用户,如果是普通用户显示为$符合 ``` 命令格式: ```linux [root@localhost ~]# command [-options] parameter1 parameter2 command:命令或可执行文件,如:ls pwd cd top等等,系统有很多预配置的功能命令 [-options]:可选项,有两种格式比如-h,-a,有时候也会有--表示,比如--help parameter:表示命令的参数或者选项的参数 命令和可选项和参数之间用空格隔开,多个空格也表示为一个 # 示例1:显示当前目录内容,按详细信息和时间排序 [root@localhost ~]# ls -latr 总用量 3622724 -rw-r--r--. 1 root root 129 5月 11 2019 .tcshrc -rw-r--r--. 1 root root 100 5月 11 2019 .cshrc -rw-r--r--. 1 root root 176 5月 11 2019 .bashrc -rw-r--r--. 1 root root 176 5月 11 2019 .bash_profile -rw-r--r--. 1 root root 18 5月 11 2019 .bash_logout drwxr-xr-x. 6 root root 65 6月 21 2021 vmtools -rw-r--r-- 1 root root 733017638 2月 22 2022 tb_sku1.sql -rw-r--r-- 1 root root 737475921 2月 22 2022 tb_sku2.sql -rw-r--r-- 1 root root 737525348 2月 22 2022 tb_sku4.sql -rw-r--r-- 1 root root 737504035 2月 22 2022 tb_sku3.sql -rw-r--r-- 1 root root 737508325 2月 22 2022 tb_sku5.sql 可选项可以写多个,多个-a -l -s 可以简写为-las,上面是没有参数的。 # 示例2:在当前目录下创建多层目录 [root@localhost ~]# mkdir -p ./test/a [root@localhost ~]# tree ./test ./test └── a 1 directory, 0 files -p :创建多层嵌套目录 # 示例3:没有添加可选项和参数的命令 ost ~]# pwd /root pwd:返回当前目录 # 示例4:命令+选项+参数一行代表一条命令被执行,如果命令过长可以使用\分行 ./configure --user=nginx \ --group=nginx \ --prefix=/www/nginx \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-stream \ --with-http_gzip_static_module \ --with-http_sub_module 上面使用的编译nginx的一个命令,使用configure这个程序文件,添加选项进行编译 ``` 下面是一些常用命令: | 命令 | 功能 | | --- | --- | | cd | 用于更改当前工作目录 | | ls | 用于列出当前目录中的文件和子目录 | | pwd | 用于显示当前工作目录的路径 | | mkdir | 用于创建新的目录 | | rm | 用于删除文件和目录(这个命令需要慎用) | | cp | 用于复制文件和目录 | | shutdown | 用于关闭或重新启动计算机 | | history | 显示历史命令,可以用来重复执行之前执行过的命令。 | | mv | 用于移动或重命名文件和目录 | | cat | 用于显示文件内容,一般用于文本内容显示,可执行文件显示乱码 | | more & less | 用于分页显示文件内容 | | head & tail | 用于显示文件的开头和结尾部分 | | chmod | 用于改变文件或目录的权限 | | chown | 用于改变文件或目录的所有者和所属组 | | ps | 用于查看当前进程状态 | | df | 用于显示磁盘空间使用情况 | | kill | 用于终止进程,类似任务管理器终止任务 | | grep | 用于在文件中搜索文本 | | find | 用于在目录中搜索文件 | | wget | 用于从网络下载文件 | | curl | 用于从网络下载文件 | | ping | 用于测试网络连接 | 上面的命令很多都有对应的选项和参数进行选择,而且很多命令可以集成使用,示例: ```linux [root@localhost ~]# ps -aux | grep nginx root 740893 0.0 0.0 85896 824 ? Ss 10月29 0:00 nginx: master process ./nginx nginx 740894 0.0 0.2 114076 22524 ? S 10月29 0:00 nginx: worker process root 4135185 0.0 0.0 12352 1088 pts/0 S+ 13:46 0:00 grep --color=auto nginx 上面先通过ps命令查询当前进程,然后通过|管道传输到下一个命令,通过grep过滤包含nginx的进程。 ``` 在Linux上命令的使用是非常灵活的,可以实现非常强大的功能。 ## 命令与信息查询 ### --help 上面给了一些常用的Linux命令,但是呢我没有写上参数,因为每个命令都有对应的参数,太多了根本写不完,但是我们也不需要死记硬背,可以通过命令的帮助功能查询,非常方便,大多数情况下可以通过--help查询该命令有什么选项。 ```linux [root@localhost ~]# ls --help 用法:ls [选项]... [文件]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. 必选参数对长短选项同时适用。 -a, --all 不隐藏任何以. 开始的项目 -A, --almost-all 列出除. 及.. 以外的任何项目 --author 与-l 同时使用时列出每个文件的作者 -b, --escape 以八进制溢出序列表示不可打印的字符 --block-size=SIZE with -l, scale sizes by SIZE when printing them; e.g., '--block-size=M'; see SIZE format below -B, --ignore-backups do not list implied entries ending with ~ -c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first -C list entries by columns --color[=WHEN] colorize the output; WHEN can be 'always' (default if omitted), 'auto', or 'never'; more info below -d, --directory list directories themselves, not their contents -D, --dired generate output designed for Emacs' dired mode -f do not sort, enable -aU, disable -ls --color -F, --classify append indicator (one of */=>@|) to entries --file-type likewise, except do not append '*' --format=WORD across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, vertical -C --full-time like -l --time-style=full-iso -g 类似-l,但不列出所有者 --group-directories-first group directories before files; can be augmented with a --sort option, but any use of --sort=none (-U) disables grouping -G, --no-group in a long listing, don't print group names -h, --human-readable with -l and -s, print sizes like 1K 234M 2G etc. --si likewise, but use powers of 1000 not 1024 -H, --dereference-command-line follow symbolic links listed on the command line --dereference-command-line-symlink-to-dir follow each command line symbolic link that points to a directory --hide=PATTERN do not list implied entries matching shell PATTERN (overridden by -a or -A) --hyperlink[=WHEN] hyperlink file names; WHEN can be 'always' (default if omitted), 'auto', or 'never' --indicator-style=WORD append indicator with style WORD to entry names: none (default), slash (-p), file-type (--file-type), classify (-F) -i, --inode print the index number of each file -I, --ignore=PATTERN do not list implied entries matching shell PATTERN -k, --kibibytes default to 1024-byte blocks for disk usage; used only with -s and per directory total # 而且里面解析非常详细,有两种写法,短格式-和长格式--,而且其实我们平时用不到那么多,只需要一些常用的记住一些就行了,熟能生巧而已。 ``` ### man 也可以通过man查询命令的详细信息。man后面接要查询的命令,然后进入一个类似说明文件,使用上下左右方向键进行移动,按键q退出。 快捷键说明: | 按键 | 功能 | | --- | --- | | 空格键 | 向下翻一页 | | [Page Down] | 向下翻一页 | | [Page Up] | 向上翻一页 | | [Home] | 去到第一页 | | [End] | 最后一页 | | /string | 向下查询,string代表需要查询的字符串 | | ?string | 向上查询,string代表需要查询的字符串 | | n,N | 通过/或者?查询结果之后使用这两个按键进行查询结果上一个和下一个跳转 | | q | 退出man查询 | ```linux [root@localhost ~]# man ls LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort 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 .. --author with -l, print the author of each file -b, --escape print C-style escapes for nongraphic characters ``` ## Linux中一些常用按键 ```linux tab : 如果使用CRT等工具连接可以使用tab键进行补全 Ctrl+C : 退出当前命令操作 ``` 好了,本次学习了命令的格式与执行,一些常用的命令和查询用法,下次继续。
Chuck
2023年12月18日 14:04
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码