.bashrc Beispiele


Applying changes

To apply changes from this article to your

(without ending subshells), do:

Or, if you want, you can build your prompt using the ✓ unicode symbol for a zero status and the ✗ unicode symbol for a nonzero status:

0 ✓ andy@alba ~ $ true

0 ✓ andy@alba ~ $ false

1 ✗ andy@alba ~ $ I will try to type a wrong command…

bash: I will try to type a wrong command…: command not found

127 ✗ andy@alba ~ $ _

Alternatively, this can be made more readable with


Here’s an alternative that only includes the error status, if non-zero:

Tips and tricks

Different colors for text entry and console output

If you do not reset the text color at the end of your prompt, both the text you enter and the console text will simply stay in that color. If you want to edit text in a special color but
still use the default color for command output, you will need to reset the color after you press

, but still before any commands get run. You can do this by installing a DEBUG
trap, like this:

Random quotations at logon

For a brown Fortune prompt, add:


To only get the absolute latest item, use this:

Colors overview

The page at ascii-table.com describes the various available color escapes. The following Bash
function displays a table with ready-to-copy escape codes.

Syntax Highlighting im vi

Der Texteditor vi auf der Konsole, der in keinem LINUX/UNIX fehlt, ist in den modernen Linuxsystemen auf einen wesentlich leistungsfähigeren Nachfolger vim oder einen Klon davon, gelinkt. Dieser Editor kann unter Anderem auch Syntax Highlighting“ für eine Vielzahl von Dateitypen. Im Verzeichnis
/usr/share/vim/current/syntax/ stehen die Syntaxkonfigurationsfiles. Anhand der Endung (prefix) der zu editierenden Datei erkennt vim welche Syntax für diesen Dateitype zu benutzen ist.
Selbstverständlich kann man auch seine eigenen Syntax-Konfigurationsfiles entwerfen und einsetzen und auch die Farben anpassen. Siehe dazu vimdoc.sourceforge.net

Ein- Ausschalten des Syntax highlighting im vim

permanent durch Eintrag in der Vim-Konfigurationsdatei ~/.vimrc

anlegen der Datei bzw. erweitern dieser Datei und folgenden Eintrag vornehmen

bei Bedarf durch Zeilenoption beim Start von vi

bei Bedarf während der Sitzung im Kommandomodus

hier kann während der Sitzung dieser Modus nach Belieben Ein- und Ausgeschaltet werden

Analog Ausschalten

So I’ve found the following cool Bash prompt:

Bash prompt

..with the very basic logic of:

However, this is not very basic and happens to be an incredible mess. I’d like to make it more readable.


to build the value up in a sane fashion. This saves a lot of quoting and makes the text much more readable. Note that you can use

instead of

to represent the escape character inside a prompt.

You can define variables for the more esoteric escape sequences, at the cost of needing some extra escapes inside the double quotes, to accommodate parameter expansion.

PS1+=“$white$? „
if [[ $last_command == 0 ]]; then
PS1+=“$green$checkmark „
PS1+=“$red$fancyX „
if [[ $EUID == 0 ]]; then
PS1+=“$red\h „
PS1+=“$green\u@\h „
PS1+=“$blue\w \$$reset „




Example .bash_profile file


30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X

An alias is nothing but shortcut to commands. The alias command allows user to launch any command or group of commands
(including options and filenames) by entering a single word. Use alias command to display list of all defined aliases. You can add user defined aliases to ~/.
bashrc file. You can cut down typing time with these aliases, work smartly, and increase productivity at the command prompt.

More about aliases

The general syntax for the alias command for the bash shell is as follows.

Task: List aliases

Type the following command:

Sample outputs:

By default alias command shows a list of aliases that are defined for the current user.

Task: Define / create an alias (bash syntax)

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:

Task: Disable an alias temporarily (bash syntax)

An alias can be disabled temporarily using the following syntax:

Task: Remove an alias (bash syntax)

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).

Task: Make aliases permanent (bash syntax)

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,

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 uses for aliases

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

#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:

Host server10
IdentityFile ~/backups/.ssh/id_dsa
user foobar
Port 30000
ForwardX11Trusted yes
TCPKeepAlive yes

You can now connect to peer1 using the following syntax:

#30: It’s your turn to share…


This post summaries several types of uses for *nix bash aliases:

  1. Setting default options for a command (e.g. set eth0 as default option – alias ethtool=’ethtool eth0′ ).
  2. Correcting typos (cd.. will act as cd .. via alias cd..=’cd ..‘).
  3. Reducing the amount of typing.
  4. 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‘ ).
  5. Adding the safety nets to Unix by making commands interactive by setting default options. (e.g. rm, mv, and other commands).
  6. Compatibility by creating commands for older operating systems such as MS-DOS or other Unix like operating systems (e.g. alias del=rm ).