Linux [~/.bashrc] File

Linux [~/.bashrc] File


This post is intended to show how to interact with the different settings this file offers. Some of the settings that will be discussed here are

  1. How to display the server user name in the prompt
  2. How to make aliases (or embedded functions) to interact with the console easily.

I use Docker as a practical example to build functions in the CentOS console. I usually like to make tables where I can see information that I am interested in from the command "docker ps", that is the main reason why I build my functions.


User Name Display

  • First, run the vi ~/.bashrc command to access the settings file
  • After getting access, add the next line of code to display the user name This is an environment variable to fix the user name at the console

PS1='\\u@\\h \\w \\$ '
        

Make Aliases

  • First, run the vi ~/.bashrc command to access the settings file
  • After getting access, add the next line of code for the desired function or “alias”

# Format
alias new_command_name = '{the command I want to shorcut}'

# Example
alias docker_all      ='docker ps --format "table {{.Names}}\\t{{.Status}}" -a'
alias docker_active   ='docker ps --format "table {{.Names}}\\t{{.Status}}"'
alias docker_all_size ='docker ps --format "table {{.Names}}\\t{{.Size}}" --size -a'        

After Changes

  • When changes are effectuated in the ./~bashrc file, you must run the next command to update the shell

source ~/.bashrc        

References

  1. What is .bashrc file in Linux?
  2. What is the purpose of .bashrc and how does it work?
  3. Guide for making functions with .bashrc


#linux #centos #bashscripting #shellscripting #docker #guide #programming #servermanagement

要查看或添加评论,请登录

Humberto Villalta的更多文章

  • Network Configuration

    Network Configuration

    Try the following steps to reset the server’s internet connection: Before Starting…. To see which file is connected to…

  • How to Push Local Repo Code into Github Repo

    How to Push Local Repo Code into Github Repo

    This guide is intended to show how to push code from our local computer to a GitHub repository. Step 1 Open the Git…

  • HDFS Clustering Through Docker in CentOS

    HDFS Clustering Through Docker in CentOS

    Overview This guide will show you how to deploy a distributed file system for Hadoop (HDFS). We will first make a…

  • Redis Integration with Python

    Redis Integration with Python

    Overview This guide is made for those who want to install Redis in a Centos 7 docker container and to integrate Python.…

  • What is Redis?

    What is Redis?

    Overview Redis is a C programming written REmote DIctionary Server developed in 2006. Redis read and write operations…

  • How to Set a Virtual Machine in Windows OS

    How to Set a Virtual Machine in Windows OS

    Overview Installing a virtual machine on a Windows operating system seems to be the easiest and most basic process that…

    2 条评论
  • Spacetime Data Hub Technology Connecting the Physical and Digital Worlds

    Spacetime Data Hub Technology Connecting the Physical and Digital Worlds

    The advancement of IT technology has enabled people to project physical spaces into virtual spaces known as “digital…

  • Python Decorator Introduction with Examples

    Python Decorator Introduction with Examples

    1. Overview The decorator pattern is a software design pattern that allows us to dynamically add functionality to…

  • HyperLogLog Basics

    HyperLogLog Basics

    Overview Probabilistic data structures are very well-known because of their outstanding time and space complexity among…

  • Cuckoo Index

    Cuckoo Index

    1. Overview Cuckoo hashing is used as a solution for hash collisions, and its worst-case lookup time is constant O(1).

社区洞察

其他会员也浏览了