[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.
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 06:56 PM.
Reason: added question
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.
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.
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.
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 08:05 PM.
Reason: typos
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.