#有的系统不支持ll命令,即查看列表的方式。 alias ll="ls -lh --time-style='+%Y/%m/%d %H:%M:%S'" #显示隐藏文件 alias lla="ls -lha --time-style='+%Y/%m/%d %H:%M:%S'" #对于Mac系统,ls的功能和Linux的不一样,格式化时间的ls功能可以为: alias ll='ls -lhT' alias lla='ls -lhaT' #显示当前目录中所有的文件夹 alias lld='ls -lhTd */' #开启一个以当前目录为webroot的HTTP服务,非常好用,用于文件分析 alias www='python -m SimpleHTTPServer 8000' #查看外部IP alias ipe='curl ipinfo.io/ip' #查看本机IP alias ipi='ipconfig getifaddr en0' #生成一个20位长度的随机密码 alias getpass="openssl rand -base64 20" #方便打印路径信息列表 alias path='echo -e ${PATH//:/\\n}' #打印当前时间 alias now='date "+%Y-%m-%d %H:%M:%S"' alias nowtime=now #打印当前日期 alias nowdate='date +"%Y-%m-%d"' #打印时间戳 alias timestamp='date "+%Y%m%d%H%M%S"' # git start alias gitlog='git log --pretty=format:"%h %s ==> author:%Cgreen%an" --graph'
参考地址:
https://opensource.com/article/18/9/handy-bash-aliases
https://linuxtoy.org/archives/10-bash-alias.html
关于系统别名的一些操作和限制的参考:
https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
linux 中使用ls指定输出时间格式
https://blog.csdn.net/chaofanwei/article/details/13018753
10 handy Bash aliases for Linux
Get more efficient by using condensed versions of long Bash commands.
How many times have you repeatedly typed out a long command on the command line and wished there was a way to save it for later? This is where Bash aliases come in handy. They allow you to condense long, cryptic commands down to something easy to remember and use. Need some examples to get you started? No problem!
To use a Bash alias you've created, you need to add it to your .bash_profile file, which is located in your home folder. Note that this file is hidden and accessible only from the command line. The easiest way to work with this file is to use something like Vi or Nano.
10 handy Bash aliases
- How many times have you needed to unpack a .tar file and couldn't remember the exact arguments needed? Aliases to the rescue! Just add the following to your .bash_profile file and then use untar FileName to unpack any .tar file.
alias untar='tar -zxvf '
- Want to download something but be able to resume if something goes wrong?
alias wget='wget -c '
- Need to generate a random, 20-character password for a new online account? No problem.
alias getpass="openssl rand -base64 20"
- Downloaded a file and need to test the checksum? We've got that covered too.
alias sha='shasum -a 256 '
- A normal ping will go on forever. We don't want that. Instead, let's limit that to just five pings.
alias ping='ping -c 5'
- Start a web server in any folder you'd like.
alias www='python -m SimpleHTTPServer 8000'
- Want to know how fast your network is? Just download Speedtest-cli and use this alias. You can choose a server closer to your location by using the speedtest-cli --list command.
alias speed='speedtest-cli --server 2406 --simple'
- How many times have you needed to know your external IP address and had no idea how to get that info? Yeah, me too.
alias ipe='curl ipinfo.io/ip'
- Need to know your local IP address?
alias ipi='ipconfig getifaddr en0'
- Finally, let's clear the screen.
alias c='clear'
As you can see, Bash aliases are a super-easy way to simplify your life on the command line. Want more info? I recommend a quick Google search for "Bash aliases" or a trip to GitHub.
SimpleHTTPServer:
https://docs.python.org/2/library/simplehttpserver.html
参考地址: https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
More about bash alias
The general syntax for the alias command for the bash shell is as follows:
How to list bash aliases
Type the following alias command:alias
Sample outputs:
alias ..='cd ..' alias amazonbackup='s3backup' alias apt-get='sudo apt-get' ...
By default alias command shows a list of aliases that are defined for the current user.
How to define or create a bash shell alias
To create the alias use the following syntax:
In this example, create the alias c for the commonly used clear command, which clears the screen, by typing the following command and then pressing the ENTER key:
Then, to clear the screen, instead of typing clear, you would only have to type the letter ‘c’ and press the [ENTER] key:
How to disable a bash alias temporarily
An alias can be disabled temporarily using the following syntax:
How to delete/remove a bash alias
You need to use the command called unalias to remove aliases. Its syntax is as follows:
In this example, remove the alias c which was created in an earlier example:
You also need to delete the alias from the ~/.bashrc file using a text editor (see next section).
How to make bash shell aliases permanent
The alias c remains in effect only during the current login session. Once you logs out or reboot the system the alias c will be gone. To avoid this problem, add alias to your ~/.bashrc file, enter:
The alias c for the current user can be made permanent by entering the following line:
Save and close the file. System-wide aliases (i.e. aliases for all users) can be put in the /etc/bashrc file. Please note that the alias command is built into a various shells including ksh, tcsh/csh, ash, bash and others.
A note about privileged access
You can add code as follows in ~/.bashrc:
A note about os specific aliases
You can add code as follows in ~/.bashrc using the case statement:
30 bash shell aliases examples
You can define various types aliases as follows to save time and increase productivity.
#1: Control ls command output
The ls command lists directory contents and you can colorize the output:
#2: Control cd command behavior
#3: Control grep command output
grep command is a command-line utility for searching plain-text files for lines matching a regular expression:
#4: Start calculator with math support
#4: Generate sha1 digest
#5: Create parent directories on demand
mkdir command is used to create a directory:
#6: Colorize diff output
You can compare files line by line using diff and use a tool called colordiff to colorize diff output:
#7: Make mount command output pretty and human readable format
#8: Command short cuts to save time
#9: Create a new set of commands
#10: Set vim as default
#11: Control output of networking tool called ping
#12: Show open ports
Use netstat command to quickly list all TCP/UDP port on the server:
#13: Wakeup sleeping servers
Wake-on-LAN (WOL) is an Ethernet networking standard that allows a server to be turned on by a network message. You can quickly wakeup nas devices and server using the following aliases:
#14: Control firewall (iptables) output
Netfilter is a host-based firewall for Linux operating systems. It is included as part of the Linux distribution and it is activated by default. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.
#15: Debug web server / cdn problems with curl
#16: Add safety nets
#17: Update Debian Linux server
apt-get command is used for installing packages over the internet (ftp or http). You can also upgrade all packages in a single operations:
#18: Update RHEL / CentOS / Fedora Linux server
yum command is a package management tool for RHEL / CentOS / Fedora Linux and friends:
#19: Tune sudo and su
#20: Pass halt/reboot via sudo
shutdown command bring the Linux / Unix system down:
#21: Control web servers
#22: Alias into our backup stuff
#23: Desktop specific – play avi/mp3 files on demand
#24: Set default interfaces for sys admin related commands
vnstat is console-based network traffic monitor. dnstop is console tool to analyze DNS traffic. tcptrack and iftop commands displays information about TCP/UDP connections it sees on a network interface and display bandwidth usage on an interface by host respectively.
#25: Get system memory, cpu usage, and gpu memory info quickly
#26: Control Home Router
The curl command can be used to reboot Linksys routers.
#27 Resume wget by default
The GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, and it can resume downloads too:
#28 Use different browser for testing website
#29: A note about ssh alias
Do not create ssh alias, instead use ~/.ssh/config OpenSSH SSH client configuration files. It offers more option. An example:
You can now connect to peer1 using the following syntax:$ ssh server10
#30: It’s your turn to share…
Conclusion
This post summarizes several types of uses for *nix bash aliases:
- Setting default options for a command (e.g. set eth0 as default option for ethtool command via alias ethtool='ethtool eth0' ).
- Correcting typos (cd.. will act as cd .. via alias cd..='cd ..').
- Reducing the amount of typing.
- Setting the default path of a command that exists in several versions on a system (e.g. GNU/grep is located at /usr/local/bin/grep and Unix grep is located at /bin/grep. To use GNU grep use alias grep='/usr/local/bin/grep' ).
- Adding the safety nets to Unix by making commands interactive by setting default options. (e.g. rm, mv, and other commands).
- Compatibility by creating commands for older operating systems such as MS-DOS or other Unix like operating systems (e.g. alias del=rm ).
I’ve shared my aliases that I used over the years to reduce the need for repetitive command line typing. If you know and use any other bash/ksh/csh aliases that can reduce typing, share below in the comments.
See also
- Customize the bash shell environments
- Download all aliases featured in this post
- GNU bash shell home page
相关推荐
Linux 命令大全搜索工具是一个非常有用的工具,可以帮助用户快速查找和使用相关命令,提高工作效率和生产力。 以下是 Linux 命令大全搜索工具的一些重要命令: * a - Apache 服务器的性能测试工具 * accept - 指示...
这在需要在同一台服务器上提供多个服务或需要多个公网IP的情况下非常有用。配置IP别名的命令通常涉及到`ifconfig`或`ip addr`命令。例如,给eth0接口添加一个新的IP地址,可以使用`ifconfig eth0:0 192.168.1.2 ...
这两个编辑器都提供了命令行下的文本编辑功能,对程序员和系统管理员来说非常有用。 总的来说,这个【Linux_Utils】压缩包旨在为Windows用户提供一套方便的Linux工具集,使他们能够在Windows环境下模拟部分Linux...
- **功能**:提供了位操作函数,如`set_bit`和`test_bit`,对于实现输入子系统非常有用。 15. **`<linux/semaphore.h>`** - **位置**:`linux-2.6.29/include/linux` - **功能**:定义了信号量的操作函数,如`...
这些工具在解决系统问题和优化性能时非常有用。 最后,“Linux命令介绍”很可能是一个命令大全,包含了许多常见的Linux命令及其用法,如ls、cd、mkdir、rm、cp、mv等,以及更复杂的命令如grep、find、sed和awk等。 ...
总的来说,了解CMD、DOS和Linux的命令行操作对于系统管理和自动化任务非常有用。熟练掌握这些命令可以极大地提高工作效率,特别是在执行批量处理、系统维护和故障排查时。无论是Windows还是Linux,熟悉命令行都是每...
理解并掌握这些知识点,对于提升Linux下的C/C++编程能力非常关键,能够帮助开发者更有效地利用操作系统资源,编写出高质量的系统级和应用级程序。通过不断学习和实践,你可以成为一个精通Linux环境下的C/C++开发者。
这在处理多任务和后台服务时非常有用。 最后,Shell脚本的调试和优化也是必不可少的知识。学会使用set命令来调整Shell的行为,以及如何利用bash的内置调试工具如set -x来追踪脚本的执行过程,这对于查找和修复错误...
这些命令在进行数据备份和迁移时非常有用。 Linux命令通常都有着丰富的选项和参数,它们可能具有不同的用途和效果。例如,`ps` 命令可以显示当前系统进程的状态,而 `ps aux` 可以展示更详细的系统进程信息。`kill`...
- `du`、`df`:分别用于显示文件或目录的磁盘使用量和整个文件系统的磁盘空间使用情况,对于监控系统资源占用非常有用。 #### 结论 Linux命令的学习和掌握是成为一名合格IT专业人员的必备技能。通过深入理解上述...
为了提高效率和用户体验,许多用户会选择自定义Bash提示符(Prompt)以显示更多有用的信息。`gittify`就是这样一个工具,它为Bash提供了一个多彩、信息丰富的提示符,并且还包含了一些自定义的Git别名,使得Git操作...
### Linux指令大全知识点详解 #### 一、At 指令 **名称**: at **使用权限**: 所有使用者 ...这些命令对于自动化任务和提高工作效率非常有用。了解这些命令的具体用法可以帮助用户更好地管理自己的系统。
此外,还有一些其他的重要命令,如`find`(文件查找)、`grep`(文本搜索)、`sed`和`awk`(文本处理工具)等,它们在处理大量数据和日志文件时也非常有用。在实际工作中,运维工程师还需要不断学习新的技术和工具,...
这在处理大量数据时非常有用,特别是需要按字母顺序或其他标准排序的情况。 #### Hack-15 Uniq命令 `uniq` 命令用于从排序后的文件中移除重复的行。这在数据分析中特别有用,可以快速去除重复数据。 #### Hack-16 ...
RDAC提供了一种方法来监控和管理远程RAID控制器,这在多路径环境中非常有用。你需要编译和安装这个源码包以支持特定型号的存储设备。这通常涉及解压文件,配置,编译,然后安装: ```bash tar -zxvf rdac-LINUX-...
Unix/Linux Cheat Sheet 是一个非常有用的工具,特别是对于初学者来说,它提供了丰富的命令行操作指南。这个资源可能是一个PDF文档,包含简明易懂的Linux命令和相关操作,旨在帮助用户快速掌握在Unix或Linux环境中...
6. **网络功能**:Linux-mc支持FTP、SFTP协议,可以直接在本地与远程服务器之间传输文件,这对于系统管理员来说尤其有用。 7. **自定义配置**:用户可以根据自己的习惯调整快捷键设置,定制命令行别名,以及创建...