You are not logged in.

#1 2009-03-20 04:34:48

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

a quick question about cp

I only want to copy files...
when you copy the entire content of a directory which contains files and subdirectories, you get the following message (without recursion of course):

cp: omitting directory `blablabla'

is there a way to "mute" this message? i know i can redirect stdout and stderr, but i thought there must be a more efficient way. or better yet can i supply all the normal files in the dir as cp's arguments instead of *? if so, how?

thanks

Offline

#2 2009-03-20 04:58:44

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: a quick question about cp

What is inefficient about redirecting stderr? Apart from obviously missing out on any other error messages...

Can you give us an example of the problem -- I don't quite understand what you're trying to achieve...

Offline

#3 2009-03-20 05:09:20

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

Re: a quick question about cp

i'm trying to copy all the files in a directory without copying the sub-directories
examaple:

[sulaiman@PINK ~]$ mkdir ./tester 
[sulaiman@PINK ~]$ mkdir ./tester/sub-test
[sulaiman@PINK ~]$ mkdir ./tester/sub-test2
[sulaiman@PINK ~]$ cd tester
[sulaiman@PINK tester]$ touch a s d f g
[sulaiman@PINK tester]$ ls
a  d  f  g  s  sub-test  sub-test2
[sulaiman@PINK tester]$ cp * sub-test
cp: omitting directory `sub-test'
cp: omitting directory `sub-test2'
[sulaiman@PINK tester]$

i don't want to copy the dirs in the first place but specifying the files one by one is not an option

Offline

#4 2009-03-20 06:53:55

bangkok_manouel
Member
From: indicates a starting point
Registered: 2005-02-07
Posts: 1,556

Re: a quick question about cp

pedobear109.png

Offline

#5 2009-03-20 07:16:30

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

Re: a quick question about cp

wtf?!!

Offline

#6 2009-03-20 07:17:33

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

Re: a quick question about cp

guys, seriously.. i need to know.
ps: funny, just got it. nice one bangkok_manouel smile

Last edited by SIGTERMer (2009-03-20 07:22:49)

Offline

#7 2009-03-20 07:40:58

djgera
Developer
From: Buenos Aires - Argentina
Registered: 2008-12-24
Posts: 723
Website

Re: a quick question about cp

For example... but do a more work, many syscalls.

find -maxdepth 1 -type f ! -name '.*' -exec cp {} hola/ \;

hola/ is a directory.
! -name ',*' omits dot-files (hidden files)
-type f only find regular files
-maxdepth 1 , don't recurse


The "osito" is funny hahah tongue
(osito == bear)

Offline

#8 2009-03-20 07:41:23

fumbles
Member
Registered: 2006-12-22
Posts: 246

Re: a quick question about cp

see above

Last edited by fumbles (2009-03-20 07:43:51)

Offline

#9 2009-03-20 07:49:47

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

Re: a quick question about cp

from the looks of it, i'll go with redirecting. loops & find are the exact opesite of what i was looking for. but thanks anyways smile

Offline

#10 2009-03-20 12:04:30

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: a quick question about cp

I see what you did there


neutral

Offline

#11 2009-03-20 13:14:51

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: a quick question about cp

Sandman, I just have to ask. I have been struggling to figure out your avatar now for quite some time.
Is it a fist wrapped in bandages?

Offline

#12 2009-03-20 13:24:04

foxbunny
Member
From: Serbia
Registered: 2006-10-31
Posts: 759
Website

Re: a quick question about cp

SIGTERMer wrote:

from the looks of it, i'll go with redirecting. loops & find are the exact opesite of what i was looking for. but thanks anyways smile

You could just create an alias for the command suggested above your post, and then use that if you don't like to miss other errors.

alias cpnd="find -maxdepth 1 -type f ! -name '.*' -exec cp {} hola/ \;"

Hmm... now that I look at it, the alias is not correct. Maybe a bash script would be better, though.

Last edited by foxbunny (2009-03-20 13:27:41)

Offline

#13 2009-03-20 15:44:49

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: a quick question about cp

I still don't get this completely.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#14 2009-03-20 17:05:15

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: a quick question about cp

Misfit138 wrote:

Sandman, I just have to ask. I have been struggling to figure out your avatar now for quite some time.
Is it a fist wrapped in bandages?

Looks like two people holding hands to me...


.:[My Blog] || [My GitHub]:.

Offline

#15 2009-03-20 17:14:36

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

Re: a quick question about cp

haxit wrote:

I still don't get this completely.

http://www.youtube.com/watch?v=dh6wtATgJRs & touch(1)... you put them together smile

why am i feeling like a 12 year old?

Last edited by SIGTERMer (2009-03-20 17:19:16)

Offline

#16 2009-03-20 17:52:02

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: a quick question about cp

SIGTERMer wrote:
haxit wrote:

I still don't get this completely.

http://www.youtube.com/watch?v=dh6wtATgJRs & touch(1)... you put them together smile

why am i feeling like a 12 year old?

That is what I thought....


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#17 2009-03-20 18:01:01

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: a quick question about cp

lol @ pedobear

reminds a bit of the "Sexual Harassment Panda" from South Park smile


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#18 2009-03-21 12:33:34

kgas
Member
From: Qatar
Registered: 2008-11-08
Posts: 718

Re: a quick question about cp

+1 Bangkog_manouel

Hello SIGTERmer this is the behaviour of cp and google search  will give tons of results smile  One way to avoid this error is to  redirect the error as fukawi2 said. The other way is to write your own bash script. I wrote a quick script and if you need you can polish it.
Note: For directory entry  don't use any / or wild card characters at the end ie blah/* or bla/  only use path/to/directroy

#! /bin/bash
# copies only files from the source directory
# to the target directory....
#
#checks the source and Target
#

if [  "$1" == "" ]  && [ "$2"=="" ];

  then

     echo " Usage: cpnd <Source Directory> <Target Directroy> "
    exit 0

fi

if [ ! -d $1 ] ;

  then

    echo " $1 is not a Directory" 

     exit 1

 fi

 if  [ ! -d $2 ];

   then

    echo "$2 is not a Directory"

     exit 2

fi

echo Preparing for copying....

   Target=$2    

 for x in  $(ls  $1);

   do

   source=$1/$x

 
  if [ ! -d $source ]; then

      cp   $source $2

        
       fi


  done
   
    echo File copying completed...

 exit 0

.

Last edited by kgas (2009-03-21 12:35:58)

Offline

#19 2009-03-21 14:24:23

SIGTERMer
Member
From: South Sura, Kuwait
Registered: 2009-01-24
Posts: 41
Website

Re: a quick question about cp

kgas wrote:

+1 Bangkog_manouel

Hello SIGTERmer this is the behaviour of cp and google search  will give tons of results smile  One way to avoid this error is to  redirect the error as fukawi2 said. The other way is to write your own bash script. I wrote a quick script and if you need you can polish it.
Note: For directory entry  don't use any / or wild card characters at the end ie blah/* or bla/  only use path/to/directroy

#! /bin/bash
# copies only files from the source directory
# to the target directory....
#
#checks the source and Target
#

if [  "$1" == "" ]  && [ "$2"=="" ];

  then

     echo " Usage: cpnd <Source Directory> <Target Directroy> "
    exit 0

fi

if [ ! -d $1 ] ;

  then

    echo " $1 is not a Directory" 

     exit 1

 fi

 if  [ ! -d $2 ];

   then

    echo "$2 is not a Directory"

     exit 2

fi

echo Preparing for copying....

   Target=$2    

 for x in  $(ls  $1);

   do

   source=$1/$x

 
  if [ ! -d $source ]; then

      cp   $source $2

        
       fi


  done
   
    echo File copying completed...

 exit 0

.

kgas, i was looking for something more in the line of * (a wild card for regular files) but it seems that the most officiant way is to simply copy everything and ignore the warnings (/dev/null). but thanks anyways smile

Offline

Board footer

Powered by FluxBB