Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-25-2008, 04:55 AM   #1
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


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.


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

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
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
Registered: Jun 2008
Location: Kolkata, India
Posts: 57

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


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: 62
(cd /home/usr/folder; ls *.pdf)
Old 06-25-2008, 10:41 AM   #5
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,167

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

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:53 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration