这打算做什么?
ls 列出当前目录中的文件 
$(ls)替换ls作为参数的场所的输出rm 
- 本质上
rm $(ls)是旨在删除当前目录中的所有文件 
这幅画怎么了?
ls无法正确处理文件名中的特殊字符。Unix用户通常建议使用不同的方法。在有关文件名计数的一个相关问题中,我还展示了这一点。例如:
$ touch file$'\n'name                                                                                                    
$ ls                                                                                                                     
file?name
$ rm $(ls)
rm: cannot remove 'file': No such file or directory
rm: cannot remove 'name': No such file or directory
$ 
而且,正如Denis的答案中正确提到的那样,带前划线的文件名可以解释为rm替换后的参数,这违背了删除文件名的目的。
什么有效
您要删除当前目录中的文件。所以使用glob rm *:
$ ls                                                                                                                     
file?name
$ rm $(ls)
rm: cannot remove 'file': No such file or directory
rm: cannot remove 'name': No such file or directory
$ rm *
$ ls
$ 
您可以使用find命令。经常建议将该工具用于当前目录以外的其他地方-它可以递归遍历整个目录树,并通过-exec . . .{} \; 
$ touch "file name"                                
$ find . -maxdepth 1 -mindepth 1                                                                                         
./file name
$ find . -maxdepth 1 -mindepth 1 -exec rm {} \;                                                                          
$ ls
$ 
Python在文件名中没有特殊字符的问题,因此我们也可以使用它(请注意,这仅用于文件,您将需要使用,os.rmdir()并且os.path.isdir()如果要在目录上进行操作):
python -c 'import os; [ os.remove(i) for i in os.listdir(".") if os.path.isfile(i) ]'
实际上,~/.bashrc为简便起见,上述命令可以转换为函数或别名。例如,
rm_stuff()
{
    # Clears all files in the current working directory
    python -c 'import os; [ os.remove(i) for i in os.listdir(".") if os.path.isfile(i) ]'
}
的Perl版本将是
perl -e 'use Cwd;my $d=cwd();opendir(DIR,$d); while ( my $f = readdir(DIR)){ unlink $f;}; closedir(DIR)'