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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
02-10-2017, 03:54 PM
|
#1
|
Member
Registered: Nov 2015
Posts: 397
Rep:
|
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.
|
|
|
02-10-2017, 04:08 PM
|
#2
|
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375
|
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.
|
|
|
02-10-2017, 05:01 PM
|
#3
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep:
|
Quote:
Originally Posted by r3sistance
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.
|
|
|
02-10-2017, 05:09 PM
|
#4
|
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375
|
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.
|
|
|
02-10-2017, 05:09 PM
|
#5
|
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
|
Quote:
Originally Posted by fanoflq
#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.
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.
|
|
|
02-10-2017, 05:29 PM
|
#6
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep:
|
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?
|
|
|
02-10-2017, 05:31 PM
|
#7
|
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375
|
Quote:
Originally Posted by fanoflq
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
Last edited by r3sistance; 02-10-2017 at 05:35 PM.
|
|
|
02-10-2017, 05:47 PM
|
#8
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep:
|
@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.
|
|
|
02-10-2017, 05:53 PM
|
#9
|
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375
|
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.
|
02-10-2017, 06:07 PM
|
#10
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep:
|
Quote:
Originally Posted by r3sistance
ah apologies, missed that. now that is odd. Just to cross reference try the following
|
OK, now I am confused.
and
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.
|
|
|
02-10-2017, 06:16 PM
|
#11
|
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375
|
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.
|
|
|
02-10-2017, 06:18 PM
|
#12
|
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
|
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.
|
02-10-2017, 06:24 PM
|
#13
|
Senior Member
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375
|
Quote:
Originally Posted by hydrurga
|
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.
|
02-10-2017, 06:25 PM
|
#14
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep:
|
OK. Here goes..... no prank.
Quote:
Originally Posted by r3sistance
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.
|
|
|
|
02-10-2017, 06:29 PM
|
#15
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep:
|
Quote:
Originally Posted by hydrurga
|
cp only copy directories if I already have a destination folder. Looks like it is a bug, no?
See my post above.
|
|
|
All times are GMT -5. The time now is 10:08 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|