Re: remove double quote character from file names
- In reply to: Polytropon : "Re: remove double quote character from file names"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Feb 2023 12:03:13 UTC
On 16/02/2023 10:24, Polytropon wrote: > On Thu, 16 Feb 2023 08:20:09 +0100 (CET), Sysadmin Lists wrote: >> [...] >> Just to throw in an awk-themed solution: >> $ ls -1 | awk '/"/ { system("mv -v '\''" $0 "'\'' " $0) }' >> >> $ touch "\"foo bar\"" \"baz\" \".zap\" xyz abc >> $ ls -1A >> ".zap" >> "baz" >> "foo bar" >> abc >> xyz >> $ ls -1 | awk '/"/ { system("mv -v '\''" $0 "'\'' " $0) }' >> ".zap" -> .zap >> "baz" -> baz >> "foo bar" -> foo bar >> $ ls -1A >> .zap >> abc >> baz >> foo bar >> xyz >> >> There's a clever use of the existing double-quotes in the filenames >> in the renaming. > > This is actually a quite clever "ab"use of existing quotes. > > Just a friendly sidenote: > > Never expect anything. It _might_ be possible that filenames > such as > > foo "bar" blah.txt > "meow" 123.dat > doodle "boo" .c++ > -my brain hurts ."tar".gz > > exist in the heap of files to be processed. Selecting a good > delimiter for input files is hard. Using the "IFS = \n" approach > works - as long as there are no newlines in filenames (which > I'm not sure could also be allowed)... ;-) Newlines are allowed in filenames. The only characters that aren't are NUL and '/' (at least for Unix-like file systems). Years ago, when ls showed filenames literally including any newlines, I played a trick on a colleague by creating a directory in his home directory that looked exactly like the ls of the home directory, and moving all other files and directories into it. It took 15 minutes of increasing curses before he said "alright, what have you done and how do I get out of it?". -- We build our computer systems the way we build our cities; over time, without a plan, on top of ruins. — Ellen Ullman