Linux file sharing artifact: usage and advantages of shar
If you often need to send and receive multiple files in a Linux system, you may encounter some troubles. You may need to compress the file into tar, gz, zip, etc. format and then send it to your contact. However, your contact may not know how to decompress these files or need to install additional programs to process them. Is there an easier and more convenient way to share Linux files? The answer is yes, that is to use the shar tool. shar is a command line tool that can "package" multiple files into an executable script file. If you send this file to your contacts, they just need to make sure it has execute permissions and then run it to automatically extract the original file. There are no complicated commands and no need to guide them through the process. This article will introduce you how to use shar to create self-extracting files in Linux, and introduce some of its usage and advantages.
Install Shar
Shar is not included by default in most Linux distributions, so you must install it first to create an automatically extracted Shar file archive. However, you won't find it in the Software Center, nor through apt yourself. Instead, you will have to install the larger "sharutils" package that contains it. To do this, launch a terminal and use the following command:
[linuxidc@linux:~/www.linuxidc.com]$ sudo apt install sharutils

Find and prepare files
Shar is a command line tool that processes a large number of files at once and places them in a single archive. So, for convenience and ease of use, create a temporary folder and then move or copy all the files you want to include in the shar archive into that temporary folder.
With your terminal still active, cd to your newly created directory.
Packaging file
To create your shar archive, run the following command:
[linuxidc@linux:~/www.linuxidc.com]$ cd linuxidc [linuxidc@linux:~/www.linuxidc.com/linuxidc]$ ls linuxidc.com.jpg linuxidc.com.py linuxidc.[Java](https://www.linuxidc.com/Java) linuxidc.com.png linuxidc.com.sh [www.linuxidc.com.ogg](http://www.linuxidc.com.ogg/) [linuxidc@linux:~/www.linuxidc.com/linuxidc]$ shar ./* > ../linuxidc.shar shar: 保存 ./linuxidc.com.jpg (文本文件) shar: 保存 ./linuxidc.com.png (文本文件) shar: 保存 ./linuxidc.com.py (文本文件) shar: 保存 ./linuxidc.com.sh (文本文件) shar: 保存 ./linuxidc.java (文本文件) shar: 保存 ./www.linuxidc.com.ogg (文本文件)
Change "Archive File Name" to your file name.

Let us "decompose" it, and let's see how it works.
Of course, the initial shar is the program itself.
The ./* is the input, and in this particular case it means "we are going to all the files in that directory."
> is the allocator between the input and output of the command. The program understands this as "merge each input on the left side of the bracket into a single file defined on the right side of the bracket".
../linuxidc.shar is the path and name of the output file. You can change it to whatever you want.
The process is very quick, usually taking no more than a few seconds (depending on the performance of your PC).
After creating the archive file, you can share the new file with your contacts. Although they also require sharutils to be installed for automatic extraction to work, as you will see in the next step, everything will be simpler than working with typical archives.
Extract shar file
When your friend receives the shar archive, all they have to do is make it executable and then run it.
Assuming your friend has sharutils installed, they can extract the files using the following command:
[linuxidc@linux:~/www.linuxidc.com/linuxidc.com]$ ls linuxidc.com.shar [linuxidc@linux:~/www.linuxidc.com/linuxidc.com]$ chmod +x linuxidc.com.shar [linuxidc@linux:~/www.linuxidc.com/linuxidc.com]$ ./linuxidc.com.shar x - created lock directory _sh33861. x - extracting linuxidc.com.jpg (文本文件) x - extracting linuxidc.com.png (文本文件) x - extracting linuxidc.com.py (text) x - extracting linuxidc.com.sh (文本文件) x - extracting linuxidc.java (文本文件) x - extracting www.linuxidc.com.ogg (文本文件) x - removed lock directory _sh33861.

That’s it – the files it contains are extracted into the same folder. We can now delete the original files they sent us.
Most Linux desktops provide full support for compression formats such as tar, gz, zip, etc., so shar is not very useful in this case. However, if you are using Linux in a server (or headless) environment, shar is very useful because you can easily extract archive files without having to remember various commands - no extra steps, no flags and switches, no Requires additional programs to be installed.
Through the introduction of this article, you should have mastered how to use shar to create self-extracting files in Linux. shar is a very useful tool that allows you to easily share Linux files without worrying about file formatting and decompression. shar also has some other features and options that give you more control and customization of your shar files. For example, you can add comments, passwords, checksums, and other information to your shar files to increase readability and security. You can also use the unshar command to extract the contents of a shar file instead of running it directly.
The above is the detailed content of Linux file sharing artifact: usage and advantages of shar. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
How to install software on Linux using the terminal?
Aug 02, 2025 pm 12:58 PM
There are three main ways to install software on Linux: 1. Use a package manager, such as apt, dnf or pacman, and then execute the install command after updating the source, such as sudoaptininstallcurl; 2. For .deb or .rpm files, use dpkg or rpm commands to install, and repair dependencies when needed; 3. Use snap or flatpak to install applications across platforms, such as sudosnapinstall software name, which is suitable for users who are pursuing version updates. It is recommended to use the system's own package manager for better compatibility and performance.
The Ultimate Guide to High-Performance Gaming on Linux
Aug 03, 2025 am 05:51 AM
ChoosePop!_OS,Ubuntu,NobaraLinux,orArchLinuxforoptimalgamingperformancewithminimaloverhead.2.InstallofficialNVIDIAproprietarydriversforNVIDIAGPUs,ensureup-to-dateMesaandkernelversionsforAMDandIntelGPUs.3.EnabletheperformanceCPUgovernor,usealow-latenc
What are the main pros and cons of Linux vs. Windows?
Aug 03, 2025 am 02:56 AM
Linux is suitable for old hardware, has high security and is customizable, but has weak software compatibility; Windows software is rich and easy to use, but has high resource utilization. 1. In terms of performance, Linux is lightweight and efficient, suitable for old devices; Windows has high hardware requirements. 2. In terms of software, Windows has wider compatibility, especially professional tools and games; Linux needs to use tools to run some software. 3. In terms of security, Linux permission management is stricter and updates are convenient; although Windows is protected, it is still vulnerable to attacks. 4. In terms of difficulty of use, the Linux learning curve is steep; Windows operation is intuitive. Choose according to requirements: choose Linux with performance and security, and choose Windows with compatibility and ease of use.
Understanding RAID Configurations on a Linux Server
Aug 05, 2025 am 11:50 AM
RAIDimprovesstorageperformanceandreliabilityonLinuxserversthroughvariousconfigurations;RAID0offersspeedbutnoredundancy;RAID1providesmirroringforcriticaldatawith50�pacityloss;RAID5supportssingle-drivefailuretoleranceusingparityandrequiresatleastthre
Linux how to enable and disable services at boot
Aug 08, 2025 am 10:23 AM
To manage the startup of Linux services, use the systemctl command. 1. Check the service status: systemctlstatus can check whether the service is running, enabled or disabled. 2. Enable the service startup: sudosystemctlenable, such as sudosystemctlenablenginx. If it is started at the same time, use sudosystemctlenable--nownginx. 3. Disable the service startup: sudosystemctldisable, such as sudosystemctldisablecups. If it is stopped at the same time, use sudosystemctldisabl
Linux how to list all running processes
Aug 08, 2025 am 06:42 AM
Usepsauxforacompletesnapshotofallrunningprocesses,showingdetailedinformationlikeUSER,PID,CPU,andmemoryusage.2.Usetoporhtopforreal-timemonitoringofprocesseswithdynamicupdates,wherehtopoffersamoreintuitiveinterface.3.UsepgreporpidoftoquicklyfindthePIDs
How to clean up your Linux system
Aug 22, 2025 am 07:42 AM
Removeunusedpackagesanddependencieswithsudoaptautoremove,cleanpackagecacheusingsudoaptcleanorautoclean,andremoveoldkernelsviasudoaptautoremove--purge.2.Clearsystemlogswithsudojournalctl--vacuum-time=7d,deletearchivedlogsin/var/log,andempty/tmpand/var
Linux how to view the contents of a file
Aug 19, 2025 pm 06:44 PM
ToviewfilecontentsinLinux,usedifferentcommandsbasedonyourneeds:1.Forsmallfiles,usecattodisplaytheentirecontentatonce,withcat-ntoshowlinenumbers.2.Forlargefiles,uselesstoscrollpagebypageorlinebyline,searchwith/search_term,andquitwithq.3.Usemoreforbasi


