1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Bash Simple Tricks (Continuation) - Part 3

Discussion in 'Unix' started by lionaneesh, Feb 15, 2011.

  1. lionaneesh

    lionaneesh New Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    India
    This is continuation of my previous articles .. Please don't miss them :-

    1. Bash Simple Tricks
    2. Bash Simple Tricks (continuation)
    Again I am following a question – solution approach to demonstrate my scripts..

    Scripts



    How to 'cat'(print) all the files in a folder

    Solution :-

    Code:
    #!/bin/bash 
    
    cat `ls` 
    
    ls output :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ ls 
    char2.sh  displayA.sh  endZ.sh  file1  ls.sh  vovelFile.sh 
    
    Running :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ ./ls.sh 
    #!/bin/bash 
    
    cat $1 | grep '..[eE]' | wc -l 
    #!/bin/bash 
    
    cat $1 | grep ^[aA] | wc -l 
    #!/bin/bash 
    
    cat $1 | grep [z]$ | wc -l 
    aaessss 
    aaaesss 
    aaaaaaaa 
    lionaneesh 
    ssssssssss 
    #!/bin/bash 
    
    cat `ls` 
    #!/bin/bash 
    
    ls | grep ^[aeiouAEIOU] | wc -l 
    
    cat(Print) all the .txt files in a folder

    Solution :-
    Code:
    #!/bin/bash 
    
    cat `ls | grep .txt` 
    
    ls output :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ ls 
    char2.sh     endZ.sh  ls.sh     txt2.txt  vovelFile.sh 
    displayA.sh  file1    txt1.txt  txt.sh 
    
    Using :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ sh txt.sh 
    WOOOOOOWWWWWW!!! 
    
    Its file no 1 named txt1 
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
    Hello !!!!!! Hi Wassup 
    
    This is file no 2 named txt2 
    
    Write a bash script to display todays date and time..
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ cat date.sh 
    
    #!/bin/bash
    
    echo "Today is `date`"
    
    Using :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ chmod +x date.sh 
    
    aneesh@aneesh-laptop:~/articles/Bash$ ./date.sh
    
    Today is Tue Feb 15 22:23:57 IST 2011
    
    Write a bash script to output the date and time in audio format(speak)
    Code:
    #!/bin/bash
    
    espeak "Today is `date`"
    
    Using :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ chmod +x date2.sh 
    
    aneesh@aneesh-laptop:~/articles/Bash$ ./date2.sh
    
    Write a bash script to maximize all the windows opened after a specified no of seconds..

    Solution :-
    Code:
    #!/bin/bash
    
    sleep $1
    
    maximus
    
    Using :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ chmod +x maximise.sh 
    
    aneesh@aneesh-laptop:~/articles/Bash$ ./maximise.sh 2
    
    How to download youtube videos with bash ?
    Code:
    #!/bin/bash
    
    youtube-dl $1
    
    Using :-
    Code:
    aneesh@aneesh-laptop:~/articles/Bash$ chmod +x youtube.sh 
    
    aneesh@aneesh-laptop:~/articles/Bash$ ./youtube.sh http://www.youtube.com/watch?v=m8Dd7rjmEW4
    
     
  2. lionaneesh

    lionaneesh New Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    India
    If you are viewing this article leave a comment whether you like it or not...Or what you want more from the article...Etc..etc...
     
  3. humpakistani

    humpakistani New Member

    Joined:
    Mar 18, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    yes i have try the last one and i think that was the best according to me
     
  4. lionaneesh

    lionaneesh New Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    India
    Downloading videos!!
    yeah!! Its good!
     

Share This Page