Linux alias命令(为复杂命令创建别名,其中命令可带选项或参数)

news2025/2/26 11:37:59

文章目录

  • Mastering the Linux `alias` Command(精通Linux的`alias`命令)
    • 1. Understanding the `alias` Command(理解`alias`命令)
      • 示例
        • Ubuntu20.04 arm操作系统
        • OpenEuler20.03 arm操作系统
    • 2. Basic Usage of `alias`(`alias`的基本用法)
    • 3. Advanced Applications of `alias`(`alias`的高级应用)
    • 4. Making Aliases Permanent(使别名永久有效)
    • 5. Tips and Tricks(技巧和提示)
      • 1. Use the `unalias` command to remove an alias.(使用`unalias`命令删除一个别)名。
      • 2. Enclose commands containing spaces in quotes when defining an alias.(在定义包含空格的命令的别名时,将命令用引号括起来。)
      • 3. Remember that aliases are specific to the shell they are defined in.
    • 6. Conclusion(结论)

Mastering the Linux alias Command(精通Linux的alias命令)

The Linux alias command is a built-in shell command that allows users to create shortcuts or synonyms(同义词) for other commands. It simplifies complex command-line instructions, saving time and minimizing potential mistakes.
Linux的alias命令是一个内置的shell命令,允许用户为其他命令创建快捷方式或同义词。它简化了复杂的命令行指令,节省了时间并尽可能减少了错误。

1. Understanding the alias Command(理解alias命令)

The alias command in Linux is an inbuilt(内置的) command that creates shortcuts for other commands which can include options and arguments. This can significantly(显著地) streamline(使效率更高) your workflow(工作流程), particularly when you frequently use long or complex commands.
Linux中的alias命令是一个内置命令,可以创建其他命令的快捷方式,其中可以包括选项和参数。这可以显著简化你的工作流程,特别是当你频繁使用长的或复杂的命令时。

To view all currently defined aliases in the terminal, simply type alias and press enter:
要查看终端中当前定义的所有别名,只需输入alias然后按回车键:

alias

示例

Ubuntu20.04 arm操作系统

在这里插入图片描述

OpenEuler20.03 arm操作系统

在这里插入图片描述

2. Basic Usage of aliasalias的基本用法)

The general syntax of the alias command is as follows:
alias命令的一般语法如下:

alias alias_name='command'

The alias_name is the name of the new alias, and command is the command that the alias refers to.
alias_name是新别名的名称,command是别名所指向的命令。

For instance(例如), to create a shortcut for the ls -lh command (which lists files in ‘long format’ with human-readable file sizes), one could define an alias named ll:
例如,为了创建ls -lh命令的快捷方式(它以"长格式"列出文件,文件大小可读),可以定义一个名为ll的别名:

alias ll='ls -lh'

Now, typing ll in the terminal would execute ls -lh.
现在,在终端中输入ll将执行ls -lh

3. Advanced Applications of aliasalias的高级应用)

Aliases can be more complex and powerful. They can incorporate(包含) multiple commands separated by semicolons(分号) or contain control structures such as loops or conditional statements.
别名可以更复杂和强大。他们可以包含由分号分隔的多个命令,或包含循环或条件语句等控制结构。

For example, an alias could be created to update the system and then clear the terminal:
例如,可以创建一个别名来更新系统然后清除终端:

alias update_and_clear='sudo apt-get update; clear'

4. Making Aliases Permanent(使别名永久有效)

Aliases defined in a terminal(终端) session(会话) are temporary - they cease(停止) to exist when the session is closed. To make an alias permanent, it needs to be defined in the shell configuration file.
在终端会话中定义的别名是临时的——当会话关闭时,它们就不存在了。要使别名永久有效,需要在shell配置文件中定义它。

注:"Terminal"或者"终端"在操作系统中,通常指的是一个用于接收用户输入命令和显示系统输出信息的接口。它通常是文本模式下的操作环境,没有图形化界面。在Windows系统中,最常见的类似工具是命令提示符(Command
Prompt)或PowerShell;而在Unix/Linux系统中,我们通常指的是shell环境。

使用终端可以让用户直接通过命令行来控制操作系统,执行各种任务,如管理文件系统、安装和删除软件包、启动和停止服务等。对于熟悉命令行的用户来说,这种方式往往比图形化界面更高效。

注:"Cease"和"stop"区别:
"Cease"和"stop"都有停止的意思,但它们的用法和语境有所不同。

"Stop"是一个更常见、更口语化的词汇,可用于各种情况,例如 “stop talking”(停止说话),“stop
running”(停止跑步)等。这个词可以在非正式或日常对话中使用。

"Cease"则更正式,常出现在书面语言或法律文件中,比如 “cease and desist”(立即停止)。通常用于表达某事物完全、永久性地结束。例如,“The company ceased operations”(公司停止了运营)。这个词通常不会在日常对话中使用。

For bash, this would be the ~/.bashrc file. For zsh, this would be the ~/.zshrc file. An example of defining an alias permanently for bash would be:
对于bash,这将是~/.bashrc文件。对于zsh,这将是~/.zshrc文件。以下是为bash永久定义别名的例子:

echo "alias ll='ls -lh'" >> ~/.bashrc
source ~/.bashrc

5. Tips and Tricks(技巧和提示)

Here are a few additional tips and tricks that might come in handy:
以下是一些可能派得上用场的额外技巧和提示:

1. Use the unalias command to remove an alias.(使用unalias命令删除一个别)名。

Explanation: The unalias command is used in Unix/Linux based systems to remove or delete the alias that was previously created.

解释:unalias命令用于Unix/Linux基础系统中,用来移除或删除之前创建的别名。

Example: Suppose we have created an alias like this: alias ls='ls -al'. If we want to remove this alias, we can use unalias ls.

示例:假设我们创建了这样一个别名:alias ls='ls -al'。如果我们想要移除这个别名,我们可以使用unalias ls

2. Enclose commands containing spaces in quotes when defining an alias.(在定义包含空格的命令的别名时,将命令用引号括起来。)

Explanation: When you are creating an alias and the command contains space, then you need to enclose(括起来) the whole command in single or double quotes(引号).

解释:当你在创建一个别名,并且命令包含空格时,你需要用单引号或双引号把整个命令括起来。

Example: To create an alias for the command ls -al, which has a space, you can write it as alias ls='ls -al'.

示例:为了创建一个包含空格的命令ls -al的别名,你可以写成alias ls='ls -al'

3. Remember that aliases are specific to the shell they are defined in.

记住,别名是特定于它们被定义的shell。

Explanation: Aliases are specific to the shell they are created in, and they will not be available in a new shell or a different terminal session unless they are defined in the shell’s configuration file.

解释:别名是特定于创建它们的shell,除非在shell的配置文件中定义,否则在新的shell或不同的终端会话中不可用。

Example: If you define alias ls='ls -al' in one terminal session, then open a new terminal window, the alias will not be recognized in the new window.

示例:如果你在一个终端会话中定义了alias ls='ls -al',然后打开一个新的终端窗口,那么在新窗口中将无法识别这个别名。

6. Conclusion(结论)

The Linux alias command can greatly simplify the command-line interface and increase productivity (生产率)by reducing the time and effort required to type long or complex commands. With a good understanding of how to create, use, and manage aliases, you’re well on your way to becoming a more efficient Linux user.
Linux的alias命令可以大大简化命令行界面,并通过减少输入长的或复杂的命令所需的时间和努力来提高生产力。通过对如何创建、使用和管理别名的良好理解,你将很快成为一个更有效率的Linux用户。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1477344.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

k8s初始化报错 [ERROR CRI]: container runtime is not running: ......

一、环境参数 linux系统为centos7kubernetes版本为v1.28.2containerd版本为1.6.28 二、报错内容 执行初始化命令kubeadm init命令时报错,内容如下 error execution phase preflight: [preflight] Some fatal errors occurred:[ERROR CRI]: container runtime is…

Excel数据表定制分组排序

实例需求:某学校体育活动统计表如下图左侧表格所示,数据按照班级排列,现在需要根据如下规格对表格进行排序 “幼儿”班级排列在表格最后按照“次数”降序排列“幼儿”班级同样按“次数”降序排列 排序结果如下图中右侧表格所示。 示例代码…

什么是蓝牙资产标签?

在当今的物联网时代,蓝牙资产标签作为一种无线通信技术,被广泛应用于各种资产跟踪和管理场景。那么,究竟什么是蓝牙资产标签呢? 蓝牙资产标签,顾名思义,是一种基于蓝牙技术实现的资产追踪设备。它通过与手…

羊大师:羊奶的多元价值,从餐桌到保健,一奶多用

羊大师:羊奶的多元价值,从餐桌到保健,一奶多用 羊奶的多元价值体现在多个方面,从餐桌到保健,都有着独特的作用。 在餐桌上,羊奶可以作为各种美食的原料,如羊奶冰淇淋、羊奶饼干、羊奶布丁等&a…

Element ui plus 中 table scroll 自动触底

Element ui plus 中 table scroll 自动触底 场景:添加客户等级的时候,新增的客户等级 input 框 被 scroll 遮挡、重叠,需要保证 scroll 保持在 最底部接可以解决 遮挡、重叠。 el-table 在设置了 height 后,会选择将 table 表头固…

逆向案例三:动态xhr包中AES解密的一般步骤,以精灵数据为例

补充知识:进行AES解密需要知道四个关键字,即密钥key,向量iv,模式mode,填充方式pad 一般网页AES都是16位的,m3u8视频加密一般是AES-128格式 网页链接:https://www.jinglingshuju.com/articles 进行抓包结果返回的是密文: 一般思…

使用vue把一周的时间划分为可以选择多个阶段

提示&#xff1a;使用vue把一周的时间划分为可以选择多个阶段段&#xff08;亲测有效&#xff09; 一、直接复制以下代码 代码如下&#xff08;示例&#xff09;&#xff1a; <template><div class"byted-weektime" mousedown"dian" mousemove&qu…

Object类详解

Object类详解 equals方法 和 equals的对比 hashcode 方法toString方法finalize 方法 &#xff08;新版被弃用&#xff09; equals方法 和 equals的对比 是一个比较运算符&#xff1a;   1&#xff09; &#xff1a;既可以判断基本类型&#xff0c;又可以判断引用类型&#x…

web自动化笔记一:元素定位的八种方式

一、元素定位 优先使用id定位&#xff0c;超链接使用link和paryial_link 二、自动化测试流程&#xff08;先定位后操作&#xff09; 1、自动化测试方案->2、自动化脚本编写&#xff08;定位元素、操作元素、验证操作、记录测试结果&#xff09;->3、执行测试用例->4、…

MATLAB环境下基于人工蜂群优化算法的卷积神经网络CNN图像识别

地球上的所有生物包括人类都在不断演变、进化&#xff0c;在这样的过程中逐渐适应了外界的环境&#xff0c;找到了适合自己的生存方式。不同的生物有不同的生存机制&#xff0c;群体活动作为一种常见的生存机制广泛存在于自然界中&#xff0c;例如蚂蚁、鸟群、鱼群、峰群甚至人…

手机和windows的便签怎么共享账号使用

在忙碌的生活中&#xff0c;我经常需要在手机和电脑之间同步记事信息。可是&#xff0c;每次当我在手机上记下一些重要事项后&#xff0c;想要在电脑上查看或继续编辑时&#xff0c;总是遇到各种麻烦。因为手机和电脑上的便签软件各不相同&#xff0c;无法实现账号共享和内容同…

系统性学习vue-vue3

系统性学习vue-vue3 Vue3简介创建Vue3.0工程使用vue-cli创建使用vite创建工程 分析工程结构&#xff08;cli创建的&#xff09;main.jsApp.vue 安装开发者工具初识setupref函数处理基本类型处理对象类型 reactive函数回顾Vue2的响应式原理vue3响应式原理—Proxyreactive对比ref…

C++面试宝典第33题:数组组成最大数

题目 给定一组非负整数nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。 示例1: 输入:nums = [10, 2] 输出:"210" 示例2: 输入:nums = [3, 30, 34, 5, 9] 输出:"…

开发一款跨境电商APP的流程是什么

开发一款跨境电商系统的流程大致如下&#xff1a; 1.需求分析&#xff1a;这是开发任何软件系统的第一步。在这个阶段&#xff0c;你需要与客户进行深入沟通&#xff0c;了解他们的业务模式、目标用户、产品特点以及竞争对手等信息。通过这一步骤&#xff0c;你可以确定系统的…

报`Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.`错误解决办法

使用了promise,但是在使用的过程中报Uncaught (in promise)错误&#xff0c;第一次遇到这种错误&#xff0c;所以在此记录下&#xff0c;方便以后解决问题 Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.错误通常出现在使用fetch API发起…

pytorch 图像数据集管理

目录 1.数据集的管理说明 2.数据集Dataset类说明 3.图像分类常用的类 ImageFolder 1.数据集的管理说明 pytorch使用Dataset来管理训练和测试数据集&#xff0c;前文说过 torchvision.datasets.MNIST 这些 torchvision.datasets里面的数据集都是继承Dataset而来&#xff0c…

【QT+QGIS跨平台编译】之五十六:【QGIS_CORE跨平台编译】—【qgsmeshcalclexer.cpp生成】

文章目录 一、Flex二、生成来源三、构建过程一、Flex Flex (fast lexical analyser generator) 是 Lex 的另一个替代品。它经常和自由软件 Bison 语法分析器生成器 一起使用。Flex 最初由 Vern Paxson 于 1987 年用 C 语言写成。 “flex 是一个生成扫描器的工具,能够识别文本中…

【Python笔记-设计模式】状态模式

一、说明 状态模式是一种行为设计模式&#xff0c;用于解决对象在不同状态下具有不同行为 (一) 解决问题 在对象行为根据对象状态而改变时&#xff0c;规避使用大量的条件语句来判断对象的状态&#xff0c;提高系统可维护性 (二) 使用场景 当对象的行为取决于其状态&#…

vue 部署后修改配置文件(接口IP)

近期&#xff0c;有一个项目&#xff0c;运维在部署的时候&#xff0c;接口ip还没有确定&#xff0c;而且ip后面的路径一直有变动&#xff0c;导致我这里一天打包至少四五次才行&#xff0c;很麻烦&#xff0c;然后看了下有没有打包后修改配置文件修改接口ip的方法&#xff0c;…

kubectl使用及源码阅读

目录 概述实践样例yaml 中的必须字段 kubectl 代码原理kubectl 命令行设置pprof 抓取火焰图kubectl 中的 cobra 七大分组命令kubectl createcreateCmd中的builder模式createCmd中的visitor访问者模式外层VisitorFunc分析 结束 概述 k8s 版本 v1.24.16 kubectl的职责 1.主要的…