Find the answer to your Linux question:
Results 1 to 7 of 7
Hey, here is what i'm trying to do: I have a folder that has many subdirectories, and some of the directories contain .html files, and some do not. I want ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    62

    CP command


    Hey, here is what i'm trying to do:
    I have a folder that has many subdirectories, and some of the directories contain .html files, and some do not. I want to sort through all the folders and sub folders and sub folders....etc grab the .html files, and put them in another folder in my home. Heres the script I tried, but it didnt work:

    Code:
    cp -R *.html /home/myusername/extractedhtml/
    It returned
    cp: cannot stat `*.html': No such file or directory

  2. #2
    Linux Enthusiast deltaflyer's Avatar
    Join Date
    May 2005
    Posts
    577
    did you cd to the directory you are copying from before typing that in?

    andy
    SLOMO: acer extensa 5235 2.2ghz,2gb ram 160gb hdd wireless
    SPEEDY: homebrew desktop,Amd x2 dualcore,2gb ram,500gb +1tb( 2x500gb) hdd suse 11.3,32mb fibreline
    registered linux user #401845

  3. #3
    Just Joined!
    Join Date
    Aug 2004
    Posts
    62
    I cd to /downloadedhtml/ which contains many many layers of sub folders, which is where im trying to grab the .html from.

    Let me clarify that sometmes downloadedhtml will not contain any .html files. It will contain a sub folder that contains a .html file though.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Mar 2005
    Posts
    1,431
    Quote Originally Posted by LoafOfBread34
    I cd to /downloadedhtml/ which contains many many layers of sub folders, which is where im trying to grab the .html from.

    Let me clarify that sometmes downloadedhtml will not contain any .html files. It will contain a sub folder that contains a .html file though.
    in that case:
    Code:
    find .|grep .html|xargs cp --target-directory /home/myusername/extractedhtml/

  6. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by jaboua
    Quote Originally Posted by LoafOfBread34
    I cd to /downloadedhtml/ which contains many many layers of sub folders, which is where im trying to grab the .html from.

    Let me clarify that sometmes downloadedhtml will not contain any .html files. It will contain a sub folder that contains a .html file though.
    in that case:
    Code:
    find .|grep .html|xargs cp --target-directory /home/myusername/extractedhtml/
    I'm not convinced that cp will take a source list from its stdin (mine won't).
    Also, please use find properly:
    Code:
    find . -name "*.html" -exec cp -p "{}" /home/myusername/extractedhtml \;

  7. #6
    Linux Engineer
    Join Date
    Mar 2005
    Posts
    1,431
    The command worked here.

    I tried the -name thing, but it wouldn't copy in my test folder - it may be the quotes, I didn't use quotes . The -exec is a new one.

    But xargs doesn't give CP a source list, it splits the source list up and utilise CP with one line at the time.

  8. #7
    Just Joined!
    Join Date
    Aug 2004
    Posts
    62
    THANK YOU. find . -name "*.html" -exec cp -p "{}" /home/myusername/extractedhtml \; works like a charm!

Posting Permissions

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