LinuxQuestions.org
Review your favorite Linux distribution.
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, 03:54 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
ls -al command issues. Unable to dsplay all fles


#I have this folder, dir, to show the problem.
Quote:
user1@server1 ~ $ ls -al dir
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:36 .
drwxr-xr-x 44 user1 user1 4096 Feb 10 14:39 ..
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

#Now create dir0 to copy files from dir.
user1@server1 ~ $ mkdir dir0

user1@server1 ~ $ ls -al dir0
total 8
drwxr-xr-x 2 user1 user1 4096 Feb 10 14:39 .
drwxr-xr-x 45 user1 user1 4096 Feb 10 14:39 ..

#Now copy ALL files from dir to dir0
user1@server1 ~ $ cp -a dir dir0

#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
user1@server1 ~/dir0 $

Last edited by fanoflq; 02-10-2017 at 04:09 PM.
 
Old 02-10-2017, 04:08 PM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
you are copying dir itself into dir0 rather than copying the content of dir into dir0, perhap try `cp -a dir/* dir0`, see if you see a difference there.

Alternatively do not create dir0 in advance.
 
Old 02-10-2017, 05:01 PM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
you are copying dir itself into dir0 rather than copying the content of dir into dir0, perhap try `cp -a dir/* dir0`, see if you see a difference there.

Alternatively do not create dir0 in advance.
Thank you.
But you are not answering my questions,
and your response is also not making sense to me.
 
Old 02-10-2017, 05:09 PM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
The issue is you messed up your CP statement, not the LS statement.

Let's put it another way...

What I think you think you are doing should result in having

dir0/.hiddenfile1

it isn't, it is resulting in having

dir0/dir/.hiddenfile1

Because you messed up the cp command.

Last edited by r3sistance; 02-10-2017 at 05:11 PM.
 
Old 02-10-2017, 05:09 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by fanoflq View Post
#I have this folder, dir, to show the problem.
user1@server1 ~ $ ls -al dir
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:36 .
drwxr-xr-x 44 user1 user1 4096 Feb 10 14:39 ..
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

#Now create dir0 to copy files from dir.
user1@server1 ~ $ mkdir dir0

user1@server1 ~ $ ls -al dir0
total 8
drwxr-xr-x 2 user1 user1 4096 Feb 10 14:39 .
drwxr-xr-x 45 user1 user1 4096 Feb 10 14:39 ..

#Now copy ALL files from dir to dir0
user1@server1 ~ $ cp -a dir dir0


#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
user1@server1 ~/dir0 $
Mine look here. see?
Code:
(userx@slacko⚡️~)>>$ mkdir test
(userx@slacko⚡️~)>>$ cd test
(userx@slacko⚡️~/test)>>$ ls -la
total 8
drwxr-xr-x  2 userx userx 4096 Feb 10 17:06 .
drwx------ 56 userx userx 4096 Feb 10 17:06 ..
(userx@slacko⚡️~/test)>>$ cd ..

(userx@slacko⚡️~)>>$ ls -la testme
total 60
-rw-r--r--  1 userx userx    23 Jan 20 15:56  ternaryoperator
drwxr-xr-x  5 userx userx  4096 Jan 20 19:30 .
drwx------ 56 userx userx  4096 Feb 10 17:06 ..
-rw-r--r--  1 userx userx     0 Jan 18 12:36 1
-rw-r--r--  1 userx userx     0 Jan 11 10:12 3-3-2323.dat
-rw-r--r--  1 userx userx     0 Jan 11 10:22 3-4-3454.dat
-rw-r--r--  1 userx userx     0 Jan 11 10:22 3-4-3455.dat
-rw-r--r--  1 userx userx     0 Jan 11 10:22 3-4-34565.dat
-rwxr-xr-x  1 userx userx 10456 Jan 20 19:29 a.out
-rwxr-xr-x  1 userx userx   124 Jan 18 16:57 nowwhat
-rwxr-xr-x  1 userx userx    23 Jan 20 15:58 ternaryoperator
-rw-r--r--  1 userx userx   319 Jan 20 19:30 ternaryoperator.c
drwxr-xr-x  2 userx userx  4096 Jan 18 16:55 testme
drwxr-xr-x  2 userx userx  4096 Jan 18 16:57 testme2
drwxr-xr-x  2 userx userx  4096 Jan 18 16:51 testme3
-rwxr-xr-x  1 userx userx   217 Jan 19 17:53 untitled
-rwxr-xr-x  1 userx userx    89 Jan 18 14:33 what
-rwxr-xr-x  1 userx userx   524 Jan 18 13:01 whatistruth

(userx@slacko⚡️~)>>$ cp -a testme test

(userx@slacko⚡️~)>>$ ls -la test
total 12
drwxr-xr-x  3 userx userx 4096 Feb 10 17:07 .
drwx------ 56 userx userx 4096 Feb 10 17:06 ..
drwxr-xr-x  5 userx userx 4096 Jan 20 19:30 testme

(userx@slacko⚡️~)>>$ ls -la test/*
total 60
-rw-r--r-- 1 userx userx    23 Jan 20 15:56  ternaryoperator
drwxr-xr-x 5 userx userx  4096 Jan 20 19:30 .
drwxr-xr-x 3 userx userx  4096 Feb 10 17:07 ..
-rw-r--r-- 1 userx userx     0 Jan 18 12:36 1
-rw-r--r-- 1 userx userx     0 Jan 11 10:12 3-3-2323.dat
-rw-r--r-- 1 userx userx     0 Jan 11 10:22 3-4-3454.dat
-rw-r--r-- 1 userx userx     0 Jan 11 10:22 3-4-3455.dat
-rw-r--r-- 1 userx userx     0 Jan 11 10:22 3-4-34565.dat
-rwxr-xr-x 1 userx userx 10456 Jan 20 19:29 a.out
-rwxr-xr-x 1 userx userx   124 Jan 18 16:57 nowwhat
-rwxr-xr-x 1 userx userx    23 Jan 20 15:58 ternaryoperator
-rw-r--r-- 1 userx userx   319 Jan 20 19:30 ternaryoperator.c
drwxr-xr-x 2 userx userx  4096 Jan 18 16:55 testme
drwxr-xr-x 2 userx userx  4096 Jan 18 16:57 testme2
drwxr-xr-x 2 userx userx  4096 Jan 18 16:51 testme3
-rwxr-xr-x 1 userx userx   217 Jan 19 17:53 untitled
-rwxr-xr-x 1 userx userx    89 Jan 18 14:33 what
-rwxr-xr-x 1 userx userx   524 Jan 18 13:01 whatistruth


(userx@slacko⚡️~)>>$ cd test
(userx@slacko⚡️~/test)>>$ ls
testme
what you did with the cp -a dir dir0 was copy the directory and its contents into dir0 that is why all you see is the directory and not that directories contents until you use a wildcard that causes it to look inside of everything within the base directory.

if you just want to copy the dir contents then it is this.
Code:
cp -ar dir/* dir0
see here
Code:
(userx@slacko⚡️~)>>$ cp -ar testme/* test
(userx@slacko⚡️~)>>$ ls test
 ternaryoperator  3-4-3455.dat   ternaryoperator    testme3
1                 3-4-34565.dat  ternaryoperator.c  untitled
3-3-2323.dat      a.out          testme             what
3-4-3454.dat      nowwhat        testme2            whatistruth

Last edited by BW-userx; 02-10-2017 at 05:15 PM.
 
Old 02-10-2017, 05:29 PM   #6
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Thank you.

Quote:
user1@server1 ~ $ ls -al dir
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 14:36 .
drwxr-xr-x 44 user1 user1 4096 Feb 10 14:39 ..
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

Quote:
user1@server1 ~ $ rm -rf dir0
user1@server1 ~ $ mkdir dir0
user1@server1 ~ $ cp -a dir/* dir0
user1@server1 ~ $ ls -al dir0
total 12
drwxr-xr-x 3 user1 user1 4096 Feb 10 16:23 .
drwxr-xr-x 45 user1 user1 4096 Feb 10 16:22 ..
drwxr-xr-x 2 user1 user1 4096 Feb 10 15:18 dir1
Why is the copy command not copying the other two files to dir0 also?
 
Old 02-10-2017, 05:31 PM   #7
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by fanoflq View Post
Thank you.

Why is the copy command not copying the other two files to dir0 also?
It seems you still haven't understood, it HAS copied the other two files. The other two files are just not where YOU think they are because you still don't understand the behavior of the cp command.

As I said, you have copied ~/dir to ~/dir0/dir and so the other files are in ~/dir0/dir. You're running 'ls -al dir0' instead of 'ls -al dir0/dir'

if you still don't get it, run the following

Code:
ls -al ~/dir0/dir

Last edited by r3sistance; 02-10-2017 at 05:35 PM.
 
Old 02-10-2017, 05:47 PM   #8
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
@r3sistance:
In my last post, I am doing a slightly different copy command.
I was copying content of dir, excluding dir itself to dir0.
Note the asterisk wildcard for dir/* below.
Quote:
user1@server1 ~ $ cp -a dir/* dir0
This means I do not expect to find dir inside dir0.
I expect to find dir1, file1, and .hiddenfile1.
But I only saw dir1 inside dir0 when using ls -al dir0.
So why is that?
You should get the sase result as I do if you did what I did.
 
Old 02-10-2017, 05:53 PM   #9
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
ah apologies, missed that. now that is odd. Just to cross reference try the following

Quote:
rm -rf ~/dir0
cp -a ~/dir ~/dir0
ls -al ~/dir0
 
1 members found this post helpful.
Old 02-10-2017, 06:07 PM   #10
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
ah apologies, missed that. now that is odd. Just to cross reference try the following
OK, now I am confused.

Quote:
cp -a ~/dir ~/dir0
and
Quote:
cp -a dir dir0
have different result if you create dir0 before cp command!

I looked at the man page, and there is no such description!

In case of an existing directory, e.g. dir0, how
do you copy all contents of dir to dir0?

Last edited by fanoflq; 02-10-2017 at 06:19 PM.
 
Old 02-10-2017, 06:16 PM   #11
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
there shouldn't be a difference... you deleted dir0 again and didn't do a mkdir right? if so... do

Quote:
which cp
let's check nobody is pulling a prank on you.
 
Old 02-10-2017, 06:18 PM   #12
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
By default, Bash doesn't glob dot files with *, which is why cp -a dir/* dir0 is not copying the hidden file across.

This behaviour can be changed with shopt -s dotglob

See e.g. http://askubuntu.com/questions/25938...e-hidden-files
 
1 members found this post helpful.
Old 02-10-2017, 06:24 PM   #13
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by hydrurga View Post
By default, Bash doesn't glob dot files with *, which is why cp -a dir/* dir0 is not copying the hidden file across.

This behaviour can be changed with shopt -s dotglob

See e.g. http://askubuntu.com/questions/25938...e-hidden-files
But only one of the two missing files is a hidden file, the other file missing which is file1 isn't dot prefixed.
 
1 members found this post helpful.
Old 02-10-2017, 06:25 PM   #14
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
OK. Here goes..... no prank.

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 so... do
let's check nobody is pulling a prank on you.
Quote:


~ $ which cp
/bin/cp
 
Old 02-10-2017, 06:29 PM   #15
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
By default, Bash doesn't glob dot files with *, which is why cp -a dir/* dir0 is not copying the hidden file across.

This behaviour can be changed with shopt -s dotglob

See e.g. http://askubuntu.com/questions/25938...e-hidden-files
cp only copy directories if I already have a destination folder. Looks like it is a bug, no?
See my post above.
 
  


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 10:22 AM
open xlsm or xls fles under linux by openoffice frhling Linux - General 1 01-07-2013 04:44 AM
How do i configure g++ to look into particular directory to search library fles? sadhup Linux - Newbie 5 05-02-2012 01:06 AM
how can i run bin fles on vector linux bushcat Linux - Newbie 2 03-28-2009 10:25 AM
Any good apps to upload fles to website darin3200 Linux - Software 2 04-15-2003 09:45 PM

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

All times are GMT -5. The time now is 10:08 AM.

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
Open Source Consulting | Domain Registration