I want to decompress a file, I wrote this command:

bunzip2 linux-source-4.15.0.tar.bz2

and I got this:

bunzip2: Input file linux-source-4.15.0.tar.bz2 is not a normal file.

I want to know exactly what is the problem.

I ran file linux-source-4.15.0.tar.bz2 and I got:

linux-source-4.15.0.tar.bz2: symbolic link to linux-source-4.15.0/linux-source-4.15.0.tar.bz2
  • 3
    Try running file linux-source-4.15.0.tar.bz2 and update the question with the output. – Soren A Jul 10 at 13:27
  • Same issue: askubuntu.com/questions/1113606/…. 1 possible reason: bunzip2 does not understand symlinks and will through that error then. – Rinzwind Jul 10 at 13:52
  • I run file linux-source-4.15.0.tar.bz2 and I got linux-source-4.15.0.tar.bz2: symbolic link to linux-source-4.15.0/linux-source-4.15.0.tar.bz2 – muna mustafa Jul 10 at 14:33

TL;DR: You can extract the whole archive with tar xf.

As Rinzwind mentioned, bunzip2 unfortunately refuses to operate on symbolic links. The output of file revealed that your .bz2 file is a symlink rather than a regular file.

How you should go about decompressing the file depends on specifically what you want to do. Considering the particular file you are operating on, it's likely that your bunzip2 command wouldn't have done quite what you wanted anyway, and that you should extract it with tar instead.

If you want to unpack the tar archive itself

Your .tar.bz2 file is a tar archive that is bzip2-compressed. You've asked just how to uncompress the file, which you can do (see below). But if you do that, the result will be an uncompressed archive, whose contents you'd then likely want to extract.

The tar command, which creates and extracts tar archives, can handle compression itself. You can extract the files from this compressed archive the same way you would for an uncompressed tar archive, because tar automatically detects and handles compression:

tar xf linux-source-4.15.0.tar.bz2

You might want to extract the file as your own non-root user, which you can do if you put it somewhere you have write permissions. If this is what you want, I suggest going to the destination and extracting it by giving its full path. For that file, this might be:

tar xf /usr/srclinux-source-4.15.0.tar.bz2

If you want tar to list each file as it extracts it, add the v option:

tar xvf linux-source-4.15.0.tar.bz2

If, for some reason, you wanted to tell tar explicitly that the archive you're extracting is bzip2-compressed, you could do so by adding the j option:

tar xvjf linux-source-4.15.0.tar.bz2

(You can use the v and j options regardless of whether the path that follows the f option is absolute or relative.)

If you want to create a decompressed copy of the file

If you want to decompress the file and place the result in the current directory, you can use bzcat -d and redirect the result:

bzcat -d linux-source-4.15.0.tar.bz2 >linux-source-4.15.0.tar

If you want to replace the target with a decompressed file

If you want to decompress the target of the symlink, replacing it with the original (uncompressed) file, then you can use realpath to dereference the symlink. In this case, I strongly doubt you want that, but here's what it looks like, for future reference:

bunzip2 "$(realpath linux-source-4.15.0.tar.bz2)"

Or just find the target and pass it to bunzip2, since you should definitely check what the target of a symlink is before performing an operation that removes it and replaces it with something else (in case you're mistaken and the target isn't what/where you think it is). To find the target, you can run that realpath command by itself:

realpath linux-source-4.15.0.tar.bz2

Of course, you can also inspect files with ls -l, file, and readlink to find out if they are symlinks and what their direct target is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.