Special topics: Windows to Linux tour: Part 1. Quick Start of Console

Source: Internet
Author: User
Linux console Quick Guide

Level: elementary

Chris Walden (cmwalden-at-us.ibm.com)
E-commerce architect, IBM Developer Relations
January 2004

IBM e-commerce architect Chris Walden willDeveloperworksThe nine articles published in this article will guide you how to use your Windows Operating Skills in Linux. This section describes various shell and some basic Linux commands.

All management tasks in Linux can be completed in the console. In many cases, using the console is faster than using graphical programs, and additional functions may be implemented. In addition, all console tasks can be written to scripts for automatic execution. To truly control your Linux environment, you will want to know how to work on the console. If you have used DOS/Windows, this article will guide you to start using the Linux console.

Go to the console
If your system directs you to the text mode (the server is usually configured to reduce service overhead), you have logged on to the console as text. In a typical Linux system, you can switch to another console by pressing Ctrl + Alt + (F1-F6. Each console is a completely independent session in the system, which can be used by different users at the same time.

This multi-console feature is different from multiple desktops in Windows. In Linux, each console can be controlled by different users. For example, you may useRootLog on to the console 2JoeuserIdentity to log on. The two consoles run different programs in their respective user spaces. Similarly, different users can remotely log on to the same Windows system. In this regard, Linux is more like a host than a simple server or workstation.

If you are in graphic mode, you can openTerminal)To enter the console window. Usually there are terminal buttons on the task bar on the desktop. You can also open the terminal from the context menu (right-click on the desktop.

Command
There are many commands available in the console. Some of them are actually used only when writing scripts. Here are some of the most likely commands you can use. Do not forget that all commands and options are case sensitive.-RAnd-RDifferent operations are performed. Almost all Console Commands are in lowercase.

CD
Use what we are familiarcdCommand to switch between directories. Note that a forward slash (/) is used in Linux, rather than a backslash (/) that you are familiar (/). The backslash is also used, but it is only used to indicate that the command needs to continue with the line feed, which can improve the readability of long commands.

Ls
lsCommand is used to list all files in a directory. You can use many different switches to change the list representation:

List objects

ls -l List objects in long format, including file size, date and time, and attributes
ls -t Sort files by Time
ls -S Sort files in large or small order
ls -r It is used in combination with a sort switch and arranged in reverse order.ls -tDisplay the latest file on the top of the list.ls -tDisplay the latest file at the bottom.
ls -h Easy-to-Read format. Use K, M, G, and so on to identify the file size, rather than in bytes.
ls -a Display All files in the directory, including hidden files

CP
UsecpCommand to copy files. This command corresponds tocopyThe command is basically the same. The basic switch is as follows:

Copy a file

cp -R Recursively copy an object. It is used when the entire directory needs to be copied.
cp -f Force copy and overwrite existing files without asking users
cp -l Link the file instead of copying it. See the following description.

Use the Copy command to create a link
UsecpCommand to create a hard link to a file or the entire file structure. Use-lSwitch to indicate that the operation is link replication. All directories are still created as directories, but all files are set as hard links.

cp -lR /data/accounting/payroll /data/management/hr

The above command will copy the entire directory structure and its files from/data/accounting/payroll to/data/management/HR/payroll. All files in the directory structure will be set as hard links. In this way, a file can have different views in the same file system. This is also a useful security technology that enables different access permissions to the same file under different directories.

MV
UsemvCommand to move and rename files. This command basically works withmoveThe command is the same, but it can move the entire directory structure and all files.

Cat
UsecatCommand to view the file content. It is equivalenttypeCommand. It will dump the file content to another file, screen, or other commands.catIs the abbreviation of concatenate. You can also combine a series of files into a large file.

More
Use commandsmoreYou can view files by page. It basically worksmoreThe command is the same.

Less
lessCommand is also used to view files, but it supports Scrolling up and down and text search in the document.

VI
Some may sayviIndicates "always Ally impossible ". It is a historical text editor in Unix.viNot really intuitive, but now almost all Unix-like environments havevi. There is a built-in tutorial for the version installed in Linux. Once you are familiarviYou only need to press the key several times to complete the incredible task. To be honest, no editor can replace vi to edit passwords and configuration files.

Man
UsemanCommand to view the command documentation. Man isManual. Almost every command has corresponding documents. In-depth understandingman, Enter the following command:

man man

Info
infoCommands andmanThe command is similar, but it provides hyperlink text to more easily browse documents.

Which shell?
One of the most important differences between DOS/Windows and Linux is that Linux shell is a layer separated from the operating system. Different shell environments affect your ability to have different functions, such as editable command line and historical Command Re-query. Shell also determines the syntax of the function in the script. In DOS/Windows, there is only one case for writing a script program, that is, the use of inefficient. BAT files. It can indeed complete many functions, but in addition to the basic tasks, complex tasks require strong creativity of the script writers. In Linux, scripts can have loops. Not only can basic conditional statements be executed, but many functions are available in programming languages. If you are good at writing. BAT files, shell scripts will make you more talented.

The default shell is a parameter of each user account. The Typical default shell in Linux is/bin/bash, but other shells can also be used. For each shellmanThe documentation is actually very good and provides detailed descriptions of various shells and their usage. Reading the following explanation is not enough. You should select one from the shell listed below to view its man document.

Bash
Bash shell is a free version of Bourne shell. It is the earliest Unix shell, including many additional features. Bash has an editable command line that allows you to check History commands. You can add the tab key to avoid entering long file names.

CSH
C shell uses the "Class C" syntax and draws on many features of the Bourne shell, but the internal shell command set is different.

Ksh
The syntax of the Korn shell is the same as that of the Bourne shell, and it is easy to use. Many installation scripts are usedksh, Even if you do not use it as your main shell, you should install it in the system.

Tcsh
TC shell is an enhanced version of C shell, which is fully compatible with C shell.

Zsh
Z shell is an enhanced version of Korn shell and has many features of bash shell.

Shell rules
You only need to execute the corresponding commands on the console to switch the shell at any time. You only need to place a ticket number (#!) on the top of the file (#!) Point to the required shell, and the script can specify the shell to be run. When a script runs, it runs in the correct shell environment regardless of the shell environment. In the following example, this line of code indicates that the script must be run in C shell:

#!/bin/csh

Give me a link to make it safer!
One of the most important features of a Linux file system is its file link. The link is a reference to the file, so that you can see the file in the file system. However, in Linux, links can be treated as original files. Links can be executed, edited, and accessed like normal files. For other applications in the system, the link is the original file corresponding to it. When you edit a file through a link, you actually edit the original file. The link is not a copy. There are two types of links: hard link and symbolic link.

Hard LinkOnly files in the same file system can be referenced. It references the physical indexes of files in the file system (also knownInode). When you move or delete the original file, the hard link will not be broken because it references the physical data of the file rather than the position of the file in the file structure. A hard-linked file does not require the user to have the permission to access the original file or display the location of the original file. This helps the file security. If the deleted file has a hard link, the file will still be retained until all references to it are deleted.

Symbolic LinkIs a pointer pointing to the position of the file in the file system. Symbolic Links can point to files in a remote file system across file systems. The symbolic link only specifies the location of the original file. You must have access to the location of the original file to use the link. If the original file is deleted, all symbolic links pointing to it will be damaged. They point to a location that does not exist in the file system.

You can use commands to connect the two types of links.ln .lnHard links are created by default. Use-sYou can create a symbolic link.

# Create a hard link from MyFile in the current
# directory to /YourDir/MyFile
ln MyFile /YourDir

# Create a symbolic (soft) link from MyFile in
# the current directory to /YourDir/YourFile
ln -s MyFile /YourDir/Yourfile

In the preceding example, myfile,/yourdir/myfile, And/yourdir/Yourfile are regarded as the same file.

Go out of your shell
For Linux management, you must learn how to work in the Console environment. Although some tools can prevent you from using the console, you are subject to many restrictions on those tools. It's easy to log on to the console.manAndinfoCommand to access the command documentation is also very convenient.

References

  • Read Other sections of the windows to Linux journey series (Developerworks, January 1, November 2003 ).

  • Follow the Tutorial "vi Entry-clever form method "(Developerworks) To start using the vi editor.
  • "Basic tasks for new Linux developers "(DeveloperworksJuly 2001) I introduced how to work in Linux in a simple way, including opening a shell window, adding users and groups, and attaching and dismounting CD-ROM.
  • "Linux user Technical FAQ "(DeveloperworksJuly 2001) can also help you smoothly transition from Windows to Linux.
  • "How good are Linux clients ?" This article describes the author's experience in switching from Windows to Linux. There is also an article "concise Linux vocabulary for Windows users" which is also a useful reference.
  • You can find many Online help pages on the GNU Manuals Online page.
  • From DOS/Windows to Linux HOWTO provides quick start information for those with DOS or Windows backgrounds.
  • AllCommands.com is a distinctive site that helps you reference and cross-reference commands from various operating systems.
  • The "LPI certification 101 exam prep, Part 1: Linux fundamentals" tutorial introduces bash, standard Linux commands, and so on.
  • Through the "Bash instance" series of articles, you can learn more about shell scripts (Developerworks).
  • Although written for AIX users, the System User's Guide: Operating System and Devices-Shells references and books, many contents including AIX Commands Reference-man Command are also applicable to Linux.
  • To start using IBM software on Linux, speeding up your Linux application development will provide you with the best reference materials. You can find installation tips and references for various applications such as DB2, Lotus Domino, WebSphere Application Server, and WebSphere Studio. You can also log on to get the free Linux software evaluation kit, which contains trial software and training materials.
  • PassDeveloperworksFrom here, I will continue to learn the basic concepts of Linux.
  • InDeveloperworksYou can find more references for Linux developers in the Linux area.

About the author
Chris Walden is an IBM developer relations Technical Consulting (also knownDragonslayersE-commerce architect, which provides education, implementation, and consulting for IBM business partners. He is dedicated to Linux-related work and will publicize the benefits of Linux to people around him as soon as he has the opportunity. In addition to fulfilling the responsibilities of his architect, he is also proficient in various fields of Linux infrastructure servers, including files, printing and other application services in the hybrid platform user environment. Chris has 10 years of experience in the computer industry. From field support to Web application development and consulting, he has been involved in various fields. You can contact Chris via cmwalden-at-us.ibm.com.

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.