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

    Join Date
    Dec 2004
    Posts
    49
    Rep Power
    13

    loop shell for beginners


    i'm new in shell programming.
    let say i have this file in directory
    file1.txt.
    file2.txt
    sample1.txt
    sample2.txt

    so,i want to move file that begin with name"file" to another directory.so how is it?
    help me please
  2. #2
  3. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    113
    Originally Posted by izza_azhar
    i'm new in shell programming.
    let say i have this file in directory
    file1.txt.
    file2.txt
    sample1.txt
    sample2.txt

    so,i want to move file that begin with name"file" to another directory.so how is it?
    help me please
    Dude, you don´t have to write a programme to do this. These jobs can usually be done on the command line. I don´t have a unix terminal handy, so I can´t test these commands, but to move all the files beginning with ´file´into the directory ´/tmp´ you need to use something like:

    ls -al | grep "file" | xargs mv /tmp

    or to run recursively. use the find command with exec:

    find . -name "file*" -exec mv /tmp {} \;

    Note, I havn´t tested these, so have a play on some dummy files & directories first

    christo
    This is me: http://chris.uk.com

IMN logo majestic logo threadwatch logo seochat tools logo