如何[tar和]压缩Emacs中的标记文件

Sab*_*lfy 8 emacs dired

dired+Debian Squeeze变体的Emacs 23.2.1中,我选择了四个文件*然后按Z下来压缩它们.我回答y了提示,并在迷你缓冲区中看到了一些状态更新.我在哪里可以找到压缩文件?我测试了一个文件(C-u Z),Emacs在一个文件上运行了gzip,并将其作为.gz文件.我如何[tar和]压缩Emacs中的标记文件?

(为了抢占关于tar,gzip,其他格式和档案的任何哲学或方法论讨论,我想要的只是四个文件作为压缩数据存储在一个文件中.如果可以通过tar和gzip实现或直接压缩每个文件进入档案并不重要.)

leg*_*cia 18

如果dired+是这样的话dired,你可以用文件标记m然后点击!(在标记的文件上运行shell命令)并将命令指定为tar -czf foo.tar.gz *(这*是一个特殊标记,由标记文件的名称替换).


Chr*_*han 6

您也可以通过标记文件并将其复制到存档文件来存档文件.

例如,在dired中标记多个文件,然后选择m-x dired-do-copy.

提示输入目的地时,键入test.zip.这些文件将自动添加到zip存档中.

您还可以通过在dired中选择并运行命令来解压缩文件 dired-do-extract

要进行此设置,请查看以下变量:dired-to-archive-copy-alist dired-extract-alist

这是我的设置,这已经服务了我多年......

;; dired-a provides support functions, including archiving, for dired
(load "dired-a")

;; Alist with information how to add files to an archive (from dired-a)
;; Each element has the form (REGEXP ADD-CMD NEW-CMD). If REGEXP matches
;; the file name of a target, that target is an archive and ADD-CMD is a command
;; that adds to an existing archive and NEW-CMD is a command that makes a new
;; archive (overwriting an old one if it exists). ADD-CMD and NEW-CMD are:
;; 1. Nil (meaning we cannot do this for this type of archive) (one of
;;    ADD-CMD and NEW-CMD must be non-nil).
;; 2. A symbol that must be a function e.g. dired-do-archive-op.
;; 3. A format string with two arguments, the source files concatenated into
;;    a space separated string and the target archive.
;; 4. A list of strings, the command and its flags, to which the target and
;;    the source-files are concatenated."
(setq dired-to-archive-copy-alist
      '(("\\.sh\\(ar\\|[0-9]\\)*$" nil "shar %s > %s")
    ("\\.jar$" ("jar" "uvf") ("jar" "cvf"))
    ("\\.tar$" ("tar" "-uf") ("tar" "-cf"))
    ("\\.tgz$\\|\\.tar\\.g?[zZ]$" ("tar" "-uf %s" "|" "gzip > %s") ("tar" "-czvf"))
    ("\\.ear$" ("zip" "-qr") ("zip" "-qr"))
;   ("\\.rar$" ("rar" "a")   ("rar" "a"))
    ("\\.war$" ("zip" "-qr") ("zip" "-qr"))
    ("\\.zip$" ("zip" "-qr") ("zip" "-qr"))
    ("\\.wmz$" ("zip" "-qr") ("zip" "-qr")) ;; for media player skins
    ("\\.arc$" ("arc" "a") nil)
    ("\\.zoo$" ("zoo" "aP") nil)
    ))

;; use pkzip with manipulating zip files (t) from within dired (use zip
;; and unzip otherwise)
(setq archive-zip-use-pkzip nil)

;; add these file types to archive mode to allow viewing and changing
;; their contents
(add-to-list 'auto-mode-alist '("\\.[ejrw]ar$\\'" . archive-mode))

;; modify the dired-extract switches to use the directory
;; ~/download/tryout as the default extract directory for zip files
(defconst MY_TRYOUT_DIR "~/downloads/tryout"
  "Directory for extracting files")

(setq dired-extract-alist
      `(
    ("\\.u\\(ue\\|aa\\)$" . dired-uud)
    ("\\.jar$" . "jar -xvf %s")
    ("\\.tar$" . ,(concat "tar -xf %s -C " MY_TRYOUT_DIR))
    ("\\.tgz$\\|\\.tar\\.g?[zZ]$" . ,(concat "tar -xzf %s -C " MY_TRYOUT_DIR))
    ("\\.arc$" . "arc x %s ")
    ("\\.bz2$" . ,(concat "bunzip2 -q %s"))
    ("\\.rar$" . ,(concat "unrar x %s " MY_TRYOUT_DIR "\\"))
    ("\\.zip$" . ,(concat "unzip -qq -Ux %s -d " MY_TRYOUT_DIR))
    ("\\.ear$" . ,(concat "unzip -qq -Ux %s -d " MY_TRYOUT_DIR))
    ("\\.war$" . ,(concat "unzip -qq -Ux %s -d " MY_TRYOUT_DIR))
    ("\\.zoo$" . "zoo x. %s ")
    ("\\.lzh$" . "lha x %s ")
    ("\\.7z$"  . "7z e %s ")
    ("\\.g?[zZ]$" . "gzip -d %s")   ; There is only one file
    ))
Run Code Online (Sandbox Code Playgroud)

  • 还进行直接复制似乎并不像您所描述的那样工作,我认为您必须有一个扩展才能启用此功能,我只是收到一个错误,目标必须是一个目录 (2认同)