Hello Linux-Fanatics, this post is dedicated to those users who are just getting started with their Linux Journey. I am sharing some Bash tips tricks which will make you more familiar with BASH & get you started on your long and very interesting journey on becoming a Linux Pro.

(Recommended Read : Complete guide for mounting drives in RHEL/CentOS )

 

Tab Completion

Tab completion is nice & very useful feature of BASH. It helps you to complete your command which not only helps when you forget complete command but also when you just want to write your command fast.

So to use it just start typing your command , lets say we want to open a folder named this_is_really_long_file_name located at /etc directory.

BASH tips & tricks

So we just type vi /etc/this and press “tab” key, which will complete the address for you.

 

Finding a Command

 A BASH has thousands of commands & to remember all of those commands is an impossible task. So what to do when you can’t remember a command to accomplish a task. Don’t worry, just remember one command “apropos”.

To use it just type apropos “command description”

Ex:-  apropos “list files” & viola we will have a command that we can use.

Bash tips & Tricks

 

Running a previous command

To see & execute a previously used command, we use history command . This will produce a list of all previously executed commands on screen & we can than see & re-run the required command.

BASH Tips & Tricks

Alternatively, we can also use UP arrow key, until we have the command needed.

 

Locating a file

We have a number of files in our system, & sometimes it happens we forget the location to a file. We have all been there but rather looking for file in all folder, we can use locate command to locate the file required.

Example   locate ifcfg

BASH tips & tricks

Note:- We need mlocate package to run locate command.

We can also use find command to locate the files & directories.

 

Find files & directories

Find command is very useful utility to learn. A number of options can used with Find to refine our search . Some examples are shared here:-

1- find /etc -type f will find all files in /etc. For all directories use “-type d

2- We can further refine search made by above command find /etc -type f -size 20M , it will search all files in /etc/with filesize of 20 Megabytes.

BASH Tips & tricks

There are a number of other options which can be used. For further details refer to man pages for find command. Also I would share a dedicated post on find command (yes, its thats useful that it deserves a dedicated post)

Some keyboard Shortcuts

  • Alt+Backspace: Deletes the previous word.
  • Alt+F: Skips ahead to the next space.
  • Alt+B: Skips back to the previous space.
  • Ctrl+R: with partial command searches for the full command.
  • Ctrl+U: Cuts all text up to the cursor.
  • Ctrl+K: Cuts all text after the cursor until end of line.
  • Ctrl+A: Moves the cursor to the start of line.
  • Ctrl+E: Moves the cursor to the end of line.

 

So, that’s all for now on our tutorial on bash tips tricks. I will writing some more bash tips tricks in our future posts which will help you guys. In meanwhile you can also read my posts on Important Commands used in BASH Part1 & Part2 .

Please feel free for suggestions/queries, I will surely respond to all the suggestions/queries.

 

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.