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

时间:2012-04-19 11:14:04

标签: emacs dired

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

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

4 个答案:

答案 0 :(得分:17)

如果dired+dired类似,则可以使用 m 标记文件,然后点击(运行shell命令)标记的文件)并将命令指定为tar -czf foo.tar.gz **是一个特殊标记,由标记文件的名称替换。)

答案 1 :(得分:5)

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

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

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

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

来解压缩文件

要进行此设置,请查看以下变量:     dired到归档拷贝ALIST     dired提取物-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
    ))

答案 2 :(得分:1)

平台:Ubuntu

<强>要求

系统:
    sudo apt-get install atool

的Emacs:
    M-x package-list-packages
    C-s dired-atool RET
    我
    X

<强>解决方案

1)在dired buffer中标记文件 2)M-x dired-atool-do-pack 注意:确保将shell-file-name设置为&#34; / bin / bash&#34;。

答案 3 :(得分:0)

为回答后一个问题,可以使用另一种工具从{died {3}}生成压缩的tar文件。标记所需的文件并执行{ "name": "Dep","color":"blue", "children": [ { "name": "AAA","color":"blue", "children": [ { "name": "Umwelt","color":"blue", "children": [ {"name": "AgglomerativeCluster","color":"blue", "size": 3938}, {"name": "CommunityStructure","color":"blue", "size": 3812}, {"name": "HierarchicalCluster","color":"blue", "size": 6714}, {"name": "MergeEdge","color":"blue", "size": 743} ] }, { "name": "Landwirtschaft","color":"green", "children": [ {"name": "BetweennessCentrality","color":"blue", "size": 1}, {"name": "LinkDistance", "color":"blue","size": 1}, {"name": "MaxFlowMinCut", "color":"blue","size": 1}, {"name": "ShortestPaths", "color":"blue","size": 1}, {"name": "SpanningTree", "color":"blue","size": 1} ] }, { "name": "Energie","color":"blue", "children": [ {"name": "AspectRatioBanker","color":"blue", "size": 7074} ] } ] }, { "name": "BBB","color":"blue", "children": [ { "name": "cluster","color":"blue", "children": [ {"name": "AgglomerativeCluster","color":"blue", "size": 3938}, {"name": "CommunityStructure","color":"blue", "size": 3812}, {"name": "HierarchicalCluster","color":"blue", "size": 6714}, {"name": "MergeEdge","color":"blue", "size": 743} ] }, { "name": "graph","color":"green", "children": [ {"name": "BetweennessCentrality","color":"blue", "size": 3534}, {"name": "LinkDistance", "color":"blue","size": 5731}, {"name": "MaxFlowMinCut", "color":"blue","size": 7840}, {"name": "ShortestPaths", "color":"blue","size": 5914}, {"name": "SpanningTree", "color":"blue","size": 3416} ] }, { "name": "optimization","color":"blue", "children": [ {"name": "AspectRatioBanker","color":"blue", "size": 7074} ] } ] } ] } ,将pack-dired-do-pack指定为输出文件名。