0

System:

  • macOS Sierra 10.12.6

Raw input(example):

.
├── f1.md
├── f2.md
├── f3.md
├── f4.txt
├── f5.csv
└── f6.doc

0 directories, 6 files

In a test folder, there are 6 files.

Expected output:

.
├── all.tar
├── f1.md
├── f2.md
├── f3.md
├── f4.txt
├── f5.csv
└── f6.doc

0 directories, 7 files

Trying and Problem:

tar -cvf all.tar f1.md f2.md f3.md f4.txt f5.csv f6.doc 

Though I get the result from the above method but I have to inputing all file names and the compressed file name, which is inconvenient. For example , I can select all files and right click, then choose compressed option without inputing all.tar (I don't mind the .tar filenames.)

Hope:

command-line method without inputing specific file names.

  • @AFSHIN, how is that a duplicate? It looks like two completely different questions to me. – Stéphane Chazelas Aug 23 '17 at 13:09
  • You should be able to do tar cf file.tar . Most tar implementations should be clever enough, not to include file.tar itself in the archive. Or you could do tar cf file.tar ^file.tar (with zsh -o extendedglob) or !(file.tar) with ksh or zsh -o kshglob or bash -o extglob. – Stéphane Chazelas Aug 23 '17 at 13:13
  • @StéphaneChazelas OP doesn't want to put destination file name as target_tar_file.tar for example, so it's not possible and duplicated as marked one, if I'm wrong @OP please edit your question to clarity the difference of yours with duplicated one. while I see OP already confirmed it's duplicated. – αғsнιη Aug 23 '17 at 13:38
  • 1
    @AFSHIN, OK, it looks like I've misread the OP's question. Unfortunately it looks like I cannot retract my reopen vote – Stéphane Chazelas Aug 23 '17 at 13:48
0

Instead of inputting f1.md f2.md f3.md you can do *.md or f*.md: tar -cvf all.tar *.md

For your question about all.tar, what should the name be? Should it be generated randomly?

  • I had mentioned the right click method do not need user to input tar filename but create the same tar filename every time. You can try on Mac. – Jack Aug 23 '17 at 12:02
  • I have updated details. There are many different types of files besides .md. So it may be not convenient using * . – Jack Aug 23 '17 at 12:07
  • You could use *.* for any file type. – Jeff Huijsmans Aug 23 '17 at 12:30
  • The right-click option on Macs just generate a filename (mostly Archive.zip or something similar.) If you want an easy-to-use command to type, find out the command you want to use and alias it. For instance, if you'd like to use tar-all, add this to your .bashrc: alias tar-all="tar -cvf Archive.tar ./*". This will allow you to type tar-all and it'll create an Archive.tar which contains all the files in the current directory. – Jeff Huijsmans Aug 23 '17 at 12:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.