LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 11-10-2014, 05:06 PM   #1
Brainhose
LQ Newbie
 
Registered: Nov 2014
Posts: 4

Rep: Reputation: Disabled
Newbie question regarding ls command


Greetings; I need to use the ls command, and only the ls command to list all files in a directory that have a 'dot' in them. Not only hidden files but also any file with a name like File1.txt I am losing my marbles trying to figure this out, and seeing as my teacher said it was OK to get the answer from a forum as long as I divulged the fact, I'm turning here for help.
 
Old 11-10-2014, 05:10 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Do you know how to use wildcards (* and ?)?
 
Old 11-10-2014, 05:53 PM   #3
Brainhose
LQ Newbie
 
Registered: Nov 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Re: Ls command and file names with dots

Hi, I know wild cards.
Don't hold it against me but I used to use MS-DOS quite a bit years ago.

I see that
ls -d .* --> Shows my hidden files
ls -d *.* --> shows my non-hidden files

Somehow I need to marry these two commands
 
Old 11-10-2014, 06:46 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

you're on the right track. Did you know that you can pass multiple arguments to ls? Eg

Code:
ls foo bar
Evo2.
 
Old 11-10-2014, 06:54 PM   #5
Brainhose
LQ Newbie
 
Registered: Nov 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Greetings

Hi,
I did not know that you could pass multiple arguments to ls like that.
Following your lead I tried: ls -d .* *.* and it seems to do the trick,
I spent a lot of time trying various expressions. It kills me that it may be something that simple.

Thanks.
 
Old 11-10-2014, 07:10 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by Brainhose View Post
I did not know that you could pass multiple arguments to ls like that.
Following your lead I tried: ls -d .* *.* and it seems to do the trick,
Excellent.
Quote:
Originally Posted by Brainhose View Post
I spent a lot of time trying various expressions. It kills me that it may be something that simple.
You probably learnt a lot by putting in the effort to work this out. Don't think of it as a waste of time but as a part of the learning process.

You may have checked the man page but didn't realise what it was telling you. From man ls:

Code:
NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...
The clue here is the "..." after "[FILE]".

HTH,

Evo2.
 
Old 11-10-2014, 07:34 PM   #7
Fred Caro
Senior Member
 
Registered: May 2007
Posts: 1,007

Rep: Reputation: 167Reputation: 167
sorry, deleted

Last edited by Fred Caro; 11-10-2014 at 07:59 PM. Reason: not relavant
 
Old 11-10-2014, 07:40 PM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It really depends on what you are doing. I would tend to use "find . -type d" rather than ls.
 
Old 11-10-2014, 07:52 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Easiest way to list just directories is to put a trailing slash after the star. The trailing slash will make it so it only matches directories, and if you have -d in the ls flags it will print the directory names instead of their contents. eg:
Code:
ls -d */
 
Old 11-10-2014, 08:20 PM   #10
Brainhose
LQ Newbie
 
Registered: Nov 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
ls -d

howdy,
I noticed that if I don't use the -d switch lists the directory names followed by its contents, even if the contents don't have dots in the name.
Whereas, when I do, it lists only the file and directory names, which is what I'm looking for. I've come to realize that I way over thought this problem
and made it more difficult for myself than it needed to be. Cheers and thanks for your assistance.

Listing 1
ls -d $HOME .* *.*

.
..
.bash_history
.bash_logout
.bashrc
.cache
.compiz
.config
CPTN203_A2_Results_mercer.txt~
CPTN203_A3_Results_Mercer.txt
CPTN203_A3_Results_Mercer.txt~
.dmrc
examples.desktop
.gconf
.ICEauthority
.lesshst
.local
.mozilla
.profile
.vboxclient-clipboard.pid
.vboxclient-display.pid
.vboxclient-draganddrop.pid
.vboxclient-seamless.pid
.Xauthority
.xsession-errors
.xsession-errors.old

###################################################

Listing 2
ls $HOME .* *.*

.bash_history
.bash_logout
.bashrc
CPTN203_A2_Results_mercer.txt~
CPTN203_A3_Results_Mercer.txt
CPTN203_A3_Results_Mercer.txt~
.dmrc
examples.desktop
.ICEauthority
.lesshst
LS-D.txt
.profile
.vboxclient-clipboard.pid
.vboxclient-display.pid
.vboxclient-draganddrop.pid
.vboxclient-seamless.pid
.Xauthority
.xsession-errors
.xsession-errors.old

.:
Assignment_1
Assignment_2
Assignment_3
CPTN203_A2_Results_mercer.txt~
CPTN203_A3_Results_Mercer.txt
CPTN203_A3_Results_Mercer.txt~
Desktop
Documents
Downloads
examples.desktop
file1
file2
file3
LS-D.txt
LS_NO-D.txt
Music
passwdcopy
Pictures
Public
sb
SHARED
Templates
Videos

..:
bmercer
brian

.cache:
compizconfig-1
event-sound-cache.tdb.25702ac1b0e5d0083a41862c5429e044.x86_64-pc-linux-gnu
evolution
folks
gstreamer-1.0
ibus
logrotate
mozilla
oneconf
sso
thumbnails
unity
upstart
wallpaper

.compiz:
session

.config:
compiz-1
dconf
enchant
evolution
gedit
gnome-control-center
gnome-session
gtk-2.0
gtk-3.0
ibus
libaccounts-glib
nautilus
pulse
update-notifier
upstart
user-dirs.dirs
user-dirs.locale

.gconf:
apps

.local:
share

.mozilla:
extensions
firefox
 
Old 11-10-2014, 08:44 PM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please use [code][/code] tags to display data and code.

Glad to see your getting a handle on things
 
  


Reply



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
Perl newbie question about system command Guttorm Programming 8 06-30-2011 08:43 PM
Newbie question about executing java command oldoldcat Linux - General 4 01-30-2004 01:15 AM
Another Newbie Question - Command Line Shortcuts? AtomiCTheGr8 Linux - General 9 08-14-2002 09:02 PM

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

All times are GMT -5. The time now is 10:28 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