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.
|
|
03-30-2017, 01:01 PM
|
#1
|
Member
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359
Rep:
|
Listing files in terminal
Hello
Please help me to list files in following way. Some I know, but others I don't know how to achieve.
- List all files and folders including hidden
- List only hidden files and folders
- List only folders (not hidden)
- List only folders (hidden only)
- List only files (not hidden) -- Don't know
- List only files (hidden) -- Don't know
- List all files (hidden and not-hidden) -- Don't know
Please help me for last three options in listing. I want to do this only through ls command. No other command or through grep or any other pipes.
1.List all files and folders including hidden
Code:
$ ls -lA
total 46856
-rw-------. 1 2dd 2dd 2707 Mar 30 20:55 .bash_history
-rw-r--r--. 1 2dd 2dd 18 Aug 2 2016 .bash_logout
-rw-r--r--. 1 2dd 2dd 193 Aug 2 2016 .bash_profile
-rw-r--r--. 1 2dd 2dd 274 Mar 30 14:05 .bashrc
drwx------. 21 2dd 2dd 4096 Mar 30 21:23 .cache
drwxr-xr-x. 25 2dd 2dd 4096 Mar 30 20:57 .config
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Desktop
-rw-r--r--. 1 2dd 2dd 1542196 Feb 24 15:20 DM Multipath.pdf
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 20:12 Documents
drwxr-xr-x. 2 2dd 2dd 238 Mar 30 21:28 Downloads
drwx------. 5 2dd 2dd 164 Mar 30 20:57 .dropbox
drwx------. 8 2dd 2dd 168 Mar 30 20:57 Dropbox
drwxr-xr-x. 3 2dd 2dd 71 Mar 30 20:49 .dropbox-dist
-rw-------. 1 2dd 2dd 16 Mar 30 13:08 .esd_auth
drwxr-xr-x. 4 2dd 2dd 4096 Feb 24 18:55 .FRD
drwxr-xr-x. 24 2dd 2dd 4096 Mar 30 19:41 .gimp-2.8
drwx------. 3 2dd 2dd 18 Mar 30 15:43 .gnome
drwx------. 2 2dd 2dd 98 Mar 30 21:32 .gnupg
-rw-------. 1 2dd 2dd 2802 Mar 30 18:12 .ICEauthority
drwx------. 3 2dd 2dd 19 Mar 30 13:08 .local
-rw-r--r--. 1 2dd 2dd 13197684 Feb 24 15:20 Logical Volume Manager Administration.pdf
drwxr-xr-x. 5 2dd 2dd 54 Mar 30 13:49 .mozilla
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Music
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Pictures
drwx------. 3 2dd 2dd 19 Mar 30 15:43 .pki
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Public
-rw-r--r--. 1 2dd 2dd 8304590 Feb 24 15:20 Red_Hat_Enterprise_Linux-7-Networking_Guide-en-US.pdf
-rw-r--r--. 1 2dd 2dd 24871779 Feb 24 15:20 Red_Hat_Enterprise_Linux-7-System_Administrators_Guide-en-US.pdf
drwx------. 2 2dd 2dd 6 Mar 30 13:49 .ssh
drwxr-xr-x. 2 2dd 2dd 26 Mar 30 19:26 Templates
drwx------. 3 2dd 2dd 48 Mar 30 20:42 .thunderbird
-rw-r--r--. 1 2dd 2dd 392 Mar 30 16:28 .tmux.conf
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Videos
-rw-------. 1 2dd 2dd 3638 Mar 30 20:09 .viminfo
-rw-rw-r--. 1 2dd 2dd 26 Mar 30 15:58 .Xresources
2.List only hidden files and folders
Code:
$ ls -ld .*
drwx------. 24 2dd 2dd 4096 Mar 30 21:22 .
drwxr-xr-x. 3 root root 19 Mar 30 13:05 ..
-rw-------. 1 2dd 2dd 2707 Mar 30 20:55 .bash_history
-rw-r--r--. 1 2dd 2dd 18 Aug 2 2016 .bash_logout
-rw-r--r--. 1 2dd 2dd 193 Aug 2 2016 .bash_profile
-rw-r--r--. 1 2dd 2dd 274 Mar 30 14:05 .bashrc
drwx------. 21 2dd 2dd 4096 Mar 30 21:23 .cache
drwxr-xr-x. 25 2dd 2dd 4096 Mar 30 20:57 .config
drwx------. 5 2dd 2dd 164 Mar 30 20:57 .dropbox
drwxr-xr-x. 3 2dd 2dd 71 Mar 30 20:49 .dropbox-dist
-rw-------. 1 2dd 2dd 16 Mar 30 13:08 .esd_auth
drwxr-xr-x. 4 2dd 2dd 4096 Feb 24 18:55 .FRD
drwxr-xr-x. 24 2dd 2dd 4096 Mar 30 19:41 .gimp-2.8
drwx------. 3 2dd 2dd 18 Mar 30 15:43 .gnome
drwx------. 2 2dd 2dd 98 Mar 30 21:32 .gnupg
-rw-------. 1 2dd 2dd 2802 Mar 30 18:12 .ICEauthority
drwx------. 3 2dd 2dd 19 Mar 30 13:08 .local
drwxr-xr-x. 5 2dd 2dd 54 Mar 30 13:49 .mozilla
drwx------. 3 2dd 2dd 19 Mar 30 15:43 .pki
drwx------. 2 2dd 2dd 6 Mar 30 13:49 .ssh
drwx------. 3 2dd 2dd 48 Mar 30 20:42 .thunderbird
-rw-r--r--. 1 2dd 2dd 392 Mar 30 16:28 .tmux.conf
-rw-------. 1 2dd 2dd 3638 Mar 30 20:09 .viminfo
-rw-rw-r--. 1 2dd 2dd 26 Mar 30 15:58 .Xresources
3.List only folders (not hidden)
Code:
$ ls -ld */
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Desktop/
drwxr-xr-x. 2 2dd 2dd 17 Mar 30 21:42 Documents/
drwxr-xr-x. 2 2dd 2dd 238 Mar 30 21:28 Downloads/
drwx------. 8 2dd 2dd 168 Mar 30 20:57 Dropbox/
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Music/
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Pictures/
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Public/
drwxr-xr-x. 2 2dd 2dd 26 Mar 30 19:26 Templates/
drwxr-xr-x. 2 2dd 2dd 6 Mar 30 13:08 Videos/
4.List only folders (hidden only)
Code:
$ ls -ld .*/
drwx------. 24 2dd 2dd 4096 Mar 30 21:22 ./
drwxr-xr-x. 3 root root 19 Mar 30 13:05 ../
drwx------. 21 2dd 2dd 4096 Mar 30 21:23 .cache/
drwxr-xr-x. 26 2dd 2dd 4096 Mar 30 21:42 .config/
drwx------. 5 2dd 2dd 164 Mar 30 20:57 .dropbox/
drwxr-xr-x. 3 2dd 2dd 71 Mar 30 20:49 .dropbox-dist/
drwxr-xr-x. 4 2dd 2dd 4096 Feb 24 18:55 .FRD/
drwxr-xr-x. 24 2dd 2dd 4096 Mar 30 19:41 .gimp-2.8/
drwx------. 3 2dd 2dd 18 Mar 30 15:43 .gnome/
drwx------. 2 2dd 2dd 98 Mar 30 21:32 .gnupg/
drwx------. 3 2dd 2dd 19 Mar 30 13:08 .local/
drwxr-xr-x. 5 2dd 2dd 54 Mar 30 13:49 .mozilla/
drwx------. 3 2dd 2dd 19 Mar 30 15:43 .pki/
drwx------. 2 2dd 2dd 6 Mar 30 13:49 .ssh/
drwx------. 3 2dd 2dd 48 Mar 30 20:42 .thunderbird/
Thanks in advance.
Last edited by ddenial; 03-30-2017 at 01:42 PM.
|
|
|
03-30-2017, 01:05 PM
|
#2
|
LQ Addict
Registered: Dec 2013
Posts: 19,872
|
i'd start by reading anything that's still unclear after that, we'll be happy to give you hints (but won't actually do your homework for you).
|
|
|
03-30-2017, 01:17 PM
|
#3
|
Member
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359
Original Poster
Rep:
|
Quote:
Originally Posted by ondoho
i'd start by reading anything that's still unclear after that, we'll be happy to give you hints (but won't actually do your homework for you).
|
Home work? Believe me I finished my education some decades ago.
I did go through man pages, but couldn't find it. So I thought its more probably about globbing thing.
I can go through man pages again if you think I can get answers, no problem about that.
Thanks
|
|
|
03-30-2017, 01:29 PM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,597
|
The manual page for ls is long and detailed, so it will take several readings.
The glob page is a bit hidden. It is in the 7th section, which is hidden by the glob in the 3rd.
Code:
man glob
man 7 glob
man 3 glob
grep might be involved in some of the last tasks you list.
Last edited by Turbocapitalist; 03-30-2017 at 01:31 PM.
|
|
1 members found this post helpful.
|
03-30-2017, 01:32 PM
|
#5
|
Member
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634
|
Edit:
Quote:
I want to do this only through ls command.
|
Whoops, missed that part
----------
Quote:
List all files including hidden
List all files (hidden and not-hidden)
|
What's the difference here?
In any case, you can use find to have some more control with listing files in the terminal
Quote:
List all files including hidden
List only hidden files and folders
List only folders (not hidden)
List only folders (hidden only)
List only files (not hidden) -- Don't know
List only files (hidden) -- Don't know
List all files (hidden and not-hidden) -- Don't know
|
List all files including hidden
List only hidden files and folders
Code:
find . -maxdepth 1 -iname '.*'
List only folders (not hidden)
Code:
find . -maxdepth 1 -type d -not -iname '.*'
List only folders (hidden only)
Code:
find . -maxdepth 1 -type d -iname '.*'
List only files (not hidden)
Code:
find . -maxdepth 1 -type f -not -iname '.*'
List only files (hidden)
Code:
find . -maxdepth 1 -type f -iname '.*'
List all files (hidden and not-hidden)
Last edited by Sefyir; 03-30-2017 at 01:35 PM.
|
|
|
03-30-2017, 01:32 PM
|
#6
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
Listing files is easy.
Start by not calling them "folders".
|
|
|
03-30-2017, 01:36 PM
|
#7
|
Member
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359
Original Poster
Rep:
|
Quote:
Originally Posted by Turbocapitalist
The manual page for ls is long and detailed, so it will take several readings.
The glob page is a bit hidden. It is in the 7th section, which is hidden by the glob in the 3rd.
Code:
man glob
man 7 glob
man 3 glob
grep might be involved in some of the last tasks you list.
|
Interesting, Thanks. I'll go through it.
@Sefyir, thanks, but I know how to do this in find command. I also know by using grep, I can get what I want. I want to do this explicitly by using ls command.
Thanks
|
|
|
03-30-2017, 01:41 PM
|
#8
|
Member
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359
Original Poster
Rep:
|
Quote:
Originally Posted by Sefyir
What's the difference here?
List all files including hidden
List all files (hidden and not-hidden)
|
Sorry about that. I have corrected it now. Thanks
|
|
|
All times are GMT -5. The time now is 01:31 PM.
|
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
|
|