Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    [SOLVED] Create file using tar and ls commands

    Hi All
    I have a file aa.txt

    I want to tar it. I'm using
    tar -cvf aa.tar aa.txt

    There's only one .txt file in my folder. I want to ls my folder, get the file's name and create a tar with its name

    ls *.txt

    And I want not to give the tar file's name directly, but use the result of ls as tar file's name. It's name will be aa.txt.tar

    Thank you very much

  2. #2
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    This is what springs to mind
    tar -cvf "$(ls *.txt).tar" "$(ls *.txt)"
    Though as soon as you have more than one file that's going to fail. It should give you some ideas though; Using $() to execute a command within a command is a very effective way of doing things quickly and simply. Using $() is considered the more modern and more correct equivalent to backticks ``

  3. #3
    Wow you're great. This is what I want
    Thank you very much

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts