1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Shell Tips & Tricks - Part 2

Discussion in 'Unix' started by pradeep, Aug 20, 2009.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Part I - Shell Tips & Tricks

    Clear and Disable Bash History



    Use the Bash inbuilt history command:

    Code:
    history -c
    To prevent writing of your Bash history to the history when you log out:

    Code:
    unset HISTFILE

    Ampersand (Background Jobs)



    & is a inbuild operator to fork processes.

    "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell"​

    Code:
    [root@pradeep test]# sleep 60 &
    [1] 32739
    
    The process id is stored in a special variable $!
    Code:
    [root@pradeep test]# echo $!
    32739
    
    List all background jobs
    Code:
    [root@pradeep test]# jobs
    [1]+  Running                 sleep 60 &
    
    Killing any background job
    Code:
    [root@pradeep test]# kill %1
    [1]+  Terminated              sleep 60
    

    Search An Replace in vi



    Open a text file in vi/vim and goto command mode by pressing ECS and then ':', the search and replace command will be like,

    Code:
    %s/oldString/NewString/g
    You can also mention which lines should be affected by this, %s means all lines.

    Code:
    5,10 s/oldString/NewString/g
    This will tell vi to make do replacing in lines 5 to 10. You may also use regex in your search expression.
     
  2. asha

    asha New Member

    Joined:
    Nov 9, 2006
    Messages:
    44
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Homemaker
    Location:
    Kolkata
    Home Page:
    Cool, the history one was really nice, it really helps me ;-)
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83

Share This Page