Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Problems with Using the exclude Options

Some users find ‘exclude’ options confusing. Here are some common pitfalls:

  • The main operating mode of tar does not act on a path name explicitly listed on the command line if one of its file name components is excluded. In the example above, if you create an archive and exclude files that end with ‘*.o’, but explicitly name the file ‘dir.o/foo’ after all the options have been listed, ‘dir.o/foo’ will be excluded from the archive.
  • You can sometimes confuse the meanings of --exclude and --exclude-from. Be careful: use --exclude when files to be excluded are given as a pattern on the command line. Use --exclude-from to introduce the name of a file which contains a list of patterns, one per line; each of these patterns can exclude zero, one, or many files.
  • When you use --exclude=pattern, be sure to quote the pattern parameter, so GNU tar sees wildcard characters like ‘*’. If you do not do this, the shell might expand the ‘*’ itself using files at hand, so tar might receive a list of files instead of one pattern, or none at all, making the command somewhat illegal. This might not correspond to what you want.

    For example, write:

              $ tar -c -f archive.tar --exclude '*.o' directory
         

    rather than:

              $ tar -c -f archive.tar --exclude *.o directory
         
  • You must use use shell syntax, or globbing, rather than regexp syntax, when using exclude options in tar. If you try to use regexp syntax to describe files to be excluded, your command might fail.
  • In earlier versions of tar, what is now the --exclude-from option was called --exclude instead. Now, --exclude applies to patterns listed on the command line and --exclude-from applies to patterns listed in a file.

 
 
  Published under the terms of the GNU General Public License Design by Interspire