Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-12-05 14:25:59

cmcanulty
Member
From: Beulah, Michigan
Registered: 2014-05-10
Posts: 259

remove a character from all files

I would like a script to remove a character, for example like | , [, {, ], } from all files in my home directory. I don't want to remove the files just specified characters and either replace with nothing a or something else. Sed seems to do this for individual files but I want to do a bulk rename or any files with a certain character. There may be hundreds of them. Like open a terminal in my home directory and enter a command to do that for all files. Thank you

Offline

#2 2021-12-05 15:28:38

KBar
Moderator
Registered: 2021-11-05
Posts: 689

Re: remove a character from all files

Are we talking about file names or file content?

For file names, there Thunar Bulk Renamer.

For file content, sed does the job. Try with the --separate option.


Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#3 2021-12-05 16:57:11

cmcanulty
Member
From: Beulah, Michigan
Registered: 2014-05-10
Posts: 259

Re: remove a character from all files

I am talking about file and directory names only not the files themselves.I have used that in the past but it only allows you to search files not directories and whenever I try to just remove a character you have to say a number from the front or end of a file so it is impossible to do several files at once as the character is in a different location in each file name. Maybe I am missing something

update I found an app called "file renamer"  and it does exactly like I want, thank you

Last edited by cmcanulty (2021-12-05 17:05:29)

Offline

#4 2021-12-12 02:03:15

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 812

Re: remove a character from all files

do you have the "rename" command?  it lets you modify file names matching a regular expression.  suppose you want to remove all "_" characters from all file names in the current directory.

rename -v s/_//g *_*

the -v is to have it show what it renames.  the "g" is to have it o multiple changes in each name.  it works much like the "sed" command.

or suppose you want to change every space to the character "_".  for this the big expression argument needs to be in quotes so the shell will pass the space character to the "rename" program.

rename -v 's/ /_/g' *

even though the * will give it every file name it only makes changes on the file names that match the expression (has a space in this case).

notice:  i just typed in these commands.  i have not actually tested them.

Offline

#5 2021-12-12 13:04:08

cmcanulty
Member
From: Beulah, Michigan
Registered: 2014-05-10
Posts: 259

Re: remove a character from all files

Thanks that seems to work. To make it more useful though with my 500GB of files is there a way for it to include subfolders? Also weirdly it seems to not work with  [ ] { }

Last edited by cmcanulty (2021-12-12 13:32:21)

Offline

Board footer

Powered by FluxBB