How to clear Terminal / Shell history in Ubuntu / Linux ?

When you type something on linux shell, by default Linux save the commands what you type as history to “~/.bash_history” or /home/username/.bash_history file so that you can easily check what you have typed previously using “history” command. $ history | tail 1998 sudo apt-get install mdns 1999 sudo apt-get install mdns-scan 2000 sudo mdns-scan As … Read more

Multiple line comment in bash / shell script

In bash script, if we want to comment a single line, we just need to add # at the start of the line, like below Now, but in certain scenarios we need to put multiple line comments, like some description of what the script is for, OR just need to disable some section of code … Read more

Shell script to check if Android device is connected over USB

Android devices has a daemon adbd which helps it to get connected over USB using adb command on linux host. If you are doing some kind of automation such as taking logs or installing some applications from ubuntu command line, the very first thing we need to make sure if our device is connected and … Read more

Shell script to check and mount a partition in Ubuntu

In the following script we check whether the current device is mounted or not by reading information from proc file /proc/mounts, if the device is not mounted, we use the “mount” command with sudo / superuser permission to mount the device to mount directory as mentioned in the beginning of script. $ vim script_to_check_and_mount_parition.bash

Shell script to find a file and delete from a directory

Below shell script will find and delete certain file or multiple files from the directory you want. We have used current directory from where script is run, you need to change DIR_TO_SEARCH and FILE_TO_SEARCH_N_DEL from below script. $ vim script_to_find_and_delete_file.sh $ cd to_your_directory $ bash script_to_find_and_delete_file.sh

shell script to check if file is present or not in a directory

Open your favorite editor and create a script as below, Now, lets say you want to search myfile.pdf in a big list of files in a directory, then cd to that directory, copy this script there, and run the script as, $ bash script_to_check_file.sh myfile.pdf