enter image description here

what is that "non-printable" char called so I can use the proper term to find or ask How do I remove that Char in order to rename my file, getting rid of it without ridding any other Chars of formatting using a BASH script?

This is a script I am using but I am not getting the desired results.


typeset -i count
let count=0



MAXFILES="$(find "$working_dir" -type f | wc -l)"

find "$working_dir" -type f | while [[ $count -ne '3' ]] ; 
do read FILENAME;


 echo "extions is : $ext" echo

 if [[ "$ext" == 'mp3' ]] ; then

     echo "$ext" echo

     pref=$(tr -dc '[[:print:]]' <<< "$pref")

     ## holds on to normal chars rids the rest

    # pref=${pref//[^A-Za-z&0-9 ]/ }

     echo "new title is -> $pref"
     sleep 2

 # Newfile=${file%_*}

 # echo " mv -v "$working_dir"/"$file" "$working_dir"/"$Newfile" "

(( count++ ))



results being this

[userx@voided temp]$ ./Justrenamefiles

max file is : 311
FILENAME IS: /home/userx/temp/Joy Division - Ceremony (Graveyard     Studios, Prestwich - Previously
extions is : Joy Division - Ceremony (Graveyard Studios, Prestwich -     Previously echo
FILENAME IS: unreleased).mp3

extions is : mp3  

**new title is -> unreleased)**

as you can see it strips off way too much of the file name. trying both metholids what are in the script, one is now commented out, I still do not get my desired results.

does anyone know what code sniplet I can use to obtain my desired results?

  • Looks like someone's picture of a line-feed (0xa is ^J, also in scripting such as tr, you would refer to it as \n). Sep 3 '16 at 14:01
  • @ThomasDickey yes it is my picture of my files that ended up like that after running a script to resample them, that is the left overs that for some reason (I never checked into) ended up being renamed with that char in them. so basicly try rem0ving an endline "marker" within the name
    – uxserx-bw
    Sep 3 '16 at 15:43

This graphic represents the character whose Unicode value is 000A (in hexadecimal). This is the linefeed (LF) character, i.e. a line break.

Linux allows line breaks in file names, but they're highly unusual. It's possible to handle file names with line breaks in shell scripts, but you need to be especially careful. Your script parses the output of find, and since this output uses newlines to separate items, this method intrinsically cannot handle newlines in file names.

Your script is a lot more complicated than it needs to be. If you keep things simple, it'll work. As a general rule, act on data when you have it, rather than packing everything into a text stream and parsing it again.

With find, don't parse the output. Use the -exec action.

The simplest way to do this renaming (I'll replace the newlines by spaces) is with zsh, thanks to its zmv function.

autoload -U zmv   # put this in your .zshrc
cd $working_dir
zmv '**/*' $'${f//\n/ }'

If you really need to stick to programs that are always preinstalled on non-embedded Linux, here's a simple (if somewhat slow) method that relies on bash to do the renaming:

find "$working_dir" -type f -name '*
*' -exec bash -c 'mv "$0" "${0//
/ }"' {} \;

You can speed this up by invoking bash on batches of files:

find "$working_dir" -type f -name '
' -exec bash -c 'for x; do mv "$x" "${x//
/ }"' _ {} +

If there's a single newline, on Linux, you can use the rename command (called rename.ul on Debian and derivatives).

find "$working_dir" -type f -name '
' -exec rename '
' ' ' {} +

If you have prename:

find "$working_dir" -type f -name '
' -exec prename 'y/\n/ /' {} +
  • so I installed zsh. to give it a shot. set it up using its set up, set it as defualt shell, changed dir to a where I have them files needing fixing, added autoload -U zmv to my .zhrc file. evern rebooted just cuz, opened up a term, cd to directory, issued the zmv '*/' $'${f//\n/ }' and got nothing, no changes whatsoever of any kind.
    – uxserx-bw
    Sep 23 '16 at 16:10
  • the second suggestion didn't work either, I am getting back this error. ... are the same file
    – uxserx-bw
    Sep 23 '16 at 16:17
  • @uxserx-bw You must have run a different command from the one I posted. Note that the file is ~/.zshrc, not ~/.zhrc, but even so you would have had an error message, not nothing. Sep 23 '16 at 17:18
  • that was just a typo on my part it was .zshrc I meant to write, its late right now, if I find time I will play with it tomorrow. give feedback
    – uxserx-bw
    Sep 24 '16 at 1:33

The problem is that your filenames contain a newline, eg aaa\nbbb, and your find | read method cannot distinguish this from two files, aaa and bbb.

The usual answer to this is to get find to separate filenames with the nul character \0 by using find -print0 and then using IFS= read -r -d '' FILENAME to read this input stream. The -d '' tells read to use the nul character as line delimiter, -r stops backslash processing, and IFS= preserves blanks at start and end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.