More Exploration

Learning to use basic tools

After installing tools for PAs, it is time to explore GNU/Linux again! Here is a small tutorial for GNU/Linux written by jyy. If you are new to GNU/Linux, read the tutorial carefully, and most important, try every command mentioned in the tutorial. Remember, you can not learn anything by only reading the tutorial. Besides, 鸟哥的Linux私房菜open in new window is a book suitable for freshman in GNU/Linux. Another book recommended by us is Harley Hahn's Guide to Unix and Linuxopen in new window.

RTFM

The most important command in GNU/Linux is man - the on-line manual pager. This is because man can tell you how to use other commands. Here is a small tutorial for man. Remember, learn to use man, learn to use everything. Therefore, if you want to know something about GNU/Linux (such as shell commands, system calls, library functions, device files, configuration files...), RTFMopen in new window.

Why RTFM?

RTFM is the elder of STFW, and was an effective way to solve problems in the days when the Internet wasn't very popular. This is because the manual contains all information about the object being looked up. The answers to everything about the objects can be found in the manual.

You may find it too much of a hassle to go through the manual, so you may try to find a solution by searching a random blog on Baidu. However, you need to be clear about the following.

  • The blog you found may be a reprint of someone else's, and may be full of flaws.
  • The blogger is just sharing his experience, and some of the claims may not be accurate.
  • If you find something relevant, it may not be a comprehensive description.

Most importantly, when you try the above and it doesn't solve the problem you need to make it clear that "I was just trying to take a shortcut, looks like I need to try RTFM".

Write a "Hello World" program under GNU/Linux

Write a "Hello World" program, compile it, then run it under GNU/Linux. If you do not know what to do, refer to the GNU/Linux tutorial above.

Write a Makefile to compile the "Hello World" program

Write a Makefile to compile the "Hello World" program above. If you do not know what to do, refer to the GNU/Linux tutorial above.

Now, stop here. Hereopen in new window is a small tutorial for GDB. GDB is the most common used debugger under GNU/Linux. If you have not used a debugger yet (even in Visual Studio), blame the Fundamentals of Programming course first, then blame yourself, and finally, read the tutorial to learn to use GDB.

Learn to use GDB

Read the GDB tutorial above and use GDB following the tutorial. In PA1, you will be required to implement a simplified version of GDB. If you have not used GDB, you may have no idea to finish PA1.

Hey! Don't be lazy!

We tell you above to write a "Hello World" program, then write a Makefile to compile it And watch the tutorial to learn the basics of GDB!

Installing tmux

tmux is a terminal multiplexer. With it, you can create multiple terminals in a single screen. It is very convenient when you are working with a high resolution monitor. To install tmux, just issue the following command:

apt-get install tmux

Now you can run tmux, but let's do some configuration first. Go back to the home directory:

cd ~

New a file called .tmux.conf:

vim .tmux.conf

Append the following content to the file:

bind-key c new-window -c "#{pane_current_path}"
bind-key % split-window -h -c "#{pane_current_path}"
bind-key '"' split-window -c "#{pane_current_path}"

These three lines of settings make tmux "remember" the current working directory of the current pane while creating new window/pane.

Maximize the terminal windows size, then use tmux to create multiple normal-size terminals within single screen. For example, you may edit different files in different directories simultaneously. You can edit them in different terminals, compile them or execute other commands in another terminal, without opening and closing source files back and forth. You can scroll the content in a tmux terminal up and down. For how to use tmux, please STFW.

STFW again?

Yes.

In addition to consolidating your knowledge in ICS theory classes, PA has an important mission: To train you to be a qualified CSer. In fact, a qualified CSer needs to be able to search for solutions independently. This is one of the basic requirements for programmers in IT companies and research organizations. Your future boss will probably give you a task directly If you ask for help whenever you have a problem, your boss will think that you can't create value.

PA is trying to get you to focus on these basic requirements that are valued by both industry and academia, so that you can develop these skills and mindsets. When you encounter a problem, your first thought is not to find a master to help you solve it, but "Let me try STFW and RTFM, see if I can solve it by myself". So PA is not a step-by-step middle school lab, and don't complain that the handout wasn't clear and caused you to go off on a tangent, we did it on purpose. We'll try to keep the road from getting too curvy, and if you're in the right frame of mind, you're capable of solving these problems on your own. What's important is that you accept the fact that the detours you've taken are indicative of your improvement. The only way to minimize your future mistakes, is if you take the journey seriously now.

The Wisdom of Asking Questions / Don't Ask Questions Like a Retard

Another criterion for a qualified CSer is to know how to ask questions.

As a CSer, I'm sure you've been asked how to fix computers before. For example, if you have a liberal arts partner who QQ's you and says "I'm having trouble with my computer" and asks you to fix it for him Then you have to ask questions to find out what the problem is, and then you ask him to try various options, and then you ask him to give you feedback on what he's tried. If you had 10 of these guys, you'd be sick of it. Now you know what it's like to be a TA.

In fact, if one wants to increase the probability of getting an answer, the questioner should learn how to ask better questions. In other words, the questioner should think seriously on what they asked. "What I can do proactively to make it easier for the other person to help me diagnose the problem". It's true that your liberal arts partner isn't a computer science major, and you can choose to forgive him But you're a CSer, so at least describe the symptoms and what you've tried to do Instead of just throwing in "my program is down" and waiting for someone else to save the day. You'll probably need to ask for help in your future career, such as posting an issue on github or posting on a forum like stackoverflow, or emailing a technical engineer, etc. If you ask a question in a very unprofessional way, it's likely that no one will want to pay attention to your question. Because not only does it make it seem like your random questions aren't that important. And people don't want to spend a lot of time consulting back and forth with you..

A recommended way of asking the question is as follows.

I encountered the error xxx at xxx. This error can be reproduced by the following steps: (describe the specific situation)
1. My system version is xxx, and the relevant tool version is xxx.
2. I did xxx (post a picture if necessary)
3. then xxx (post a picture if necessary)
...
In order to troubleshoot this error, I made the following attempts: (to show that I really hope to solve the problem, really have no choice but to ask the question)
1. I did xxx and got xxx results (post a picture if necessary)
2. I also did xxx, and got xxx results (post a picture if necessary)
...
If finally the problem is not solved, what else do I need to do?

Also be sure to read how to askopen in new window and stop askopen in new window There are a number of examples in there for you to look at.

The following picture shows a scene working with multiple terminals within single screen. Is it COOL?

tmux

Why use tmux?

This is actually an example of "using the right tool for the job".

Computers are built for users, and whenever you have a need, you can think, "Is there a tool that can help me do that? We want each terminal to do different things, to be able to see everything on the screen, and to be able to switch between terminals quickly. In fact, with STFW and RTFM you can learn how to use the right tool. You just have to search for it on a search engine. You can find tmux as a result by searching for "Linux terminal split screen" Then search for "tmux tutorials" to learn the basics of using tmux'. Type man tmuxin the terminal to check any questions abouttmux`.

Of course, learning doesn't come at no cost. A former student suggested a way to split the screen at no cost. Open four terminals, and drag them to the four corners of the screen, Since Alt+Tab shortcut does not allow you to select a window easily(because all four windows look the same), he switch between them by clicking with the mouse. Then he described installing and learning tmux as a redundant.

The whole point of tmux is to save the user the cost of doing this. If you're not willing to pay any learning costs, you won't be able to enjoy the tool.

Things behind scrolling

You should have used scroll bars in GUI. You may take this for granted. So you may consider the original un-scrollable terminal (the one you use when you just log in) the hell. But think of these: why the original terminal can not be scrolled? How does tmux make the terminals scrollable? And last, do you know how to implement a scroll bar?

GUI is not something mysterious. Remember, behind every elements in GUI, there is a story about it. Learn the story, and you will learn a lot. You may say "I just use GUI, and it is unnecessary to learn the story." Yes, you are right. The appearance of GUI is to hide the story for users. But almost everyone uses GUI in the world, and that is why you can not tell the difference between you and them.

Why GNU/Linux and How to

Why use Linux?

Let's start with two examples.

How to compare if two files are identical? This example looks very simple and can be realized under Linux using the diff command. If the files are large, it is useful to use md5sum to calculate and compare their MD5. For a Linux user, it takes about 3 seconds to type these commands. But on Windows, this is not so easy to do. Maybe you downloaded an MD5 calculator, but how many mouse clicks do you need to do the comparison? Maybe you're thinking it won't save you much time. The truth is, however, that's how your development efficiency decreases.

How to List All Included Header Files in a C Project? This example is slightly more complicated than the one just described, but you can hardly do it efficiently on Windows. In Linux, we can do this with a single line of command:

find . -name "*.[ch]" | xargs grep "#include" | sort | uniq

By looking at man, you should have no trouble understanding how the above command accomplishes the desired function. This example is another example of the Unix philosophy.

  • Each tool does one thing, but does it well.
  • Tools are easy to use by using text-based inputs and outputs.
  • Solve complex problems by combining tools.

The last point of the Unix philosophy best describes the difference between Linux and Windows: Programability. If you compare tools to functions in code, combining tools is a form of programming. But Windows tools are almost impossible to combine, because Windows for the average user needs to emphasize ease of use.

So, the reason you should use Linux is very simple. As a coder. Windows has always been an obstacle to your ability to think, act, and be productive.

How to use Linux in an effective way?

  1. Uninstall Windows, free your mind, get rid of the obstacles of Windows. Instead of defaulting to "No way, that's the way it has to be," You should try "See if you can get this right".
    • Linux also has the corresponding common software, such as Chrome, WPS, Chinese input method, mplayer...
    • You can live without Windows.
    • If you can't, you can install a Windows VM as a backup.
  2. Familiarize yourself with some common command-line tools and force yourself to use them in your daily operations.
    • Document management - cd, pwd, mkdir, rmdir, ls, cp, rm, mv, tar
    • Document search - cat, more, less, head, tail, file, find
    • Input/Output Control - Redirection, Piping, tee, xargs
    • text processing - vim, grep, awk, sed, sort, wc, uniq, cut, tr
    • regular expression
    • System monitoring - jobs, ps, top, kill, free, dmesg, lsof
    • The above tools cover the vast majority of a programmer's needs
    • You can start by trying simple ones, and memorize them if you use them more, or if you can't remember them.man
  3. RTFM + STFW
  4. perseverance.
  • Mindset, believing that there's always the right tool to help me do better.
  • Actions, willingness to take the time to find it, learn it, use it.

The Missing Semester of Your CS Education

The Missing Semester of Your CS Educationopen in new window is a series of tutorials on Linux tools recommended by jyy.

This tutorial is available in Chinese, check it out.

Overcoming Fear, Gaining Initial Confidence

The fact is, learning to use Linux is a low-cost, high-success exercise. If you are willing to STFW and RTFM, you can solve most problems. In contrast, the problems you will encounter later (in subsequent PAs/in subsequent courses/at work) will be more difficult. So, by solving these small, simple problems independently, you will start to build up your initial confidence in your ability to solve more difficult problems.