- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a zip file and ignore directory structure in Linux?
In order to be able to zip file and ignore directory structure that gets created with it, we first must understand what the zip command on Linux actually means and how we can make use of it.
The zip command that Linux provides us with allows us to specify a compression level with a number prefixed with dash and that number is usually in between 0 and 9. In simple terms, it is used to reduce the size of files with the help of compression and sometimes also used as a file package facility.
The compression of files actually involves one or more compressed filed and it compresses them into a single zip archive, along with some information about those files.
zip [OPTIONS] zipfile files
Consider a case where you want to convert a single file into a zip file, then the command shown below will allow you to do just the same.
zip file.zip sample.txt
-rw-r--r-- 1 immukul staff 661 Jul 14 09:00 file.zip
You can also unzip the zip file to get the files back with the help of the command shown below −
-rw-r--r-- 1 immukul staff 661 Jul 14 09:02 sample.txt
In order to make sure that you don’t get a directory structure mimicking the files, you can make use of the command shown below
zip -j zipContent d1/file.txt d2/2.txt d2/3.txt
In the above command, we can notice the -j option which stands for “junk the path”, that will help you in ignoring the directory structure.
-rw-r--r-- 1 immukul staff 2201512 Jul 14 09:19 zipContent.zip
- How to create a zip file using Python?
- How to Zip a directory in PHP?
- How to create a zip archive of a directory using Python?
- How to disable delete permission of File and Directory in Linux?
- How to change file or directory permission in Linux/Unix?
- How to copy a file, group of files, or directory in Linux?
- How to find the most recent file in a directory on Linux?
- How to Create a Shared Directory for All Users in Linux?
- How to create a new directory in Linux using the terminal?
- How to Create a New Ext4 File System in Linux?
- How to Create a New File in Linux from Bash?
- How can I create directory tree using C++ in Linux?
- How to create a new directory by using File object in Java?
- How to ignore a previously committed file in Git repository?
- How to Create a File in the Linux/Unix system using terminal?