LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 04: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, 07:30 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,915
Blog Entries: 13

Rep: Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948
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, 09:15 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,797

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

Last edited by rknichols; 01-12-2017 at 09:16 AM.
 
Old 01-12-2017, 09:27 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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 09:28 AM.
 
Old 01-12-2017, 10:29 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7 / 8
Posts: 3,529

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

Rep: Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200Reputation: 3200
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, 10: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, 03:20 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,598
Blog Entries: 4

Rep: Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894
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 03:23 AM.
 
Old 01-13-2017, 04:53 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,273

Rep: Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696Reputation: 7696
you may find this http://www.thegeekstuff.com/2013/12/xargs-examples/ useful (or you can find similar pages too)
 
Old 01-13-2017, 12:44 PM   #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, 12:47 PM   #11
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,598
Blog Entries: 4

Rep: Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894
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, 01: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, 08:02 PM   #13
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,647

Rep: Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655Reputation: 2655
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, 09:31 PM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,797

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

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

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