LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-25-2008, 03: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 03:56 AM.
 
Old 06-25-2008, 05:02 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 05: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, 05:09 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
(cd /home/usr/folder; ls *.pdf)
 
Old 06-25-2008, 09:41 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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



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

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

All times are GMT -5. The time now is 03:14 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
Open Source Consulting | Domain Registration