How can an interactive script move multiple files from one directory to another?how to rename and move files according to directory names?Bash script to move filesHow I can monitor new files in a directory and move/rename them into another directory?Move files from specifically named folders / move files up one levelmoving the file from one folder to another folderChange Encoding and Move Files in ONE bash ScriptHow can I move all java source files to their respective package directory?How can I move content of a txt file to another using Bash Script?Create bash script that allows you to choose multiple options instead of just one?

A Society Built Around Theft?

Calculate the shadow on earth of a large orbital disk

Did Feynman cite a fallacy about only circles having the same width in all directions as a reason for the Challenger disaster?

Self organizing bonuses?

Based on true story rules

A variant of the Shortest Path Problem

I'm largest when I'm five, what am I?

Make Leaflet polyline bold by hover?

Can you use wish to cast a level 9 spell?

Why is it so hard to land on the Moon?

Why are seats at the rear of a plane sometimes unavailable even though many other seats are available in the plane?

Why is matter-antimatter asymmetry surprising, if asymmetry can be generated by a random walk in which particles go into black holes?

What is the meaning of "shop-wise" in "… and talk turned shop-wise"?

Does these arithmetic means on Pythagorean triangles converge?

How do I weigh a kitchen island to determine what size castors to get?

Should a grammatical article be a part of a web link anchor

Little Endian Number to String Conversion

Drawing Super Mario Bros.....in LaTeX

Is consistent disregard for students' time "normal" in undergraduate research?

What is the word for things that work even when they aren't working - e.g escalators?

Slow coworker receiving compliments while I receive complaints

Can the bass be used instead of drums?

What good is Divine Sense?

An employee has low self-confidence, and is performing poorly. How can I help?



How can an interactive script move multiple files from one directory to another?


how to rename and move files according to directory names?Bash script to move filesHow I can monitor new files in a directory and move/rename them into another directory?Move files from specifically named folders / move files up one levelmoving the file from one folder to another folderChange Encoding and Move Files in ONE bash ScriptHow can I move all java source files to their respective package directory?How can I move content of a txt file to another using Bash Script?Create bash script that allows you to choose multiple options instead of just one?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0

















I'm trying to write a shell script that moves multiple files in a directory to another directory. I was able to write a script that asks the user what file they want to move and then moves that file to the target directory, but how can I move multiple files to another directory?



Here is the script I wrote for a user to move one file to another directory:



#! /bin/bash
echo " enter the name of the file that you want to move "
read filename
if [ -f "$filename" ]
then
echo " enter the target directoy name that you want to move the file to"
read dir
if [ -d "$dir" ]
then
mv -i "$filename" "$dir" && echo "the file is moved to "$dir" successfully "


else
echo "the directory is not found"
fi
else
echo "the file is not found !"

exit 1
fi










share|improve this question























  • 2





    Why do you need to write a script if a move operation is easily done by the mv command?

    – Philippe Delteil
    Apr 21 at 16:19






  • 1





    Plus this errors out on dirs not owned by the user :P

    – Rinzwind
    Apr 21 at 16:21











  • Please indent your code correct.

    – Cyrus
    Apr 22 at 6:56

















0

















I'm trying to write a shell script that moves multiple files in a directory to another directory. I was able to write a script that asks the user what file they want to move and then moves that file to the target directory, but how can I move multiple files to another directory?



Here is the script I wrote for a user to move one file to another directory:



#! /bin/bash
echo " enter the name of the file that you want to move "
read filename
if [ -f "$filename" ]
then
echo " enter the target directoy name that you want to move the file to"
read dir
if [ -d "$dir" ]
then
mv -i "$filename" "$dir" && echo "the file is moved to "$dir" successfully "


else
echo "the directory is not found"
fi
else
echo "the file is not found !"

exit 1
fi










share|improve this question























  • 2





    Why do you need to write a script if a move operation is easily done by the mv command?

    – Philippe Delteil
    Apr 21 at 16:19






  • 1





    Plus this errors out on dirs not owned by the user :P

    – Rinzwind
    Apr 21 at 16:21











  • Please indent your code correct.

    – Cyrus
    Apr 22 at 6:56













0












0








0








I'm trying to write a shell script that moves multiple files in a directory to another directory. I was able to write a script that asks the user what file they want to move and then moves that file to the target directory, but how can I move multiple files to another directory?



Here is the script I wrote for a user to move one file to another directory:



#! /bin/bash
echo " enter the name of the file that you want to move "
read filename
if [ -f "$filename" ]
then
echo " enter the target directoy name that you want to move the file to"
read dir
if [ -d "$dir" ]
then
mv -i "$filename" "$dir" && echo "the file is moved to "$dir" successfully "


else
echo "the directory is not found"
fi
else
echo "the file is not found !"

exit 1
fi










share|improve this question
















I'm trying to write a shell script that moves multiple files in a directory to another directory. I was able to write a script that asks the user what file they want to move and then moves that file to the target directory, but how can I move multiple files to another directory?



Here is the script I wrote for a user to move one file to another directory:



#! /bin/bash
echo " enter the name of the file that you want to move "
read filename
if [ -f "$filename" ]
then
echo " enter the target directoy name that you want to move the file to"
read dir
if [ -d "$dir" ]
then
mv -i "$filename" "$dir" && echo "the file is moved to "$dir" successfully "


else
echo "the directory is not found"
fi
else
echo "the file is not found !"

exit 1
fi







bash scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question



share|improve this question








edited Apr 22 at 14:18







EddieInso

















asked Apr 21 at 16:11









EddieInsoEddieInso

11 bronze badge




11 bronze badge










  • 2





    Why do you need to write a script if a move operation is easily done by the mv command?

    – Philippe Delteil
    Apr 21 at 16:19






  • 1





    Plus this errors out on dirs not owned by the user :P

    – Rinzwind
    Apr 21 at 16:21











  • Please indent your code correct.

    – Cyrus
    Apr 22 at 6:56












  • 2





    Why do you need to write a script if a move operation is easily done by the mv command?

    – Philippe Delteil
    Apr 21 at 16:19






  • 1





    Plus this errors out on dirs not owned by the user :P

    – Rinzwind
    Apr 21 at 16:21











  • Please indent your code correct.

    – Cyrus
    Apr 22 at 6:56







2




2





Why do you need to write a script if a move operation is easily done by the mv command?

– Philippe Delteil
Apr 21 at 16:19





Why do you need to write a script if a move operation is easily done by the mv command?

– Philippe Delteil
Apr 21 at 16:19




1




1





Plus this errors out on dirs not owned by the user :P

– Rinzwind
Apr 21 at 16:21





Plus this errors out on dirs not owned by the user :P

– Rinzwind
Apr 21 at 16:21













Please indent your code correct.

– Cyrus
Apr 22 at 6:56





Please indent your code correct.

– Cyrus
Apr 22 at 6:56










1 Answer
1






active

oldest

votes


















0


















This script loop over all files in current directory, and ask to move to specified directory:



#!/usr/bin/env bash

set -e

read -p "enter the target directoy name:" -r dir
if [[ ! -d "$dir" ]];then
echo "incorrect directory"
exit 1
fi
if [[ ! -w "$dir" ]];then
echo "directory is not writeable by current user"
exit 1
fi

for filename in ./*; do
[[ ! -w $filename ]] && echo "$filename cant be moved, access denied" && continue
read -p "move $filename to directory? [y/Enter=No]" domove
[[ ! -z "$domove" ]] && mv -i "$filename" "$dir" && echo "$filename moved successfully" || true
done





share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1135815%2fhow-can-an-interactive-script-move-multiple-files-from-one-directory-to-another%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0


















    This script loop over all files in current directory, and ask to move to specified directory:



    #!/usr/bin/env bash

    set -e

    read -p "enter the target directoy name:" -r dir
    if [[ ! -d "$dir" ]];then
    echo "incorrect directory"
    exit 1
    fi
    if [[ ! -w "$dir" ]];then
    echo "directory is not writeable by current user"
    exit 1
    fi

    for filename in ./*; do
    [[ ! -w $filename ]] && echo "$filename cant be moved, access denied" && continue
    read -p "move $filename to directory? [y/Enter=No]" domove
    [[ ! -z "$domove" ]] && mv -i "$filename" "$dir" && echo "$filename moved successfully" || true
    done





    share|improve this answer






























      0


















      This script loop over all files in current directory, and ask to move to specified directory:



      #!/usr/bin/env bash

      set -e

      read -p "enter the target directoy name:" -r dir
      if [[ ! -d "$dir" ]];then
      echo "incorrect directory"
      exit 1
      fi
      if [[ ! -w "$dir" ]];then
      echo "directory is not writeable by current user"
      exit 1
      fi

      for filename in ./*; do
      [[ ! -w $filename ]] && echo "$filename cant be moved, access denied" && continue
      read -p "move $filename to directory? [y/Enter=No]" domove
      [[ ! -z "$domove" ]] && mv -i "$filename" "$dir" && echo "$filename moved successfully" || true
      done





      share|improve this answer




























        0














        0










        0









        This script loop over all files in current directory, and ask to move to specified directory:



        #!/usr/bin/env bash

        set -e

        read -p "enter the target directoy name:" -r dir
        if [[ ! -d "$dir" ]];then
        echo "incorrect directory"
        exit 1
        fi
        if [[ ! -w "$dir" ]];then
        echo "directory is not writeable by current user"
        exit 1
        fi

        for filename in ./*; do
        [[ ! -w $filename ]] && echo "$filename cant be moved, access denied" && continue
        read -p "move $filename to directory? [y/Enter=No]" domove
        [[ ! -z "$domove" ]] && mv -i "$filename" "$dir" && echo "$filename moved successfully" || true
        done





        share|improve this answer














        This script loop over all files in current directory, and ask to move to specified directory:



        #!/usr/bin/env bash

        set -e

        read -p "enter the target directoy name:" -r dir
        if [[ ! -d "$dir" ]];then
        echo "incorrect directory"
        exit 1
        fi
        if [[ ! -w "$dir" ]];then
        echo "directory is not writeable by current user"
        exit 1
        fi

        for filename in ./*; do
        [[ ! -w $filename ]] && echo "$filename cant be moved, access denied" && continue
        read -p "move $filename to directory? [y/Enter=No]" domove
        [[ ! -z "$domove" ]] && mv -i "$filename" "$dir" && echo "$filename moved successfully" || true
        done






        share|improve this answer













        share|improve this answer




        share|improve this answer



        share|improve this answer










        answered Apr 21 at 18:29









        LeonidMewLeonidMew

        1,97512 silver badges27 bronze badges




        1,97512 silver badges27 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1135815%2fhow-can-an-interactive-script-move-multiple-files-from-one-directory-to-another%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Tamil (spriik) Luke uk diar | Nawigatjuun

            Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

            Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?