Bash script recursively find all files in directory

Bash script recursively find all files in current and subfolders based on wildcard matching, you can use find normally but tree with -P option is easier to read. find will find all files that match a pattern: find . -name “*foo” However, if you want a picture: tree -P “*foo” Hope this helps!

Bash script arguments example

In this post, I will shortly share Bash script arguments via an easy example so it can help you understand how it works and write a bash script with parameters input from command line in terminal. Let’s imagine the following command line: [[email protected] me]$ your_bash_program word1 word2 word3 If your_bash_program were a bash shell script, we could read…

Bash script for loop

This type of for bash script for loop is characterized by counting. The range is specified by a beginning (#1) and ending number (#5). The for loop executes a sequence of commands for each member in a list of items. A representative example in BASH is as follows to display welcome message 5 times with…

Bash script while loop

Bash script while loop is one of the most fundamental and powerful constructs computing because it allows us to repeat a set of commands, as many times as we want, upon a list of items of our choosing. The loop is how we make the computer do that repetitive work #!/bin/bash # while-read: read lines from a…

Bash script check a valid phone number

We are given a text file calledsample.txt that contains la ist of phone numbers ( each is per line), we will write a bash script to check which one is a valid phone numbers. Valid phone number format as: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit) You may also assume each line in the…

Bash script to count the frequency of each word in a text file

Linux shell — text processing — Write a bash script to count the frequency of each word in a text file cat words.txt | tr [:space:] “\n” | sed ‘/^$/d’ | tr ‘[:upper:]’ ‘[:lower:]’|sort|uniq -c|sort -nr| awk ‘{print $2″ “$1}’ Explanation: cat: open content tr: replace all space with a newline ( all words will be as one line…