|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
gzip of a file in the same folder
I want gzip of a file in the same folder where it is kept now $filename = '/var/dev/test.txt' /opt/home/>> Code:
gzip -c $filename > test.txt.gz however command creates it in the folder in /opt/home/ How to gzip a file in the same directory where it is now , no matter from where we execute and also the file path and folder is selected from variable and hence cant hardcode in gzip command |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Use regex to extract the path (everything to the left of the last slash) from $filename into $filepath, then use that in your command: Code:
gzip -c $filename > $filepath/test.txt.gz Last edited by Scrutinizer; 04-26-2012 at 09:02 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
since the path is already given in the filename, and you are only adding .gz suffix, you shouldn't have to strip the path to add it back again... Code:
gzip -c "$filename" > "$filename.gz" this way /var/dev/test.txt goes to /var/dev/test.txt.gz |
| Sponsored Links | ||
|
![]() |
| Tags |
| gzip a file in same folder, parameter expansion |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gzip vs pipe gzip: produce different file size | hanfresco | UNIX for Advanced & Expert Users | 1 | 06-03-2011 10:48 PM |
| gzip a file and append creation date stamp to file | jacktravine | Solaris | 3 | 09-22-2009 10:09 AM |
| File Management: How do I move all JPGS in a folder structure to a single folder? | guptaxpn | Shell Programming and Scripting | 4 | 06-11-2009 02:41 AM |
| Parse the .txt file for folder name and FTP to the corrsponding folder. | MeganP | Shell Programming and Scripting | 3 | 07-03-2007 01:54 PM |
| How do I send a file as an attachment (gzip file) on a Unix system | lacca | UNIX for Dummies Questions & Answers | 3 | 07-03-2002 01:04 PM |
|
|