Results 1 to 4 of 4

Thread: Moving folders...

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Beans
    34

    Question Moving folders...

    This should be easy, but maybe not.

    I want to move about 10 folders that are in a sub-folder (x).

    In x there are also some files that I do not want to copy.

    Looks like this

    ls x

    folder 1
    folder 2
    ...
    folder 10
    file 1
    file 2
    file 3

    now, using nautilus, i could do this in 2 seconds, but i am trying to learn the command line, and I cant find the answer.

    I have googled and used my books, but all i see is how to move the folders and files, or one at a time, but not how to exclude the files!

    argh!

    any ideas?

    Thanks!

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,697
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Moving folders...

    You need a little script to do that:
    Code:
    for f in *; do
        if [ -d "$f" ]; then
            mv -- "$f" /path/to/destination
        fi
    done
    Basically: for every entry in the directory check if it is a directory. If it is, move it to another location.

    Hope it helps,
    Regards.

  3. #3
    Join Date
    Oct 2009
    Beans
    2,199
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Moving folders...

    find x/* -prune -type d -exec mv '{}' new_directory \;

    The new_directory must already exist
    Last edited by YesWeCan; September 8th, 2011 at 05:34 PM. Reason: prune required.
    ASRock P67 Extreme6, Intel i5 2500K, 8GB RAM, nVidia 6600GT, 4x1TB RAID1+0

  4. #4
    Join Date
    Oct 2007
    Location
    $HOME
    Beans
    631

    Re: Moving folders...

    Code:
    mv x/*(/) /where/you/want/to/copy/
    Note: This works in zsh alright. Not tested for other shells.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •