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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-12-2017, 04:38 AM
|
#1
|
LQ Newbie
Registered: Jan 2017
Posts: 2
Rep:
|
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
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.
|
|
|
|
01-12-2017, 07:30 AM
|
#2
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,915
|
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.
|
|
|
01-12-2017, 09:15 AM
|
#3
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,797
|
The 8.4 version of basename does not support the "-s" option.
Last edited by rknichols; 01-12-2017 at 09:16 AM.
|
|
|
01-12-2017, 09:27 AM
|
#4
|
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
|
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.
|
|
|
01-12-2017, 10:29 AM
|
#5
|
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7 / 8
Posts: 3,529
|
What does this give you:
Code:
find . -name "*.xyz" -exec basename {} .xyz \;
|
|
|
01-12-2017, 02:39 PM
|
#6
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,028
|
TenTenths example should work as your own output gave the exact same example:
Code:
basename include/stdio.h .h Output "stdio".
|
|
|
01-12-2017, 10:50 PM
|
#7
|
LQ Newbie
Registered: Jan 2017
Posts: 2
Original Poster
Rep:
|
Quote:
Originally Posted by TenTenths
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
|
|
|
01-13-2017, 03:20 AM
|
#8
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,598
|
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.
Edit: see also the manual page for basename and the -a option.
Last edited by Turbocapitalist; 01-13-2017 at 03:23 AM.
|
|
|
01-13-2017, 12:44 PM
|
#10
|
Member
Registered: May 2016
Posts: 222
Rep:
|
Quote:
Originally Posted by Turbocapitalist
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.
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-
|
|
|
01-13-2017, 12:47 PM
|
#11
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,598
|
Quote:
Originally Posted by nodir
|
Right. Re-read post #8 where -print0 is mentioned for find and --null mentioned for xargs
|
|
|
01-13-2017, 01:04 PM
|
#12
|
Member
Registered: May 2016
Posts: 222
Rep:
|
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.
|
|
|
01-13-2017, 08:02 PM
|
#13
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,647
|
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
|
|
|
01-13-2017, 09:31 PM
|
#14
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,797
|
Red Hat Enterprise Linux 6 is fully supported until November 30, 2020, and uses coreutils-8.4. A lot of people are using it.
|
|
|
All times are GMT -5. The time now is 07:43 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|