[SOLVED] ls -al command issues. Unable to dsplay all fles
Linux - NewbieThis 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.
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.
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 $
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.
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.
#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
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 06:35 PM.
@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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.