#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    4
    Rep Power
    0

    Copy files from a dir to a new one


    I need to write a Bourne shell script to do the following:
    (i)Copy a *.java and *.c files in /Home/MyHomeDir to a directory called /Home/MyHomeDir/NewDir

    (ii)Make all the files executable and readable by everyone
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Central Florida, U.S.A.
    Posts
    77
    Rep Power
    11
    #!/bin/sh

    cp $HOME/*.java $HOME/new
    cp $HOME/*.c $HOME/new

    chmod 777 $HOME/new/*.c
    chmod 777 $HOME/new/*.java
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    4
    Rep Power
    0
    Thanks it works perfectly!!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,200
    Rep Power
    14
    this perfecty && accidentally work
    in unix, i would say
    cd #this bingt me to home
    [ -d ../new ] || mkdir ../new || exit 1
    cp *.java *.c ../new
    #he said: executable and readable by everyone
    chmod 755 ../new/*.java ../new/*.c
    ALL other is hazard (but working IN YOUR ENVIRONMENT)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0
    I'm having a similar problem with copying files from one directory to another. It's part of a lab I need to do for school. Now ordinarily, I wouldn't go online looking for an answer to one question, but I am unable to proceed unless I can get past this question. So here it is:

    "Enter a command to copy all files in your home directory beginning with the
    letter 'a' to the current directory."

    For this, I must assume that I am not in my home directory. Also, the question does not specify which directory I'm in- and no, I cannot issue a pwd command to find out where I am.

    I've tried 'cp /home/dreynolds5/a*'; 'cp /home/dreynolds5/[a]*'; 'cp ~dreynolds5/a*'; 'cp ~dreynolds5[a]*'; 'cp ~/a*' and 'cp ~/[a]*'

    As I'm sure you've all figured out, none of those worked. Any sort of help is appreciated.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,467
    Rep Power
    1751
    Your current directory can be referenced by the 'short-cut' of . and your home directory (depending on shell) by ~

    So, try:

    Code:
    cp ~/a* .
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo