隐藏多个文件?

隐藏多个文件?

我有一组文件需要隐藏以避免混乱。是否有命令可以简单地隐藏多个文件?是否有应用程序?是否有单个命令可以隐藏我列出的文件?

谢谢。

答案1

有一个 nautilus 脚本可以实现这个功能:

#!/bin/bash

# Hide-Unhide-In-Nautilus.sh
# Creator: Inameiname
# Date: 21 June 2011
# Version: 1.0
#
#
# This is a simple nautilus script to automatically add file(s)/folder(s)
# to a ".hidden" file so Nautilus will hide them, just like ".*" files
# Instructions:
# - decide what file(s)/folder(s) you want to hide inside a particular folder,
# - highlight them, and right click and select the script
# - it will automatically add the filenames to a created ".hidden" file inside the directory
# - if ".hidden" isn't there, it will add it
# - if you decide to unhide things, simply highlight and select the script again,
# - and it will automatically remove the filenames from the ".hidden" file
# - if ".hidden" contains no filenames, it will remove it
#
#
# Optionals:
# - Add the option to change the owner and group for whatever is selected to hide/unhide
# - Add the option to add the permissions for whatever is selected to hide/unhide
# - Add the option to make executable whatever is selected to hide/unhide
#
#
# Remember this only works inside the current directory/opened folder and files/folders inside that folder.
# Just comment out or uncomment whatever desired.
# Currently, only the ability to hide/unhide stuff is uncommented,
# but you can always just comment it out, and uncomment one of the "Make Executable" commands,
# and/or one of the "Change the owner and/or group of each file" commands,
# and/or one of the "Add permissions" commands, or mix and match whatever you want.
#
#
# For the changes to take effect to the file(s)/folder(s) you hid/unhid, you may have to refresh the folder, or even Nautilus



# Set IFS so that it won't consider spaces as entry separators.
# Without this, spaces in file/folder names can make the loop go wacky.
IFS=$'\n'

# See if the Nautilus environment variable is empty
if [ -z $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ]; then
    # If it's blank, set it equal to $1
    NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$1
fi

# Loop through the list (from either Nautilus or the command line)
for ARCHIVE_FULLPATH in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
    NEWDIRNAME=${ARCHIVE_FULLPATH%.*}
    FILENAME=${ARCHIVE_FULLPATH##*/}
    NAME=${ARCHIVE_FULLPATH##*/.*}

    # Hide/Unhide file(s)/folder(s) using ".hidden" file within the current folder
      # Copies all selected files/folders filenames to ".hidden"
        echo $FILENAME >> .hidden
      # Sorts and Checks ".hidden" for any duplicates
        sort .hidden | uniq -u > .hidden_temp
        rm .hidden
        mv .hidden_temp .hidden
      # Checks ".hidden" to see if there is anything there; if not, it removes it
        for file in .hidden
        do
          if [ `wc -l < $file` -eq 0 ]; then
             # file is empty
             rm $file
          fi
        done
    # Change the owner and/or group of each FILE to OWNER and/or GROUP, if desired
      # chown -R $USER:$USER $ARCHIVE_FULLPATH # set owner:group to current user
      # gnome-terminal -x sudo chown -R root:root $ARCHIVE_FULLPATH # set owner:group to root
      # gnome-terminal -x sudo chown -R $USER:$USER $ARCHIVE_FULLPATH # set owner:group to current user
    # Add permissions, if desired
      # chmod 444 $ARCHIVE_FULLPATH # read-only permissions for all
      # chmod 600 $ARCHIVE_FULLPATH # read/write for you, no permissions for rest
      # chmod 644 $ARCHIVE_FULLPATH # read/write for you, read-only permissions for rest (default)
      # sudo chmod 444 $ARCHIVE_FULLPATH # read-only permissions for all
      # sudo chmod 600 $ARCHIVE_FULLPATH # read/write for you, no permissions for rest
      # sudo chmod 644 $ARCHIVE_FULLPATH # read/write for you, read-only permissions for rest (default)
    # Make executable, if desired
      # chmod +x $ARCHIVE_FULLPATH
      # gnome-terminal -x sudo chmod +x $ARCHIVE_FULLPATH

done

# Add a notification when finished, if desired
    notify-send -t 2000 -i /usr/share/icons/gnome/32x32/status/info.png "Job Finished"

来源:http://gnomefiles.org/content/show.php/Easily+Hide+Files%2BFolders+in+Nautilus?content=142912


将上述代码框的内容复制并粘贴到新文档中。保存并重命名为隐藏或取消隐藏. 使其可执行(右键单击 -->特性-->权限-->允许作为程序执行文件)。然后将文件移动到~/.gnome2/nautilus-scripts

您现在应该能够从 nautilus 上下文菜单访问脚本。只需右键单击要隐藏或取消隐藏的任何文件,然后选择脚本-->隐藏或取消隐藏。您必须重新加载文件夹 ( F5) 才能看到更改

这种方法的优点(除了易于使用之外)是它不会重命名文件。

答案2

Linux 惯例是将它们重命名为以 开头.。大多数程序,包括 Nautilus(GNOME 文件浏览器)、Dolphin(KDE)和命令行程序(如lsBash 的 shell 通配符)都会隐藏它们(默认情况下)。

要同时重命名多个文件,您可以使用以下几种图形工具之一:

.在 PyRenamer 中,选择您的文件,激活“插入/删除”选项卡,并告诉它在位置 1 处插入:

样品比伦纳

从命令行,常规方法是使用mvfind(如果需要)。如果您只想隐藏几个特定文件,请运行:

for f in file0 file1 file2 file3; do mv "$f" ".$f"; done

.在每个文件的名称后附加一个。

如果您想要隐藏多个名称相似的文件(例如,以 开头的任何文件hideme),请使用 shell 通配符:

for f in hideme*; do mv "$f" ".$f"; done

答案3

要执行与上述 Nautilus 脚本相同的操作,也可以添加隐藏/取消隐藏菜单到 Nautilus,通过安装nautilus-actions-extra 包通过PPA渠道这里:https://launchpad.net/~nae-team/+archive/ppa

相关内容