Successfully reported this slideshow.
Your SlideShare is downloading. ×

Learn Linux in a Month of Lunches: learn Linux while you eat

Ad

Using specialized command
line programs for specific
tasks: top, xkill,
killall, wget, and grep
From Learn Linux in a Mont...

Ad

Five useful command line programs
This presentation is about learning to use five specialized
command line programs for ve...

Ad

top
We’ve all had issues with our computers slowing down for some
reason. Most operating systems have a task manager that ...

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Check these out next

1 of 24 Ad
1 of 24 Ad

Learn Linux in a Month of Lunches: learn Linux while you eat

Download to read offline

Learn Linux in a Month of Lunches shows you how to install and use Linux for all the things you do with your OS - all in easy-to-follow lessons designed to take an hour or less. Learn while you eat!

Save 42% off Learn Linux in a Month of Lunches with code ssllinux at:
https://www.manning.com/books/learn-linux-in-a-month-of-lunches

New from manning.com

Learn Linux in a Month of Lunches shows you how to install and use Linux for all the things you do with your OS - all in easy-to-follow lessons designed to take an hour or less. Learn while you eat!

Save 42% off Learn Linux in a Month of Lunches with code ssllinux at:
https://www.manning.com/books/learn-linux-in-a-month-of-lunches

New from manning.com

Advertisement
Advertisement

More Related Content

More from Manning Publications (20)

Advertisement

Learn Linux in a Month of Lunches: learn Linux while you eat

  1. 1. Using specialized command line programs for specific tasks: top, xkill, killall, wget, and grep From Learn Linux in a Month of Lunches by Steven Ovadia. Save 42% with code ssllinux at manning.com
  2. 2. Five useful command line programs This presentation is about learning to use five specialized command line programs for very specific tasks: top, which tracks system usage; xkill and killall, which shut down programs and processes; wget, which downloads files; and grep, which searches files. These five apps get used a lot, and once you master them, you’ll wonder how you ever did without them!
  3. 3. top We’ve all had issues with our computers slowing down for some reason. Most operating systems have a task manager that lets you see which programs and processes are running, and how much CPU and memory they are using. We can use the task manager to discern the nature of the problem. Ubuntu’s task manager is called System Monitor – see the next slide to find out what it looks like.
  4. 4. top Ubuntu System Monitor
  5. 5. top The top command does the same thing as System Monitor. So why use it? Because it’s fast. It lets you end and kill processes just like the System Monitor, but it demands far less of the system. This can be relevant if your computer is totally choking on a process and adding the System Monitor to the mix would just make things worse. top has the same effect and uses fewer resources.
  6. 6. top The top command: notice that you can see how system resources are being used.
  7. 7. top Even though it looks like the system monitor, it doesn’t work quite the same. To sort by CPU or memory usage you have to type P or M, respectively, instead of by clicking the column. Now, what about killing the process or program that’s holding up your computer? To do that, you’re going to look at the PID for the offending process. It’ll have very high %CPU or %MEM usage—probably the most on your computer. In this case, it’s Firefox.
  8. 8. top To kill our process we need to type in the PID of whatever we want to shut down.
  9. 9. top Then you’ll type in the PID of whatever you want to shut down. In the previous slide, it’s PID 4020, which is assigned to Firefox. Type in 4020 and click Enter. You’ll be asked if you want to send the signal. It will look something like this: Send pid 4020 signal [15/sigterm] Press Enter. Whatever was assigned to that PID (in slide 8, it’s Firefox) will close.
  10. 10. top When you’re done with top, type q to close it. Make sure it’s lowercase. top is useful for seeing what’s going on with your system without slowing anything down. The ability to kill programs and processes is especially convenient. Let’s explore some other ways to kill processes and programs from the command line.
  11. 11. xkill top is useful when you’re not sure what’s slowing down your computer. But often you know right away when a program is hung up. You can still use top to get the PID and kill it, but it’s a multi-step process. For times when I know what I want to shut down, I use the xkill command.
  12. 12. xkill xkill is brilliant. You type it into the terminal and your cursor turns from an arrow into an X.
  13. 13. xkill Once it’s an X, click on any program and it will close. This is very useful for unresponsive programs that won’t close by normal means. Rather than going into the terminal to launch xkill, you can also use Alt-F2, which is a shortcut for entering a command into the terminal, without launching the terminal first – as shown below.
  14. 14. xkill Try it Now: xkill 1. Launch Firefox. 2. Press Alt-F2 to launch the terminal box. 3. Enter xkill into the box. You’ll notice your cursor is now an X. 4. Click Firefox to force it closed. Using xkill is faster than going into your System Monitor, and also quicker than using top.
  15. 15. killall Sometimes you know which program or process is slowing down your computer, but you can’t see it. In these cases, I know what the problem is but xkill won’t work, because there’s nothing to click. The issue is the program is running in the background. We can use killall to help, a command-line utility that lets you shut down a program by name.
  16. 16. killall Have you ever closed Firefox and gotten a message saying that it’s already running (and not responding) when next you try to open it? We could open top and use the PID to shut it down, or just cut to the chase by going into the terminal and typing: killall firefox This command will shut down all instances of Firefox.
  17. 17. killall What’s nice about killall is that if multiple processes with the same name are running, let’s say multiple instances of the Chrome browser, it will shut down all of them. Something to keep in mind is that when you kill programs with killall and xkill, you’re not properly shutting down the programs. When you shut down a program with killall or xkill, you run the risk of losing data and will often reopen the program to find an error message.
  18. 18. wget To have uncooperative programs to kill with xkill and killall we need to download some from somewhere. wget is a command-line application that downloads files from the internet. The files could be HTML pages, sound files, or PDFs. You point the command to the file or site, and wget handles the rest. Without opening a web browser!
  19. 19. wget You might be wondering why you wouldn’t want to just use the browser. Well, you don’t have to leave the browser open when you download big files, which keeps your computer running faster. You also don’t have to worry about the download getting corrupted, which sometimes happens when you download very large files via the browser, which isn’t designed for that kind of downloading.
  20. 20. wget wget is also much faster than the browser download. It is mostly useful for downloading larger files, as smaller files download quickly enough via the browser. If I wanted to download a file from example.com to my documents folder, the syntax would look like this: 1. cd Documents 2. wget http://www.example.com/sample.iso
  21. 21. grep After downloading all those big files with wget and reading error messages from programs you ended using xkill and killall, you might be in need of a command to search through text files. If so, grep does just that! It’s kind of like Ctrl-F on steroids. grep is a specific, powerful tool that can be very useful for pulling text out of logs and files.
  22. 22. grep When you’re looking through things like error logs, grep can take you to the text that you’re looking for in a flash. Let’s say you’re computer is crashing and you want to find out why. You can search the system log for the word fail. That search will look like this: grep fail /var/log/syslog The first part, grep fail is your search term. The second part, /var/log/syslog is the file you’re searching.
  23. 23. grep It’s a really great command when you’re hunting for specific bits of text. grep can also be used to search through text files in an entire directory. To do that, you would have a search like this: grep -r searchterm. The -r makes the search recursive, looking through subdirectories.
  24. 24. See what else you can do with Linux! Save 42% off Learn Linux in a Month of Lunches with code ssllinux at manning.com. Also see:

×