我们经常遇到文件和文件夹名称。 在大多数情况下,文件/文件夹名称与文件/文件夹的内容相关,并以数字和字符开头。 Alpha数字文件名是相当普遍和非常广泛使用,但是这不是这样的情况,当我们必须处理文件/文件夹名称中有特殊字符。
除了把这样命名的人拖出去打一顿之外,你还是需要学会如何处理这样的文件的。。。详情见上面链接。
『贰』 linux命令行下文件名中有空格的处理方法
Q:我在树莓派命令行模式下使用mplayer播放单首音乐,因为文件名中含有空格,提示不存在该文件,该如何解决?
[johnwick@raspberrypi~]$sudo mplayer Me like yuh.mp3
MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2017 MPlayer Team
Cannot open file '/root/.mplayer/input.conf': No such file or directory
Failed to open /root/.mplayer/input.conf.
Cannot open file '/etc/mplayer/input.conf': No such file or directory
Failed to open /etc/mplayer/input.conf.
Playing Me.
Cannot open file 'Me': No such file or directory
Failed to open Me.
Playing like.
Cannot open file 'like': No such file or directory
Failed to open like.
Playing yuh.mp3.
Cannot open file 'yuh.mp3': No such file or directory
Failed to open yuh.mp3.
A:mplayerh播放当前目录下单首歌曲的格式为: mplayer [文件名],显然系统认为 Me like yuh.mp3 是三个独立文件
解决办法:①使用引号(英文输入法下)将文件名全部包含: mplayer "Me like yuh.mp3"
方法②空格前使用连接符号"\" : mplayer Me\ like\ yuh.mp3 “\”告诉系统后面跟着的字符为原意,不是命令
完毕。
『叁』 linux shell 脚本中 如何处理带空格的超长目录名 如下:
#/bin/bash
OLDIFS=$IFS
IFS=$'\n'
myhome=`pwd`
for str in `find . -type d `
do
cd $myhome
if [ `expr index "$str" "#"` -eq 0 ]
then
echo "process $str"
cd "$str"
fi
done
IFS=$OLDIFS
『肆』 linux里面的命令:./和. /【第二个有空格】,分别怎么用。
./ 点号紧跟/表示当前目录(相对路径的写法)。直接 / 表示根目录。
. / 有空格的点号等同于source命令,表示在当前shell环境执行后面的命令或脚本(不加点号默认是新开一个shell执行的)。例如 . /home/test.sh 等同于 source /home/test.sh。
用source执行的脚本所做的任何改变会影响当前shell(如其中有用cd改变目录,脚本执行完后目录就变掉了);如果没用source,就不会影响当前shell。
上述两种情况结合:
. ./test.sh
表示以source方式在当前shell执行当前目录下的test.sh脚本。
对新手来说,为明显区别,建议书写的时候将第二种情况直接写作source而不要用点号。
『伍』 linux 下,打开一个文件把里面的空格替换成“:"怎么弄啊
你是想用命令把里面的所有的空格都改为:吗,还是怎么啊,如果只改几个的话,用vi就可以,如果是批量的话,还是用命令把,sed 's/ /:/g' filename
sed命令我也不大会,你自己看一下参考资料,我也不怎么用linux的