adding extension

Posted on 2006-05-16
Last Modified: 2010-04-20
hi! i need to write a shell script which checks whether a given file exists. If the file exists add the extension ".bak" at the end of the file name.
Question by:btocakci
    LVL 45

    Accepted Solution

    Hi btocakci,

    First argument to the script is name of the file to which extension is to be added
    if [ -f "$1" ]
         mv $1 $1.bak

    LVL 8

    Expert Comment


    find / -name filename -exec mv '{}' '{}'.bak \;

    Author Comment

    sunnycoder i am sorry to make you spend time by these beginner qoestions but
    how can i use this script for exxample i have a file as "btocakci" ..
    what should i write to terminal?
    LVL 45

    Expert Comment

    suppose you named the script as
    After giving it execute permissions, you need to invoke it as

    /path/to/  /path/to/btocakci

    paths can be absolute or relative

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
    Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now