LinuxQuestions.org
Latest LQ Deal: Linux Power User 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 06-25-2008, 04:55 AM   #1
Byenary
Member
 
Registered: Oct 2003
Distribution: edgy dapper feisty
Posts: 36

Rep: Reputation: 15
doing a ls from a directory (not the current) giving the files without path


Hello,

Im looking for an instruction like this
ls /home/user/folder/*.pdf
But it should only give a list of the filenames and leave out the path, I could script this but im sure there must be a cleaner method using ls but i can't seem to find it or overlooking it.

THx

Last edited by Byenary; 06-25-2008 at 04:56 AM.
 
Old 06-25-2008, 06:02 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
You could 'find /home/user/folder -printf "%f\n"' or '\ls find /home/user/folder/*.pdf|while read f; do echo "${f//*\//}"; done'. Watch for spaces though.
 
Old 06-25-2008, 06:07 AM   #3
Swagata Paul
Member
 
Registered: Jun 2008
Location: Kolkata, India
Posts: 57

Rep: Reputation: 15
No way.
U can write a script.....like 1) change directory 2) list files 3) change to previous dir.

OR

U can filter out the unwanted parts.
 
Old 06-25-2008, 06:09 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
(cd /home/usr/folder; ls *.pdf)
 
Old 06-25-2008, 10:41 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
how bout
Code:
ls -1 /home/user/folder/ | grep pdf$
 
Old 06-25-2008, 12:35 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
or
Code:
ls /home/user/folder/*.pdf | xargs -I{} basename {}
with the -I option of xargs unquoted blank spaces do not terminate the input item, so having blank spaces in the file names is not an issue here.
 
  


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
move all files in current directory into a subdirectory in the current directory jakykong Linux - Newbie 8 07-17-2013 12:46 AM
double current directory in path Saulo SUSE / openSUSE 5 04-20-2006 07:19 PM
setting bash to look in current directory before searching the path muhkuhmasta Linux - Newbie 4 09-21-2004 03:08 AM
edit path environment variable to include current working directory alb1954 Linux - Newbie 8 07-12-2004 12:26 AM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 12:05 PM


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