LinuxQuestions.org
Visit Jeremy's Blog.
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 01-12-2017, 03:38 AM   #1
jrffrey
LQ Newbie
 
Registered: Jan 2017
Posts: 2

Rep: Reputation: Disabled
Need help for basename


I have tried to run this:

Lets say i have two files in the current folder:
file1.xyz
file2.xyz

Quote:
$find . -name "*.xyz" | xargs basename -s ".xyz"
i was hoping to get
Quote:
file1
file2
but this is the output i got
Quote:
basename: invalid option -- 's'
this is the version of basename i have
Quote:
$basename --help
Usage: basename NAME [SUFFIX]
or: basename OPTION
Print NAME with any leading directory components removed.
If specified, also remove a trailing SUFFIX.
--help display this help and exit
--version output version information and exit
Examples:
basename /usr/bin/sort Output "sort".
basename include/stdio.h .h Output "stdio".

Report basename bugs to bug-coreutils@gnu.org
GNU coreutils home page: http://www.gnu.org/software/coreutils/
General help using GNU software: http://www.gnu.org/gethelp/
For complete documentation, run: info coreutils 'basename invocation'
[khorseik@ntu03 output]$ basename --version
basename (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.
 
Old 01-12-2017, 06:30 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,354
Blog Entries: 13

Rep: Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411Reputation: 4411
I have basename version 8.25 and your command works fine.

Possible that this is a bug, however also possible is something else is wrong, my FSF statement shows (C) 2016 versus 2010.
 
Old 01-12-2017, 08:15 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,555

Rep: Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088
The 8.4 version of basename does not support the "-s" option.

Last edited by rknichols; 01-12-2017 at 08:16 AM.
 
Old 01-12-2017, 08:27 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Code:
DESCRIPTION
       Print NAME with any leading directory components removed.  If
       specified, also remove a trailing SUFFIX.

       Mandatory arguments to long options are mandatory for short options
       too.

       -a, --multiple
              support multiple arguments and treat each as a NAME

       -s, --suffix=SUFFIX
              remove a trailing SUFFIX; implies -a
....
....

GNU coreutils 8.26               January 2017                      BASENAME(1)

Last edited by BW-userx; 01-12-2017 at 08:28 AM.
 
Old 01-12-2017, 09:29 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,210

Rep: Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389Reputation: 1389
What does this give you:
Code:
find . -name "*.xyz" -exec basename {} .xyz \;
 
Old 01-12-2017, 01:39 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,821

Rep: Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084
TenTenths example should work as your own output gave the exact same example:
Code:
basename include/stdio.h .h Output "stdio".
 
Old 01-12-2017, 09:50 PM   #7
jrffrey
LQ Newbie
 
Registered: Jan 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
What does this give you:
Code:
find . -name "*.xyz" -exec basename {} .xyz \;
Yes, this one works as what i want. But the problem, i need to use xargs as part of my next step of work.
So i guess i would need to find a workaround with the -exec
 
Old 01-13-2017, 02:20 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,672
Blog Entries: 3

Rep: Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904
You can use find with xargs. Leave out the -exec clause and use -print0 instead. Then for xargs use -0 or --null.

Be sure to check the manual pages for both periodically so that they start to become familiar.

Code:
man find
man xargs
Edit: see also the manual page for basename and the -a option.

Last edited by Turbocapitalist; 01-13-2017 at 02:23 AM.
 
Old 01-13-2017, 03:53 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,620

Rep: Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608Reputation: 5608
you may find this http://www.thegeekstuff.com/2013/12/xargs-examples/ useful (or you can find similar pages too)
 
Old 01-13-2017, 11:44 AM   #10
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
You can use find with xargs. Leave out the -exec clause and use -print0 instead. Then for xargs use -0 or --null.

Be sure to check the manual pages for both periodically so that they start to become familiar.

Code:
man find
man xargs
Edit: see also the manual page for basename and the -a option.
You can, but you shouldn't.
http://mywiki.wooledge.org/UsingFind...and_-exec_.2B-
 
Old 01-13-2017, 11:47 AM   #11
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,672
Blog Entries: 3

Rep: Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904Reputation: 2904
Quote:
Originally Posted by nodir View Post
Right. Re-read post #8 where -print0 is mentioned for find and --null mentioned for xargs
 
Old 01-13-2017, 12:04 PM   #12
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Oh, i read that.
And truth to be told: i am not that much in the subject that i could advise or explain it at all.
My post was rather focused at the OP, so he knows that some folks have strong opinions against usage of xargs ( while, like said, i for one sure can't say much about it).

in short: it really was a side-note only.
 
Old 01-13-2017, 07:02 PM   #13
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,523

Rep: Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619Reputation: 2619
jrffrey
why are you using a old operating system from 2010
courutils 8.4 is 7 years old
http://ftp.gnu.org/gnu/coreutils/?C=M;O=D
 
Old 01-13-2017, 08:31 PM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,555

Rep: Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088
Red Hat Enterprise Linux 6 is fully supported until November 30, 2020, and uses coreutils-8.4. A lot of people are using it.
 
  


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
basename not working why? varunimast Linux - Newbie 7 09-16-2011 07:48 AM
basename naidu29 Linux - Software 11 06-02-2010 02:03 AM
“basename $0” returns basename: -k: unknown option jaideepca Linux - Newbie 6 11-09-2009 05:30 AM
basename ovince Programming 2 03-21-2007 09:47 AM
basename counterpart? glass Linux - General 1 08-24-2002 06:11 AM

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

All times are GMT -5. The time now is 11:34 AM.

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