From windows to * nix (2) daily operations

Source: Internet
Author: User

In windows, we have the following procedure: log on to the system, browse the file system, find the program execution, find the document, and open it. Then exit the system.

 

Login

In * nix, there are two login Methods: one is to log on directly on the local terminal, and the other is to remotely access through ssh or telnet. Either way, after you enter your username, password, and successfully log on, a prompt appears in front of you. Generally, it is a $ symbol or #. You can customize the prompt as follows:

$ <Br/> oyd @ localhost ~ $ <Br/> localhost oyd # 

 

This is what the shellof * nixshows you. shellis equivalent to windows's external shell program mongoer.exe. On * nix, you type a command at the end of the prompt to deal with shell. In windows, you use the mouse and keyboard to interact with windows shell programs through the GUI.

 

* There are many shell types in nix, such as csh, ksh, and bash. The most popular one is bash. I believe that bash is used by all users without any quirks. Shell selection can be specified when users are added, or you can enter commands to switch. Enter the following command to check whether your shell is bash.

Localhost oyd # echo $ SHELL <br/>/bin/bash <br/> localhost oyd # 

If other shells are displayed, You can manually enter the bash command to switch over.

$ Echo $ SHELL <br/>/bin/tcsh <br/> $ bash <br/> bash: not found <br/> $ 

However, the above prompt bash: not found indicates a failure. If it succeeds, it should be a new prompt directly for you. The cause of this failure is that bash is not installed in the system, this also illustrates the role of bash from one side. If the shell you are working on is not bash, it is probably not installed in your system.

 

If it is not bash, there is nothing. The basic operations of various shells are similar. bash just makes you more comfortable.

 

Browse

First, let's take a look at how to browse your file system. You can use the following commands:

Pwd to see where you are now

Ls to list files in the current directory

Cd to a directory, cd .. to the parent directory cd ~ Go to the user's home directory

Df: List partitions of the current File System

Example:

Oyd @ localhost ~ $ Cd/<br/> oyd @ localhost/$ ls <br/> bin boot dev etc home lib lost + found mnt opt proc root sbin sys tmp usr var <br/> oyd @ localhost/$ cd ~ <Br/> oyd @ localhost ~ $ Pwd <br/>/home/oyd <br/> oyd @ localhost ~ $ Df <br/> Filesystem 1K-blocks Used Available Use % Mounted on <br/>/dev/sda3 7692908 2412544 4889584 34%/<br/> udev 10240 160 10080 2%/dev <br />/dev/sda1 38856 11552 25298 32%/boot <br/> oyd @ localhost ~ $ 

 

For the first time, you may think that this method is far less convenient than windows. However, if you use the shell tab to automatically complete, you will find the advantage.

For example, I am writing a blog, and suddenly I think D:/CODE/sgfc-1.16 to see below, so in windows, I need to first click Start menu, then click my computer, when there are too many programs running, wait for a while (do not think your computer is fast, it will become me after a long time), and then double-click the D disk, there are a lot of files, it took a lot of time to find CODE, and then double-click in, find the sgfc-1.16 took a lot of time, and then double-click in.

So under * nix, assuming I'm Going To/home/oyd/CODE/sgfc-1.16, then I just need to type cd ~ /C <tab>/sg <tab> <enter> (<tab> indicates the tabulation key and <enter> indicates the enter key). This process is fast.

 

Windows browsing is especially suitable for unfamiliar things, such as browsing others' systems. * Nix's browsing method is suitable for familiar things, such as the directory structure on your computer.

 

View/execute

Unlike windows documentation, * nix operations are still program-centered. That is to say, you must first know the program that can open this document before you can open this document.

You may think that * nix is quite backward, but at least you know what you are doing, right?

In windows, the ghost knows which Trojan is in the background when you double-click a txt file. Furthermore, document-centric operations are not a feasible concept at all. For example, after a file has evolved to a database, I have never seen anyone who double-click a data link or perform any operations.

 

* A basic belief in Nix makes it easier for you to process documents than in windows. * Nix believes that everything is text.

For example, if you want to view account information in Windows, you need a dedicated tool. However, in * nix, it is only a text file (/etc/passwd ), you can view it in any way you are used to (such as CAT ).

 

That is to say, in windows, double-click what you see, and in * nix, cat is what you see. For example, view the CPU information:

Ouyangde @ localhost ~ $ CAT/proc/cpuinfo <br/> processor: 0 <br/> vendor_id: genuineintel <br/> CPU family: 6 <br/> model: 14 <br/> model name: genuine Intel (r) CPU t2400 @ 1.83 GHz <br/> stepping: 8 <br/> CPU MHz: 0.000 <br/> cache size: 2048 kb <br/> fdiv_bug: No <br/> hlt_bug: No <br/> f00f_bug: No <br/> coma_bug: No <br/> FPU: yes <br/> fpu_exception: Yes <br/> cpuid level: 10 <br/> WP: Yes <br/> flags: fpu vme de Pse tsc msr pae mce cx8 APIC Sep mtrr pge mca cmov clflush dts acpi mmx fxsr SSE sse2 ss nx constant_tsc up arch_perfmon pebs BTS limit PNI pdcm <br/> bogomips: 134637.15 <br/> clflush size: 64 <br/> power management: <br/> ouyangde @ localhost ~ $ 

 

Cat command to view the entire file

More and less view the entire file in one screen at a time

Head: view the first n rows of the file

Tail: view the end n rows of the file

You can ignore more or less, but remember head and tail. They are very useful. For programmers, the daily operations under * nix are also like programming.

Tail also has a very common usage: tail-F, which is very useful for monitoring log files. If you use ultraedit in Windows to view log files, you will switch between them, come back and check if the log is changed. Although it is troublesome, it is much better than using notepad. Or there are dedicated tools to view logs. These dedicated tools provide a listview control to list logs in one row (I did similar tools when I was a child ).

However, tail-F is as simple as it does not exist, but once you use it, you will not seek for anything else.

 

There are also non-text files. For such files, there is a command file to find out what type it is:

$ File main. c <br/> main. c: ascii c program text <br/> $ file main. o <br/> main. o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped <br/> $ file 1.JPG< br/> 1.JPG: JPEG image data, JFIF standard 1.01 <br/> $ file vim-7.2-3-src.tar.bz2 <br/> vim-7.2-3-src.tar.bz2: bzip2 compressed data, block size = 900 k <br/> $ 

 

 

* Nix commands, except for the built-in shell, are all * nix executable files, which are placed in different directories. There is a PATH environment variable that tells shell which directory to find them.

Ouyangde @ localhost ~ $ Echo $ PATH <br/>/usr/local/bin:/usr/bin:/opt/bin:/usr/i486-pc-linux-gnu/gcc-bin/4.1.2: /usr/i686-pc-linux-gnu/gcc-bin/4.1.2 <br/> ouyangde @ localhost ~ $

Generally, the PATH in the default setting does not contain the current directory. The current directory is represented by a dot (.). Therefore, when you run the program in the current directory, Add./In front ./. For example,./configure, which indicates that the configure program under the current directory is executed.

To execute a program, you must have the execution permission of the program file. Executable files are not necessarily binary files or scripts. Use ls-l to View File permissions.

$ Ls-l configure ttt <br/>-rwxr-xr-x 1 oyd 152953 Dec 18 configure <br/>-rwxr-xr-x 1 oyd 8349 Dec 18 18:32 ttt

X in-rwxr-xr-x above indicates executable. Therefore, both files are executable files.

$ File configure ttt <br/> configure: Bourne shell script text executable <br/> ttt: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV ), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped

However, configure is a text script that can be executed by shell, and ttt is a 32-bit executable program under * nix. As you can see, it is still dynamically linked.

 

If you confirm that a file is executable, such as ttt, You can execute it in the following ways:

$ Pwd <br/>/home/oyd <br/> $ ls-l auto/ttt <br/>-rwxr-xr-x 1 ouyangde 8349 Dec 18 auto/ ttt <br/> $ auto/ttt <br/> Hello, world! <Br/> $/home/oyd/auto/ttt <br/> Hello, world! <Br/> $ cd auto <br/> $./ttt <br/> $ Hello, world! <Br/> $

 

* Nix programs have some common conventions on command line parameters. They have two styles: Long Options and short options. In general,-h or -- help can be used to view brief help on the usage of this program.

If the input is incorrect, Ctrl + C can interrupt the input of the current row, and shell will output a new prompt

 

To exit * nix, run the exit command.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.