List file in current folder:
ls -al
total 92
drwxr-xr-x 2 debian debian 77824 Oct 28 12:31 .
drwxrwxrwt 27 root root 4096 Oct 28 12:35 ..
-rw-r--r-- 1 debian debian 31 Oct 28 12:23 '伪å'$'\302\205\302\203''ç´ .txt'
-rw-r--r-- 1 debian debian 13 Oct 28 12:22 'æµ'$'\302\213''é'$'\302\207\302\217''.txt'
-rw-r--r-- 1 debian debian 2061 Oct 23 22:29 conf.py
There are three files in the current folder ,the first two files are special,and the first one not only contains special character but also blank space in its filename.
Now print them with sed:
ls -al |sed -n '1,6p'
total 92
drwxr-xr-x 2 debian debian 77824 Oct 28 12:31 .
drwxrwxrwt 26 root root 4096 Oct 28 12:36 ..
-rw-r--r-- 1 debian debian 31 Oct 28 12:23 伪å
ç´ .txt
-rw-r--r-- 1 debian debian 13 Oct 28 12:22 æµé.txt
-rw-r--r-- 1 debian debian 2061 Oct 23 22:29 conf.py
How can fix it?
find
(or write a program in awk, perl, python, or whatever - almost anything that isn't shell) if you need to do anything more than just displaying filenames to a terminal for a human to read. – cas Oct 28 '22 at 09:50ls
knows whether it is outputting to a terminal, or something else (file, pipe, ...). When outputting to a terminal, it tries to make the output quoted (so you can paste it back into a shell), and readable by a human. Otherwise, it just outputs raw bytes. Tryls -l | cat -vet
andls -l | od -t x1ac
. – Paul_Pedant Oct 28 '22 at 19:02