LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-10-2017, 07:29 PM   #16
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872

Quote:
Originally Posted by r3sistance View Post
But only one of the two missing files is a hidden file, the other file missing which is file1 isn't dot prefixed.
Thanks, r3sistance. That is indeed unusual. :-) I just executed the command on my system and dir1 and file1 were both copied into dir0.

Last edited by hydrurga; 02-10-2017 at 07:31 PM.
 
Old 02-10-2017, 07:32 PM   #17
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
there shouldn't be a difference... you deleted dir0 again and didn't do a mkdir right?
If I deleted the destination folder, dir0, then it works.
Meaning content of dir were copied to dir0.

BUT....
If I create (mkdir) dir0 before cp command, only directories were copied!
What did I missed?
 
Old 02-10-2017, 07:48 PM   #18
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872
In case it has not already been asked of you, which shell (and version) are you using?

echo $0 will give you the shell name.

Your package manager will give you the version e.g. dpkg -l bash

On my system, where the non-hidden directory and file are copied across, but not the hidden file (as I would expect) I'm using Bash 4.3.
 
Old 02-10-2017, 07:49 PM   #19
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,352
Blog Entries: 11

Rep: Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319
If indeed your original post examples are correct, the problem is not with the cp operation:

Code:
#When I use "ls -al dir0" command on dir0, I do not see files, I only see directory.
user1@server1 ~ $ ls -al dir0
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:40 .
drwxr-xr-x 45 user1 user1 4096 Feb 10 14:39 ..
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:36 dir

#BUT if I use "ls -al dir0/*" command on dir0, I see ALL the files.
user1@server1 ~ $ ls -al dir0/*
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:36 .
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:40 ..
drwxr-xr-x 2 user1 user1 4096 Feb 10 11:57 dir1
-rw-r--r-- 1 user1 user1 0 Feb 10 11:56 file1
-rw-r--r-- 1 user1 user1 0 Feb 10 11:55 .hiddenfile1
user1@server1 ~ $

#Now if I cd into dir0, I still do not see all the files using ls -al.
#This does not make sense since I can see ALL files when I do ls -al in my home directory, /home/user1. Why?
user1@server1 ~ $ cd dir0
user1@server1 ~/dir0 $ ls -al
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:40 .
drwxr-xr-x 45 user1 user1 4096 Feb 10 14:39 ..
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:36 dir
All of the red commands should produce the same result.

Filesystem corruption maybe? Or do you have some weird aliases, or symlink or hardlink on those?

What do the following show:

Code:
alias |grep 'ls\|cp'

ls -l ~/ |grep dir
And a little more context: Is this on a local machine or some remote machine? What distro, version, etc.? And as others have asked, what shell?

Last edited by astrogeek; 02-10-2017 at 07:56 PM. Reason: added question
 
Old 02-10-2017, 08:11 PM   #20
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872
Quote:
Originally Posted by astrogeek View Post
All of the red commands should produce the same result.
Not on my system they don't (Mint 18.1, Bash 4.3).

Given the directory contents generated by the OP's commands, the output from the various ls commands in question on my system mimics the OP's. It's just the results of the cp that differ between this system and theirs.
 
1 members found this post helpful.
Old 02-10-2017, 08:21 PM   #21
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,352
Blog Entries: 11

Rep: Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319
I stand corrected!

OK, I see what is happening but will completely form my next thought before posting...
 
Old 02-10-2017, 08:47 PM   #22
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
A thousand apologies.
I took a break... and came back and check my work.
My eyes were playing games on me.
cp does work.
Please ignore my posts about missing files when doing cp.
All your generous posts were correct, except mine!
Sorry again.

Last edited by fanoflq; 02-10-2017 at 08:51 PM.
 
Old 02-10-2017, 08:51 PM   #23
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872
Quote:
Originally Posted by fanoflq View Post
A thousand apologies.
I took a break... and came back and check my work.
My eyes were playing games on me.
cp does work.
Please ignore my post about missing files when doing cp.
All your generous posts were correct, except mine!
Sorry again.
No problem! The most important thing is that your query was solved and that you understand what was happening.
 
1 members found this post helpful.
Old 02-10-2017, 08:55 PM   #24
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,352
Blog Entries: 11

Rep: Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319
This almost looks like a clever juxtaposition of behaviors forming a kind of edge case, but I guess someone has to trip over it eventually.

The confusion results because of the difference between cp -a dir and cp -a dir/*, and because of two different destinations cases: dir0 exists, and dir0 does not exist. Finally, a subtle default behavior of the ls command conspires to further obscure the final result...

First, the behavior of cp:

* When you use cp -a dir you are copying the directory itself, and therefore everything in it, to some destination.
* When you use cp -a dir/* you are copying non-hidden files and directories within dir/ only, hidden files are not copied!

And

* When dir0 exists, the intended behavior of cp is to copy the source, dir, into the destination, dir0
* When dir0 does not exist, cp copies the source directory to a new directory named dir0, not INTO dir0

Clearly this is the observed behavior and others have correctly explained it this way.

Finally, the behavior of ls:

* When ls -al lists the contents of dir0 it lists ., .. and dir/, correctly.
* When ls -al lists the contents of dir0/*, it lists the only non-hidden thing there, dir/, exactly as it should.

BUT - in this last case, when it lists the directory contents, and there is only one directory item, it does not print a heading clearly showing it to be a subdirectory. If you add a visible file in there or another directory, it will clearly add the subdirectory heading.

It is this last condition which is subtle and which we do not often see which allows us to become confused!

As such, I have to think this was a cleverly contrived example. If not, it ought to be!

Fanoflg, where did you find this?

*** I see it is now solved, good luck!

Last edited by astrogeek; 02-10-2017 at 09:05 PM. Reason: typos
 
1 members found this post helpful.
Old 02-10-2017, 09:57 PM   #25
rs2
LQ Newbie
 
Registered: Sep 2007
Location: Indiana
Distribution: Debian
Posts: 12

Rep: Reputation: 1
cp -a will work on all files, including hidden, -a is archive. If you want all the folder "~/dir" with ALL files inside of ~/dir0 -- Try with an ending / and -f, a wildcard isn't necessary here. Are all the files/folders being used with a privileged user / has correct permissions?

cp -af ~/dir/ ~/dir0/

Also consider running the command in verbose(-v) or interactive(-i) for answers.
 
1 members found this post helpful.
Old 02-10-2017, 10:03 PM   #26
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
This almost looks like a clever juxtaposition of behaviors forming a kind of edge case, but I guess someone has to trip over it eventually.

... ... ...
Fanoflg, where did you find this?

*** I see it is now solved, good luck!
Thank you for your analysis.
I did not find it anywhere.
I was learning about cp and decide to make up directories and files for testing.
 
1 members found this post helpful.
Old 02-10-2017, 10:12 PM   #27
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,352
Blog Entries: 11

Rep: Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319
Quote:
Originally Posted by fanoflq View Post
Thank you for your analysis.
I did not find it anywhere.
I was learning about cp and decide to make up directories and files for testing.
Well, it was certainly educational!

It really does create a clever trap for those not paying attention (like me, and should have been).

Glad you found the answer, and thanks to all who helped!
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cygwin simple tar command fails when issues on command line deannad Linux - General 1 06-12-2013 11:22 AM
open xlsm or xls fles under linux by openoffice frhling Linux - General 1 01-07-2013 05:44 AM
How do i configure g++ to look into particular directory to search library fles? sadhup Linux - Newbie 5 05-02-2012 02:06 AM
how can i run bin fles on vector linux bushcat Linux - Newbie 2 03-28-2009 11:25 AM
Any good apps to upload fles to website darin3200 Linux - Software 2 04-15-2003 10:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration