新聞中心
隨著Linux系統(tǒng)的廣泛應(yīng)用,學(xué)習(xí)Linux命令已經(jīng)成為了一項(xiàng)必備的技能。其中,alias命令是Linux系統(tǒng)中重要的一個(gè)命令,它可以幫助用戶實(shí)現(xiàn)快捷輸入一些常用的命令。本文將詳細(xì)介紹alias命令的作用和使用方法。

十載的德江網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整德江建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“德江網(wǎng)站設(shè)計(jì)”,“德江網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
一、alias命令的作用
在Linux命令行中,用戶可以輸入各種命令完成不同的操作。有些命令名稱比較長,輸入起來比較麻煩,而有些命令則需要較長的參數(shù),用戶不方便每次都輸入完整的命令及參數(shù)。這時(shí)候alias命令就派上用場了。
alias命令可以為常用或復(fù)雜的命令添加一個(gè)簡短的別名,幫助用戶快速輸入命令。比如,我們可以把ls -lh命令設(shè)置為一個(gè)名為ll的別名,然后在命令行中輸入ll就可以快速執(zhí)行l(wèi)s -lh命令。除此之外,alias命令還可以實(shí)現(xiàn)多個(gè)命令組合在一起執(zhí)行,使得復(fù)雜的操作變得更加簡單。
二、alias命令的使用方法
1.alias命令簡介
alias命令的通用語法為:
alias [-p] [alias_name[=’value’]…]
其中alias_name是所創(chuàng)建的別名的名稱,value則是所對(duì)應(yīng)的命令及參數(shù),可以是任意長度。
2.創(chuàng)建簡單別名
我們以將ls -lh設(shè)置為別名ll為例:
$ alias ll=’ls -lh’
這樣,我們?cè)诿钚兄休斎雔l就可以快速執(zhí)行l(wèi)s -lh命令。但注意,這種設(shè)置只在當(dāng)前會(huì)話有效。如果用戶希望在下次登錄時(shí)仍可以使用別名,應(yīng)該將該命令加入到.bashrc文件中。
3.取消別名
如果用戶不需要某個(gè)別名,可以使用unalias命令進(jìn)行取消。比如,取消別名ll可以使用下面的命令:
$ unalias ll
同樣,這種取消設(shè)置只在當(dāng)前會(huì)話中有效,如果希望長期有效,應(yīng)該將命令加入到.bashrc文件中。
4.使用別名組合命令
alias命令不但可以使用單個(gè)命令的別名,還可以將多個(gè)命令組合起來,構(gòu)成一個(gè)復(fù)雜的別名。
比如,我們可以將cd命令和ls命令組合成一個(gè)命令:
$ alias cl=’cd /var/log; ls -lh’
這樣,我們?cè)诿钚兄休斎隿l,就可以執(zhí)行cd /var/log并且列出該目錄下的文件了。
5.查看所有別名
如果用戶想查看當(dāng)前系統(tǒng)中設(shè)置的所有別名,可以使用alias命令加上-p選項(xiàng):
$ alias -p
該命令會(huì)列出當(dāng)前所有系統(tǒng)級(jí)別的別名。
三、
alias命令是Linux系統(tǒng)中非常重要的一個(gè)命令,可以幫助用戶實(shí)現(xiàn)快捷輸入一些常用的命令,也可以組合命令完成復(fù)雜操作。在日常的Linux使用中,熟練掌握alias命令的使用方法可以幫助用戶更加高效地完成工作。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián),建站經(jīng)驗(yàn)豐富以策略為先導(dǎo)10多年以來專注數(shù)字化網(wǎng)站建設(shè),提供企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),響應(yīng)式網(wǎng)站制作,設(shè)計(jì)師量身打造品牌風(fēng)格,熱線:028-86922220alias怎么輸入尺寸
在提示欄輸入尺寸歷猜。
經(jīng)查閱alias資料桐爛孫可知,在非等局鏈比縮放,激活scale,然后在提示欄輸入尺寸。
在linux中,alias命令(注意全為小寫)的功能是設(shè)置命令的別名,以簡寫命令,提高操作效率。
如何讓linux用戶自定義的命令alias永久生效
通過man bash可以查找到關(guān)于alias命令的用法
alias …>
Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output. When arguments are supplied, an alias is defined for each name whose value is given. A trailing
兄?jǐn)y鋒 space in value causes the next word to be checked for alias substitution when the alias is expanded. For each name in the argument list for which no value is supplied, the name and value of the alias is printed. Alias
returns true unless a name is given for which no alias has been defined.
顯示當(dāng)前全部的別名:
# alias -p
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’
顯示特定的別名:
# alias ls
alias ls=’ls –color=auto’
讓自定義的alias生效的方法:
同樣來自man bash,
When bash is 隱租invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks
for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The –noprofile option may be used when the shell is started to inhibit this
behavior.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the –norc option. The –rcfile file option will force bash to
read and execute commands from file instead of ~/.bashrc.
簡單說,用戶在打開終端shell的時(shí)候會(huì)加載幾個(gè)配置文件,而且根據(jù)當(dāng)前shell是否是登陸(login)shell,交互式shell會(huì)加載不同的配置文件。
一般來說設(shè)置別名如果想全局羨晌生效,即對(duì)所有用戶都生效,需要修改/etc/profile,只針對(duì)當(dāng)前用戶生效,推薦修改~/.bashrc。目前很多l(xiāng)inux發(fā)行版中非登陸shell默認(rèn)也會(huì)加載~/.bashrc,因?yàn)閪/.bash_profile中加了這么一段:
$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if ; then
. ~/.bashrc
fi
添加自定義的alias的方法,在上述配置文件中添加alias命令,如
linux系統(tǒng)中什么命令快速進(jìn)入指定文件夾
通過alias命令建立進(jìn)入指虧扒搏定文件夾的快捷鍵,如:
alias
“銷祥cd1=cd
/etc”
alisa
“cd2=cd
/usr/in”
這樣,就可以快捷的進(jìn)入到指定的目錄下了。
退回上一次此和所在目錄,快捷鍵為:
cd
–
可以把你想要快速進(jìn)入的文件夾的絕對(duì)路徑在環(huán)境變寬州量中設(shè)一個(gè)別名,如
alias
abc
=
‘/etc/init.d’
下次你想慎禪蔽進(jìn)入/etc/init.d之需要輸襲者入cd
abc就好了
關(guān)于linux alias命令的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
成都創(chuàng)新互聯(lián)科技公司主營:網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、小程序制作、成都軟件開發(fā)、網(wǎng)頁設(shè)計(jì)、微信開發(fā)、成都小程序開發(fā)、網(wǎng)站制作、網(wǎng)站開發(fā)等業(yè)務(wù),是專業(yè)的成都做小程序公司、成都網(wǎng)站建設(shè)公司、成都做網(wǎng)站的公司。創(chuàng)新互聯(lián)公司集小程序制作創(chuàng)意,網(wǎng)站制作策劃,畫冊(cè)、網(wǎng)頁、VI設(shè)計(jì),網(wǎng)站、軟件、微信、小程序開發(fā)于一體。
網(wǎng)站題目:學(xué)習(xí)Linux命令:解析alias命令的作用和用法(linuxalias命令)
本文URL:http://fisionsoft.com.cn/article/dphhcid.html


咨詢
建站咨詢
