LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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,353
Blog Entries: 55

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

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


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