Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
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.
|
 |
05-06-2015, 01:14 AM
|
#1
|
LQ Newbie
Registered: Mar 2011
Posts: 1
Rep:
|
How to replace filename whitespace with underscore?
I have a routine need to replace filename whitespace (space, period, hyphen, etc.) with underscore. While scrounging, I found a comment online referring to a program and downloaded it. It worked perfectly. Now I have no clue about its location and name. I know. I should have given it a friendly name, stashed it where I could find it, and put its location in the path.
Can anyone tell me what program will do the job and where I can find it?
This time I'll stash it where I can find it.
Thanks
|
|
|
05-06-2015, 10:52 AM
|
#2
|
Senior Member
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524
|
You can use shell script with sed to change them to '_'.
Code:
#!/bin/bash
mv "$1" `echo "$1" | sed -e 's@[ ]\+\|[.]\+\|[-]\+@_@g'`
And run this script with 'scrname filename'.
|
|
|
05-07-2015, 06:48 AM
|
#3
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,961
|
You can use the rename(1) command:
Code:
$ echo 1 > "ab cd.txt"
$ echo 2 > "for this.txt"
$ ls
ab cd.txt for this.txt
$ man rename
$ rename s/\ //g *.txt
$ ls
abcd.txt forthis.txt
$
|
|
1 members found this post helpful.
|
05-07-2015, 07:07 AM
|
#4
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
Code:
[schneidz@hyper test]$ ll
total 428
-rw-rw-r--. 1 schneidz schneidz 438176 May 6 10:43 admin.php
-rw-rw-r--. 1 schneidz schneidz 0 May 7 07:58 file name-1.txt
[schneidz@hyper test]$ for file in *; do mv "$file" `echo $file | tr ' .-' '___'`; done
[schneidz@hyper test]$ ll
total 428
-rw-rw-r--. 1 schneidz schneidz 438176 May 6 10:43 admin_php
-rw-rw-r--. 1 schneidz schneidz 0 May 7 07:58 file_name_1_txt
|
|
|
05-07-2015, 07:34 AM
|
#5
|
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7 / 8
Posts: 3,572
|
|
|
|
05-07-2015, 05:05 PM
|
#6
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,700
|
you really do not want to rename " admin.php" to " admin_php"
|
|
1 members found this post helpful.
|
05-07-2015, 06:46 PM
|
#7
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
^ i thought it was weird too but that is what the op describes.
|
|
|
All times are GMT -5. The time now is 08:36 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
|
|