Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

shell scripting question

  • 04-12-2002 5:30pm
    #1
    Closed Accounts Posts: 7,230 ✭✭✭


    just wondering how to back up every file in my home directory. What i mean _exactly_ is to add a .bak extension to each file using bash scripting. I can't for the life of me figure this one out. i can do it to a file one by one but i want to do it to every file at once.

    Thanks in advance!@#


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    I don't do much bash scripting, but a cursory examination of the Advanced Bash Scripting Guide gives me something like this:
    #!/bin/sh
    for i in ~/*
    do
            if [ -f "$i" ]
            then
                    cp $i $i.bak
            fi
    done
    exit 0
    
    adam


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    Thanks adam!


  • Registered Users, Registered Users 2 Posts: 432 ✭✭Catch_22


    just to be pedantic your better of using ~/.* instead of ~/* so that you get all the .files (i.e. config files) which ~/* wont match.

    Also if you want to get the subdirectories too do:

    #!/bin/sh
    for file in `find ~ -type f`; do
    cp $file $file.bak
    done

    c22


Advertisement