LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 12-28-2010, 02:16 PM   #1
Kitt3n
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Rep: Reputation: 0
-ls -l [filename]


I am trying to learn coding in C in a Linux environment. Now the problem is that I have never used Linux before.

Now in my book it stated I needed to see if the file was actually stored in a certain location using the following command and parameters.
Code:
-ls -l [./filename]
Now I looked this up using google and -ls seems to be the same to me as 'dir' in the Windows system and -l is the parameter deciding what information is shown.

What I do not understand is why I needed to write './' in front of the file name. I thought the -ls command lists only the files in the current directory and that './' has the same meaning (search in current directory).

Next to that, am I right in saying that by attaching the files name to '-ls -l' I make it only display the info for that particular file?
 
Old 12-28-2010, 02:21 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
whilst it's just "ls" as a command, no - before it, you are right, there's no need to use ./ here. And yes, as per the documentation you have available to you already, putting a file name, or pattern, as a parameter, only matching files will be shown.
 
1 members found this post helpful.
Old 12-28-2010, 02:27 PM   #3
Kitt3n
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie View Post
whilst it's just "ls" as a command, no - before it, you are right, there's no need to use ./ here. And yes, as per the documentation you have available to you already, putting a file name, or pattern, as a parameter, only matching files will be shown.
Sorry for the '-' in front of the ls. Would the following command then result in the same or does the 'ls' command need to be send with it in every case?
Code:
-l [./filename]
 
Old 12-28-2010, 02:35 PM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
You want
Code:
ls -l filename
 
1 members found this post helpful.
Old 12-28-2010, 02:46 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
ls is the command name. -l is just one of many options you can add to it to determine what information is displayed and how. In this case it stands for the "long" format. man ls will give you the documentation with the rest.

. (single dot) is just the relative path character for the current directory (just as .. means the containing directory), so ./filename is simply the relative path to the file, meaning of course "filename in this directory". Generally you do not need to use it with simple command arguments such as with ls, as the Present Working Directory is usually considered the default by most programs. So ls -l filename will work just fine. You only really need to add it when a full or relative path is expected, the most common case being launching scripts or executables when the current directory isn't in your PATH environment setting, or when the program you are feeding it to doesn't know to look in the PWD for some reason.

I recommend linuxcommand.org for a good primer on how to navigate around the shell.
 
2 members found this post helpful.
Old 12-28-2010, 03:04 PM   #6
snorky
LQ Newbie
 
Registered: Aug 2003
Location: upper left corner, US of A
Distribution: several
Posts: 15

Rep: Reputation: 1
Quote:
Originally Posted by Kitt3n View Post
Sorry for the '-' in front of the ls. Would the following command then result in the same or does the 'ls' command need to be send with it in every case?
Code:
-l [./filename]
ls is a command analagous to the windows dir command
-l is an argument that makes the command more precise
In this case what you want is ls -l

There are many more arguments you can pass to the ls command

To learn about those, try the following
Code:
ls --help
man ls
The same type of research will apply to any linux command: use man command or command --help

FWIW, my favorite ways to get directory listings that are sorted, displayed in columns, and detailed are
Code:
ls -laSh
ls -laS

And one last tip: in linux every command and every filename is case-sensitive. If you aren't precise with case in commands and filenames, you will get unexpected results.

Last edited by snorky; 12-28-2010 at 03:08 PM. Reason: clarify even more
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How can we convert a dynamic library (filename.so) to a static library (filename.a). hanumaan Programming 4 11-20-2009 01:07 AM
Change name of backup file in ext3 from filename~ to .filename~ Libu Linux - General 2 07-21-2008 10:29 PM
Convert static library (Filename.a) to dynamic shared object (filename.so) afx2029 Linux - Software 4 08-17-2007 07:07 AM
change uploaded files from filename.avi to filename.avi.html like www.rapidshare.de latheesan Linux - Newbie 3 06-16-2005 05:33 AM
filename- and filename~ files? slinky2004 Linux - Newbie 5 10-17-2004 11:32 PM

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

All times are GMT -5. The time now is 10:37 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration