BASH shell commands pipes (commands for Linux)
Video Title: BASH shell commands pipes (commands for Linux)
Hello and welcome to Linux leech in today’s tutorial I’m going to show you how to use pipes so let’s get started okay the first step I’m going to take so open on our terminal and I’m going to show you what a pipe is so a pipe is this vertical line character here and
What it allows you to do is to take the output of one command and use that as input for another so as a quick example if I had say let’s call it command 1 so that’s my first command what I would then do is put in the space and then the
Pipe character and then command – so what’s actually going to happen here is whatever commands one would output to the screen is now going to be fed into command 2 as input so the best way to show you that is to go ahead and do some
Examples so I’m just going to CD over to my desktop and into this rubber directory here and I’m just going to run LS so that we can see the directories that are within that java directory and what I’m now going to do is I’m going to
List these in order of the newest so to do that I can just type in LS dash L so we can get a long listing and T so that we can list them in order of the newest directory or the directory that has had the newest change so now if I hit enter
You can see that they’ve been listed in order of the newest but let’s just say I had 30 or 40 directories here and I only wanted to see the top 10 what I could do is if I just clear the screen I could use the same command so LS space – LT
And then I could use the pipe character and a command that we know of that lists the top 10 lines within any kind of document is head so if I pipe the output that we had before in two heads it’s going to give me a
Leaving first 10 lines so if I hit enter now you can see that it’s a lot shorter and we actually have nine directory listings because this line here counts as one of the 10 that we’re going to list so if I actually wanted to list 10
I could either leave out the – L so I could type in LS – T and then pipe that into head and as you can see we’ve got an extra directory at the end and if you count all of these there are 10 there or I could modify the head command and I
Could use the – n parameter so I could type in LS – LT to get a long listing and in order of the newest fast and then pipe that into head and use the – n option and I’d type 11 so that we’re going to include this line here as well
As 10 directories so if I enter now you can see that we have now got 10 directories listed in order of the newest verse so newest directory second newest directory and so on and so forth so that’s quite useful if you only want to see the top half of any kind of
Information that you would list and there’s another really useful thing to do with pipes and that is if I just clear the screen if we use a command like history you can see that there’s a lot of listings there and if I scroll up we’re not actually getting the full
Picture of what’s going on so what we could do is we could type in the history command and we could pipe that into a command that we’ve used before which is less and if we hit enter now you can see that we’re actually able to view all of
The information that would have been displayed by history but in a much easier to read kind of fashion so whenever you get come on so they’re going to give you a lot of output sometimes it is a good idea to actually just pipe that commands output into less it just makes things easier
For you to read basically so I’m just going to type Q to quit out of less let’s move on to something else so I’m just going to clear the screen again and what I’m going to do now is I’m going to use the find command and
I’m going to tell it that we’re looking in the current directory so I’m going to use a single dot and then what we’re looking for so – type and we’re going to use an F so we’re looking for files and we want to print those to the screen so
– print and let’s hit enter to see what that gives us so as you can see we’ve got this long listing of all of the files within the java directory and it’s sub directories now let’s just say that we wanted to know how many files were there we could actually count each
Individual line because each of these lines is equivalent to one file so we could do that manually which could take forever depending on how many listings there were or we could actually just pipe this command that we used so this finds command we could pipe it into
Something that will allow us to count the lines that are being output so if we just use the pipe command we can use the WC come on forward cap but with the dash L option for lines so now if I hit enter you can see that we’ve got 188 files so
As you can see we’ve actually combined two separate commands to give us an output that is something that we were looking for now with pipes you’re not just limited to two commands you can actually pipe multiple commands together so if I use the same command again so we’re going to
Use this listing again but this time we’re going to pipe that into the head command and we’re then going to pipe that in the WC command with the – L option so what’s actually going to happen is we’re going to print this long listing it’s going to go into the head command which
Will give us an output of the first 10 and WC is going to count the number of lines so we should be left with a number which is 10 so if we hit enter now there we go we’ve been left with the number 10 so as
You can see here we have actually used three commands so I’ve used the find command here and then we’ve piped that output into head and then pipe heads are put into WC so you can basically pipe as many commands together as you want to get the desired output that you’re
Looking for now when you’re using pipes you can also use redirection so if we just run the same command again but this time we want to redirect our output into a file we can just use our redirect symbol here and then let’s type in the name of the file so let’s use desktop
Just a the forward slash layer so my desktop and then forward slash let’s call it test dot txt and hit enter and as you can see that file has been created on our desktop and if we just open it it’s got the number 10 in it
Which is what our output was here so there you go that’s how to use pipes and in my opinion pipes are probably the most useful and most powerful tool that you have when it comes down to I re direction and as you can see you can just pipe pretty much any commands
Together to achieve your desired output so that’s brought us to the end of that tutorial I hope you found it useful and if you did please don’t forget to subscribe you can also follow Linux leech on facebook.com forward slash Linux leap and on twitter at linux leech and thanks again for watching goodbye
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Can you share the link of the lesson where the concept of backslash is explained which prompts to enter data the the > prompt
i want you to know what my sisters mouth feels like on your snake head. may i plz bring her over later, larry?
y u not on LBRY
Thank you so much for this
Very smooth videos and I love your clear speech!
Nice tutorial! An alternative (since there is a plethora of ways to do the same thing in the terminal) to 3:40 would be:
$ ls -lt | tail -n +2 | head
This preserves the long listing and gets rid of the 'total 52' line.
Very helpful and easy to parse for a beginner. Thanks a lot!
Thanks bro
So how do you read file on the screen using pipes?
I find your videos very helpful! You can explain everything so clearly. Thank you for that.
I learn along with your videos and everything has been all right up till now.
Where's my mistake? 🙂
find . -type f -print | head | wc -l > -/Desktop/pipes.txt
bash: /Desktop/pipes.txt: No such file or directory
damnn, i was really shocked when suddenly as computer name Tarek appeared. Guess there are also other Tarek's out there that are using the bash XD
This was amazingly useful thanks so much 🙂
I don't see how, single dot(.) its current directory, the same as dot forward slash(./). . == ./
Most probably what happened with you its you typed /, witch is root dir.
"find ./ -type f -print" is what worked for me on my Mint 14.1 mate 64bit.
when I used just "find . -type f -print" I got something different. Your show is great.