您可以尝试将以下Bash代码添加到〜/ .bash_profile中。它ls
在运行时更改命令$HOME
以不显示某些文件夹(“音乐”,“电影”,“图片”等)。
所有这一切都是更改目录中ls
显示的内容$HOME
。它实际上并没有删除文件夹。例如,如果您这样做,ls -l
您将看到文件夹仍然在那里。
function ls-home() {
excludeDirectories=(
"Music"
"Movies"
"Pictures"
"Public"
"Documents"
"Desktop"
"Downloads"
"VirtualBox VMs"
)
files=$(comm -23 <( /bin/ls -1) <(printf '%s\n' "${excludeDirectories[@]}" | sort))
temporary_dir=$(mktemp -d)
for file in $files; do
if [ -h $file ]; then
ln -s $file $temporary_dir/$file
elif [ -f $file ]; then
touch $temporary_dir/$file
if [ -x $file ]; then
chmod +x $temporary_dir/$file
fi
else
mkdir $temporary_dir/$file
fi
done
/bin/ls $temporary_dir
rm -rf $temporary_dir
}
function ls-shim() {
if [ "$(pwd)" = "$HOME" ]; then
lastArgument="${@:-1}"
if [ "${lastArgument:0}" = 1 ]; then
ls-home
else
/bin/ls "$@"
fi
else
/bin/ls "$@"
fi
}
alias ls="ls-shim"
运行中的脚本的屏幕截图: