element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Blog Ubuntu Bash Tips and Tricks
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Embedded and Microcontrollers requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: narrucmot
  • Date Created: 26 Feb 2021 5:59 PM Date Created
  • Views 1329 views
  • Likes 5 likes
  • Comments 1 comment
  • Ubuntu
  • linux hacks
  • avnet
  • petalinux
  • xilinx
  • vivado
  • linux administration
  • bash
  • .bashrc
  • git
  • linux
Related
Recommended

Ubuntu Bash Tips and Tricks

narrucmot
narrucmot
26 Feb 2021

I will admit it.  I am sometimes lazy.  And forgetful.  And despite my preference for working at the Linux command line rather than a GUI, I don't really like to type any more than I need to.  It is good to know these things about oneself.  It has also lead me to create and discover some tips and tricks to use in a Ubuntu bash command shell to help my productivity.  Keep in mind the hacks below all require edits to the user .bashrc file (~/.bashrc) and are known to work in Ubuntu 18.04 LTS.  If you aren't comfortable editing the .bashrc file then proceed with caution (and make a backup first!).  Here are a few of my favorites:

  • I mentioned I am lazy and don't like to type any more than I need to.  Setting up command aliases is a great way to minimize what you need to type, especially for commands that you need to run often.  Here are a few of my favorite aliases:
    • This alias only applies to Xilinx users and developers.  Print the Xilinx environment variables to remind me what version of tools my environment is set for.  This is especially handy if you have more than one version of Vivado, etc. installed at one time and often have to work in each of them simultaneously:
      alias pxil='printenv |grep XILINX; printenv |grep PETALINUX; printenv |grep VITIS'
      $ pxil

    • Search through the command history for a particular command.  I mentioned I was forgetful and lazy, and I often forget the exact syntax of a command that I know I have typed before.  I use this alias to help me re-run commands easily ($ !<command number>) or jog my memory for the syntax:
      alias hgrep='history |grep '
      $ hgrep <command name, or string in command>

    • Find out the status of the git repository I am working in.  Do I have any uncommitted changes?
      alias gstat='git status'
      $ gstat

    • What branch am I working on in my git repository?
      alias gbr='git branch'
      $ gbr

    • I often have more than one dev board connected to my PC, and forget which Linux ttyUSB device(s) they are connected to.  Depending on the dev board this command will reply with more than one ttyUSB device per dev board (some dev boards have more than one UART), so I still have to figure out the one I need, but at least this command helps me limit my choices:
      alias lsgusb='ls /dev |grep USB'
      $ lsgusb

    • This alias does the same as searching for attached ttyUSB devices, except for UARTs that are known to Linux as ttyACM devices:
      alias lsgacm='ls /dev |grep ACM'
      $ lsgacm

  • When working in a git repository I have been known to forget what branch I am working in, only to make a change to a source file that I shouldn't have.  This creates extra work to undo a commit or wastes work to have to stash any changes that can't be committed (because I am on the wrong branch).  Thanks to the community at stackoverflow.com there is a hack to the .bashrc file that adds the current git branch to the command line prompt.  This has saved me immeasurable grief from making changes in the wrong branch!  Be careful when making this edit and be sure to backup  your .bashrc file first!
    #https://stackoverflow.com/questions/15883416/adding-git-branch-on-the-bash-command-prompt
    parse_git_branch() {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    }
    if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[32m\]$(parse_git_branch)\[\033[00m\]$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
    fi

  • This hack only applies to Xilinx users and developers.  Here is a hack to add the Xilinx environment variable settings setup scripts so they always run whenever you open a Ubuntu command shell.  Put this at the end of the .bashrc file and edit the path to match where your Xilinx tools are installed:
    #
    # Setup Xilinx environment
    #
    TOOLS_VER=2020.2
    source /path/to/Xilinx/Vitis/$TOOLS_VER/settings64.sh
    source /path/to/Xilinx/Vivado/$TOOLS_VER/settings64.sh
    source /path/to/Xilinx/PetaLinux/$TOOLS_VER/settings.sh

I hope you find these Ubuntu .bashrc hacks, tips, and tricks helpful.  I am interested to know what some of your favorite Ubuntu, Xilinx, and embedded Linux productivity hacks are.  What command aliases, git tricks, etc. make you more productive and you can't work without?  If you have any please leave them in the comments below!

  • Sign in to reply
  • bhfletcher
    bhfletcher over 4 years ago

    I find that sourcing the Xilinx tools settings as you have shown is especially convenient. I like your TOOLS_VER setting as I do have occasion to switch between multiple tool versions that I have installed on my system.

    Thanks, Tom!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube