Araneo: DevOps & Automation
Araneo: DevOps & Automation
  • Home
  • Concepts
    • Development
  • Articles
  • Blog
  • About
  • Home
  • Concepts
    • Development
  • Articles
  • Blog
  • About

A BLOG

4 Quick Linux Command Line Tips

4/23/2015

2 Comments

 
Today's small blog post will cover four handy tips, which makes your life on a Linux/bash terminal easier and faster!

Search your BASH History on-the-fly

One of the most time-saving features of bash is the "search bash history" quick command Ctrl-r. Find a terminal and see what happens when you issue the command. The prompt will say "(reverese-i-search)". Type in the beginning of a command you have used recently, which had some hard-to-remember extra parameters. This can be a scp-command with that awkward flag for pointing out which certificate to use for the connection, or just finding the path to a script deep in the file-system, which you edited the other day but can't remember where it's located. 

Press ctrl-r and type the first one or two letter of the command that you are looking for, and it will find the last executed command for your user which match. Type more letters to qualify the search even further, or press ctrl-r again, to find the next match.

If you are not already familiar with this, you will ask yourself very soon, how you managed to live without it!

Find and Kill a Background Job the Fast Way

You probably know how to put a process in the background by using "&" after a command. You use the command "jobs" to list the processes that you have put in the background, where each command has it's own unique numerical identifier. This ID can be used to kill the process, using "kill %<id>". See image below.
Kill bg job
Find and kill background jobs.

Show Last Exit Status

Scripts and programs in the unix-styled-world has a tendency not to send unnecessary (or even necessary ) information back to the command line. However, the exit code of a program can tell a a lot about why the program did not execute as expected. It can also be very useful in scripts and automation, to be able to determine specific exit codes.

To check the exit code of the last executed program, use "echo $?". Example

[[email protected] ~]$ ./my_script.sh --option=invalidValue
[[email protected] ~]$ echo $?
4

It's customary in the unix-world that 0 means "program executed successfully", and everything else means that the program failed in some way.

Go to Last Directory

You know what it's like. You're deep into the file-system, in some obscure configuration directory of an application, and just have to go to your home directory to check a config file. Then you need to find your way back, but was it /opt/app/version/config or /var/app/version/config, or....? 

Just use the command "cd -" to go to the directory you were in last!

[[email protected] tmp]$ cd -
/var/www/demoapp/html/api
2 Comments
devops online training link
8/16/2016 07:22:35 am

Thank you very much ! You have cleared out the difference between them.

Reply
devops online training link
2/6/2017 08:49:35 am

Great post, most informative, didn't realise devops were into this.

Reply



Leave a Reply.

    Author

    Hi, I'm Johan, I've been working as a consultant and entrepreneur in the IT-sector since 1999.

    I blog about ideas, tricks and tech tips from my daily work life as solution architect.

    Archives

    April 2016
    March 2016
    February 2016
    May 2015
    April 2015

    Categories

    All
    Atlassian
    CentOS
    Devops
    Git
    LAMP
    Linux
    Scm
    Security
    Svc Virt
    Testing
    Tips N Tricks
    Tips-n-tricks
    Virtualization

    RSS Feed

(cc) Araneo 1999-2016

Privacy Policy | Copyright