Results 1 to 3 of 3
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 ...
- 02-16-2009 #1Just Joined!
- Join Date
- Jan 2007
- Posts
- 9
[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
aa.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
- 02-16-2009 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
This is what springs to mind
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 ``Code:tar -cvf "$(ls *.txt).tar" "$(ls *.txt)"
- 02-16-2009 #3Just Joined!
- Join Date
- Jan 2007
- Posts
- 9
Wow you're great. This is what I want
Thank you very much


