Linux Bash usage tips

In this article you will learn some tips related to the use of bash in the main Linux distributions , especially for those who work in environments without access to the Internet and who need more information about certain Linux bash commands.

Linux Bash

Bash, or Bourne- Again- SHell, is the most popular command interpreter that does the “translation” between the “human” language and the language of the operating system. Below are some tips that will help you optimize your daily use.

Install the bash-completion package

First, we recommend installing the bash-completion (bash autocomplete feature) package, which is responsible for autocompleting most native commands on Linux systems. Currently most of the distributions already come with it installed, but otherwise the commands for installing this package according to distribution are mentioned in the section below.

In Ubuntu, Debian, Linux Mint and derivatives run the APT-GET command with sudo.

sudo apt-get install bash-completion

For Fedora, Red Hat and CentOS and derivatives – Run with root or with sudo permission

yum install bash-completion

Right after installing bash-completion , the TAB key will be your best friend. Start typing a command and press the TAB key twice and bash will autocomplete or give you more options about a particular command, for example:

systemctl TAB TAB

In the example above, when typing the command systemctl and pressing TAB twice, bash will present all possible parameters to be used together with systemctl .

Read: How to display Images in the command line in Linux/Ubuntu

Another example is the possibility of autocompleting when browsing between directories:

cd / u TAB
cd / usr /
cd / usr / TAB TAB

Therefore, TAB can “save” the use of your keyboard, making typing much faster.

Search for commands already entered with CTRL + r

A few days ago you typed that gigantic command in bash and you no longer remember what its parameters were, or do you only remember parts of this command?

Hold the CTRL key and then the r key and notice that your bash will look something like the one below:

(reverse-i-search) “:

This is a reverse search where any entry typed in your user’s history will be found. In the example below I will search for the word “box”:

(reverse-i-search) `’:` box’: vagrant box add archlinux / archlinux

The CTRL + r found the last command box with the word used in bash. But if this is not yet the command you are looking for with the word “box”, just press CTRL + r again:

(reverse-i-search) `’:` box’: vagrant box remove centos7

Use and abuse the man command

The man command is responsible for presenting reference manuals about a given command. Certainly a great feature that most users don’t know about is that the man command has its own manual. Then execute the command below in your terminal:

man man

A man reference manual page will open up. Below is an example with the crontab command :

man crontab

Note that the command has a (1), so it indicates that the manual will describe the crontab command and its parameters.

Read: How to tweet from the Linux Command Line

But what if I’m in doubt as to what the syntax of the cron files is like ? Then just access the manual related to “File formats and conventions”, in case number 5:

man 5 crontab

Use the examples in / usr / share / doc

Within the / usr / share / doc directory there is extensive documentation of all packages installed on your operating system. In addition, it has standard configuration files that can help you configure new services. An interesting example is samba-common , which has a smb.conf file as a model:

cd / usr / share / doc / samba-common / examples

sudo gunzip smb.conf.default.gz

cat smb.conf.default

The file has the minimum operating parameters of the samba commented out. So you can use this file as a template to configure samba in /etc/samba/smb.conf .

Read: How to Google search from Linux terminal; Build your own search engine

In summary, although not a bash tutorial, we hope that this article on how to optimize the use of bash will help you in your working and learning journey in the Linux world.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

Leave a Reply