How To Copy Command Output To Linux Clipboard Directly Last Updated : 04 Dec, 2022 Comments Improve Suggest changes Like Article Like Report To copy commands outputs directly to Linux Clipboard we will be using a Program called xclip. xclip is a program that allows us to clip-> copy/crop ->cut and external reference or a block to a specific area. xclip reads text from standard inputs or files and make it available to other application for passing an X section. It reads from all files specified, or from standard input if no files are specified. xclip has many parameters like -copyfile, -cutfile, -pastefile, etc that are used to redirect the outputs of input or command or files to the specified location or area. 1. How to Use xclip for clipboard copy and paste:In the first step we need to install this program in Linux to do so we will use the following command:$ sudo apt install xclip After installing this program we are all set to use it to copy text or files to the clipboard directly. usage: Open nano editor or some other editor of your choice type in some text and save it.$ nano testfile Now with the cat command, we can see the content of the file as follows.$ cat testfile Use the xclip command to copy the file text to the clipboard as follows:$ cat testfile | xclip By using a pipe we can copy the content of the file to the clipboard. Now to see test whether it is copied or not simply paste the clipboard on the terminal. This is one way of doing this, there are many other programs and utilities which allow you to copy files/ outputs to a clipboard. 2. How to copy sort command output into the clipboard without using the Mouse in Linux:To copy sort command output we are going to use the xclip parameter called -selection clipboard we are specifying the output to be copied into the clipboard so that we can paste it anywhere.$ command | xclip -selection clipboardReplace the command with the sort command like this:$ sort -n -k 3. -k 2 test.txt | xclip -selection clipboard Now you can paste it with the keyboard shortcut SHIFT+ CTRL+V. for the terminal and simple CTRL+V to paste it in the GUI applications like a text editor. 3. How to paste the output to GUI applications?we can follow the above approach simply as you can see in the above output that we have pasted the clipboard into our text editor without using a mouse, so this step is similar to the above one just use the command like the following:- $ cat test | xclip -selection clipboardWith this being done you can go to any of your GUI applications and paste the output of the command cat test. 4. Using xclip in shell scripts:Using xclip in a shell script is something that you might think is difficult but it's not all you need to do is just write the command within the bash script. we can take an example by using the following command :$ echo "hello your script is running" xclip --selection clipboardThe above command will simply copy the string that is in quotes to your clipboard so let's try to write it in a script.First, create a file with extension .sh like bash.sh.Then write the above command with a line addition that will specify the bash script. #!/bin/bash echo "hello your script is running" xclip --selection clipboardNow we are good to go just run this script in your terminal and the string will be copied to your clipboard. to run the bash file you need to modify the permissions first and follow up these commands.$ chmod +x bash.sh $ bash bash.sh Conclusion:Now if you want to know more about this command you can always go to its MAN page with the command $ man xclipit's going to show you all the details about all the options available for you to perform with xclip command. Comment More infoAdvertise with us Next Article Company Preparation L lucifer2411 Follow Improve Article Tags : Technical Scripter Linux-Unix Technical Scripter 2022 Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like