Go: Linux basic commands Daquan

Source: Internet
Author: User
Tags set time unpack

Beginners may feel inconvenience when they touch Linux, but there is no connection, there is a process of contact with new things, after you have used Linux for some time, you will gradually understand that Linux is as easy to master as Windows.

Due to the unfamiliar operation and use of the environment, if you want to fully familiar with the application of Linux we first need to solve the problem is the Linux Common Command proficiency. In this chapter we will introduce the common basic commands for Linux.

Start Linux first. After the start of the user login required, select the user login different natural permissions are not the same, where "system administrator" has the highest privileges.

After starting Linux, the screen appears as follows:
......
Red Hat Linux Release 9 (shrike)
Kernel 2.4.20.8 on an i686
Login
Enter: root (administrator name), the computer displays the output password (password:), enter your password. When a "#" prompt appears on your computer, it indicates that you are successful!
screen displays the Linux prompt: [[email protected] root] #_
It should be noted here that "Red Hat Linux release 9 (shrike)" indicates the name and version of the operating system currently in use. "2.4.20.8" represents the core version number of the Linux operating system. "i686" indicates the level of CPU used by the computer.
Let's introduce the common basic commands.
First, logoff, shutdown, restart
Logout command to unregister the system
1,logout Logoff is the relative operation of the landing, after landing the system, to leave the system, the user can simply release the Logout command:
[[email protected] root] #logout
Red Hat linuxrelease 9 (shike)
Kernel 2.4.20.8 on an i686
Login:← back to the landing screen
2, shutdown or restart of the shutdown command
The shutdown command closes all programs and restarts or shuts down according to the user's needs.
The parameters are described as follows:
? Shutdown now: The-H parameter allows the system to shut down immediately. Examples are as follows:
[[email protected] root] #shutdown –h now← requires the system to be shut down immediately
? Specify shutdown time: The time parameter can specify when to shut down, or set how long to run the shutdown command, as shown in the following example:
[[email protected] root] #shutdown now← shut down immediately
[[email protected] root] #shutdown +5←5 minutes after shutdown
[[email protected] root] #shutdown 10:30← shut down at 10:30
? Auto restart after shutdown:-r parameter is set to restart after shutting down the machine. Examples are as follows:
[[email protected] root] #shutdown-R now← immediately shut down the system and reboot
[[email protected] root] #shutdown-R 23:59← Specify restart at 23:59
3. Restart the computer's reboot command
As the name implies, the reboot command is used to reboot the system. The commonly used parameters are as follows:
? -F parameter: Shut down the system and restart the computer by shutting down the normal program.

? -I parameter: Close all network interfaces before restarting.

Although the reboot command has a parameter that can be used, it is generally only necessary to run the reboot command separately.

  File and directory operations
the LS command
1,ls (list) command, which lists file lists, is a useful command to display a list of files and subdirectories in the current directory. With the use of parameters, the contents of the directory can be displayed in different ways. Here's an example:
? Displays the contents of the current directory:
[[[email protected] tony]$ ls
Desktop mail myinstall.log test.txt← has two directories and two folders
? When you run the LS command, the name "." is not displayed. The beginning of the file. Therefore, you can add the "-a" parameter to specify that you want to list these files. Here's an example:

[Email protected] tony]$ Ls–a
? The "-S" parameter displays all of the space for each file, and the "-S" parameter specifies the size of all occupied space. Examples are as follows:
[Email protected] tony]$ Ls–s–s
Total 36
4 Desktop 4 mail myinstall.log 4 test.txt
? When the LS command is added directly to the directory path you want to display, the contents of that directory are listed. Examples are as follows:
[Email protected] tony]$ Ls–l/usr/games
2. Switch directory to the CD command
The CD (change directory) command allows the user to cut the current directory. Examples are as follows:
[[Email protected] home]$ CD tony← switch to the Tony subdirectory in the current directory
[Email protected] tony]$ CD. ← Switch to the previous level directory
[[Email protected] home]$ CD/← switch to the system root directory
[[email protected]/]$ cd← switch to user home directory
[[email protected] tony]$ cd/usr/bin← switch to/usr/bin directory
3, create the mkdir command for the directory
The Make Directory command can be used to create subdirectories Mkdir. The following example creates a tool subdirectory in the same directory.
[Email protected] tony]$ mkdir tool
4. rmdir command to delete directory
The rmdir (remove directory) command can be used to delete "empty" subdirectories. Examples are as follows:

[[email protected] tony]$ rmdir tool← Delete tool directory

5. The CP command to copy files
The CP (copy) command allows you to copy files from one place to another. Typically when you use the CP command to copy a file to another file or to a directory, you need to specify the original file name and destination file name or directory. Examples are as follows:
[[email protected] tony]$ cp data1.txt data2.txt← copy Data1.txt to Data2.txt

[[email protected] tony]$ cp data3.txt/tmp/data← copy data3 to/tmp/data directory

? Show replication process: Join the-v parameter to display the command execution process. Examples are as follows:
[[email protected] tony]$ CP Zip.txt zip2.txt← General status does not show the copy process
[[email protected] tony]$ cp–v zip.txt zip3.txt← Display the copy process with-V
Zip.txt->zip3.txt
? Recursive system: Add "-r" parameter can copy all the files and subdirectories under the directory at the same time. Examples are as follows:
[[email protected] tony]$ cp–v–r * backup← copy all files (including subdirectory files) to the backup directory
6. Delete the RM command for a file or directory
The RM (remove) command can delete a file or directory. Examples are as follows:
[[Email protected] tony]$ RM myfile← Delete the specified file
[[Email protected] tony]$ RM *← Delete all files in the current directory
The common parameters of the RM command are as follows:
? Forced Delete: When using the-f parameter, the RM command deletes the file directly and no longer asks. Examples are as follows:
[[email protected] tony]$ rm–f *.txt← forced to delete files
? Recursive Delete:-R is also a fairly common parameter, using this parameter to delete all files and subdirectories in the specified directory at the same time. Examples are as follows:
[[email protected] tony]$ rm–r data← Delete the data directory (including all files and subdirectories in the data directory)
[[email protected] tony]$ rm–r *← Delete all files (including all files in the current directory, all subdirectories and subdirectories files)
? Force deletion of the specified directory: When you delete a directory with the-r parameter, if there are many subdirectories and files under that directory, you are asked continuously to confirm that you do want to delete the directory or file. If you have determined that you want to delete the stored directory and files, you can use the-RF parameter, so that all files and subdirectories in that directory will be deleted directly and no longer asked. Examples are as follows:
[[email protected] tony]$ RM–RF tmp forcibly delete the TMP directory and all files and subdirectories in that directory
? Show Delete procedure: Use the-v parameter. Examples are as follows:

[Email protected] tony]$ Rm–v

7, let the display screen pause more commands
In order to avoid the screen display instantaneous flash past, the user can use the more command, so that the screen display full page when the pause, you can press the SPACEBAR to continue to display the next screen, or press the Q key to stop the display.
? When you use the LS command to view a list of files, you can use the more command if there are too many files. Examples are as follows:
[Email protected] bin]$ Ls–al
More
? When you use the more command alone, you can display the contents of a text file. Examples are as follows:

[Email protected] tony]$ more Data.txt
8. Cat command to connect files
The Cat (CONCATENATE) command can display the contents of a file (often with the more command) or combine several files into one file. Examples are as follows:
? To display the contents of Preface.txt on a per-page basis:
[email protected] tony]$ cat Preface.txt
More
? After attaching the preface.txt to the Outline.txt file:
[email protected] tony]$ cat preface.txt >> outline.txt
? Merge New.txt and info.txt into the Readme.txt file:
[email protected] tony]$ cat new.txt info.txt >readme.txt
9, move or replace the file, the directory name of the MV command
The MV (move) command allows you to move files and directories under another directory, or to change the names of files and directories. Examples are as follows:
[Email protected] backup]$ mv A.txt. ← Moving a.txt files to the upper-level directory
[[Email protected] backup]$ MV Z1.txt z3.txt← renamed Z1.txt to Z3.txt
[Email protected] backup]$ CD. ← Switch to the previous level directory
[Email protected] tony]$ MV Backup. ←backup directory Move up one layer

10, displays the PWD command for the current directory
The PWD (print working directory) command displays the directory where the user is currently located. Examples are as follows:
[Email protected] tony]$ pwd
/home/tony← current directory is "/home/tony"
11. Find the Locate command for a file
The locate command can be used to search for a file or directory that contains a specified condition string. Examples are as follows:

[[Email protected] tony]$ Locate ZH_CN lists all files and directories that contain "ZH_CN" strings.
Since the locate command is to search for files from a database that holds files and directory names from the system, although the system updates the database periodically, the files and directories that have just been added or deleted may still not be available because the database has not yet been updated, and the UpdateDB command is updated with the root identity. The contents of this database are correct.
12, search string to get grep command
The grep command can search for a specific string and display it, usually to filter the previous results and avoid displaying too much unnecessary information. Examples are as follows:
[[email protected] etc]$ grep text *.conf← searches the current directory for files with the extension. conf and containing the "text" string.
Grep:amd.conf:← denied permission to operate
Grep:diskcheck.conf:← denied permission to operate
Grep:grub.conf← denied permission to operate
? If you are running with a user with general permissions, the output from the example above will contain a number of error messages such as "Deny actions that do not work," which can be eliminated using the-s parameter.
[Email protected] etc]$ grep–s text *.conf
13, re-conduction and piping
The redirect can output the result of a command in a guide file, which has two commands: ">" and ">>". ">" can output the result to a file, the original content of the file will be deleted: ">>" will append the results to the file, the original file content will not be erased. Examples are as follows:
[[email protected] tony]$ ls–a>dir.txt← outputs the ls–a command execution results to the Dir.txt file.
[[email protected] tony]$ cat data1.txt >> data2.txt← append data1.txt content to the Data2.txt file.
The symbol for the channel (pipe) command is "", which outputs the result of a command to another command, and the example passes the output of the LS command to the grep command filter:
[[email protected] etc]$ ls
Gerp conf← searches for and displays the "conf" string contained in the LS command run result
In an example of deleting a file or directory, you can use the Yes command to repeat the output of the "Y" character, passing the result to the RM command, thus avoiding repeated input "Y":
[[email protected] tony]$ Yes
Rm–r Mydir

Third, the use of CD-ROM and floppy
In the Linux text mode to use the disc or floppy disk, not only the disc or floppy disk, users need to run the loaded command, to read and write data. Loading is the designation of storage media (such as discs and floppy disks) as a directory in the system (such as/mnt/cdrom or mnt/floppy). By accessing this load directory directly, you can read and write data from the storage media. Here's a look at the loading and unloading commands in text mode.
1, load the Mount command
To use the disc, place the disc in the CD-ROM drive, and then execute the loaded mount command to load the disc into the system:

[[email protected] tony]# mount/dev/cdrom/mut/cdrom← loading disc
Similarly, a floppy disk must be loaded before it can be used, just like a disc:
[[email protected] tony]# mount/dev/fd0/mut/floppy← loading floppy disk
2, uninstall the Umount command
If you do not need to use a disc or floppy disk, you must perform the uninstall command before you can exit the disc or floppy disk. Examples are as follows:
[[email protected] tony]# umount/mnt/cdrom← disc Uninstall
Execute the umount command to unmount the floppy disk without using a floppy disk, and then remove the floppy disk
[[email protected] tony]# umount/mnt/← floppy diskette Uninstall
Four, running the program in the background
Sometimes the user's program may take a lot of time, and if you put it in the foreground, it will prevent you from doing other things, the best way is to keep it running in the background, and you may even want the program to continue running after the user logs off the system. Let's see how that can be achieved.
1, run the program in the background &, BG command
The simplest way to put a program in the background is to add "&" at the end of the command, as in the following example:
[[email protected] root]# updatedb &← perform locate database update command in the background
[[email protected] root]# bg← to run the update operation in the background
2, the foreground runs the program FG command
If the user currently has a program running in the background, you can enter the FG command to move it from the background to the foreground run:
[[email protected] root]# fg← put in front of the command will be displayed
3. Nohup command to keep the program running after exiting
This command enables the program to continue running after the user exits the system. Examples are as follows:
[Email protected] rony]$ nohup MyServer &

The user can then exit and, when logged in again, can use the Ps–aux command to see that the program is still running in the background.

V. Task scheduling commands
Computers have many programs that need to be used periodically, such as cleaning up disk scratch disks, backing up system data, checking messages from remote servers, and so on. For these repetitive tasks, it is not necessary to run these programs every time. You can use task scheduling commands to specify that the system periodically runs these programs at a certain time, and to easily complete the work you want to do.
Crond resident command for task scheduling
Crond is a command that Linux uses to execute programs on a regular basis. This task Transfer command is started by default when the operating system is installed. The Crond command periodically checks to see if there is work to be done and automatically performs the work if there is work to be done. Because the task scheduling in the middle of the operation process is very complicated, we will only introduce the task scheduling file to everyone, for everyone to see:

Minute Hour Day Month DayOfWeek Command
In this text, except that "Command" is a field that must be specified each time, other automatic visual requirements are self-determining whether to specify.
Vi. Task scheduling System work
The/ect/crontab/file is a task scheduling setup file for Linux systems Engineering, and its default content is as follows:
shell=/bin/bash← Specifies the shell that is used to perform task scheduling work
Path=/shin:/bin:/usr/sbin:/usr/bin← specifying the path to a command search
mailto=root← specifies that the output will be given to the root user
home=/← specified with directory

Vii. Individual work of task scheduling
In addition to the above-mentioned task scheduling system work, the general user can use the Crintab command, set up the work to be performed on a regular basis.
Each user can execute the crontab–e command, edit his or her task scheduling settings file, and join the work to be performed on a regular basis in this file. The following example sets the task scheduling settings file for Tony users to edit:
[Email protected] rony]$ crontab–e
After executing the above command, you will go to the vi text editor to edit the Task Scheduler yourself.

Viii. Delete a scheduled work task
If you do not want to periodically perform the work in a task transfer, you can execute the crontab–r command to remove all task scheduling. Examples are as follows:
[[email protected] rony]$ crontab–r← Delete work in Task Scheduler
[[email protected] rony]$ crontab-1← review work in Task Scheduler
No crontab for tony← No task is scheduled to work
Nine, packaging, compression and decompression
Since this is the basic functionality that every Linux user will often use, we will describe the most common packaging, compression, and decompression programs.
1. Tar command for packaged files
The TAR command is located in the/bin directory, which packages the files or directories specified by the user into a single file, although it does not compress. Generally, the common Unix compression method is to first use the TAR command to package many files into a file, and then compress the file with the compression command such as gzip. The parameters of the tar command are numerous, as described in the following examples:
? -C: Create a new tar file;
? -V: Displays the operation process information;
? -F: In: Specify the file name;
? -Z: Call the gzip compression command to perform the compression;
? -j: Call the BZIP2 compression command to perform the compression;
? -T: See the contents of the compressed file;
? -X: Unpack the tar file.
In this case a common example:
[[Email protected] data]# tar CVF data.tar *← package All files in the directory into Data.tar
[[Email protected] data]# tar CVF data.tar.gz *← package all directory files into Data.tar and compress with gzip command
[[Email protected] data]# tar TVF data.tar *← see which files are included in the Data.tar file
[[Email protected] data]# tar xvf data.tar *← unlock Data.tar
2, compression and decompression
The tar command itself does not have the ability to compress, but it can be compressed with other compression commands immediately after the resulting tar file, and the provinces need to enter two commands.
? Use the-Z parameter to unlock the most common. tar.gz files:
[[email protected] data]# TAR–ZXVF foo.tar.gz← Unpack the file into the current directory
? Use the-j parameter to unpack the tar.bz2 compressed file:
[[email protected] data]# TAR–JXVF linux-2.4.20tar.bz2← Unpack the file into the current directory
? Use the-z parameter to specify to compress with the Compress command

[[email protected] data]# TAR–CZVF prcture.tar.z*.tif all. tif packages and commands in this directory are compressed into. tar.z files

X. Other COMMON commands
There are quite a few commands available for Linux, and in this chapter we only illustrate a few of the commands that are commonly used, and in later chapters, there are many other commands.
1. passwd command to change password
The passwd (password) command allows the user to change the password. Examples are as follows:
[Email protected] tony]$ passwd
Changing password for user Tony
Changing password for Tony

(current) UNIX password:← Enter the original password
New password:← Enter the password
Retype new password← here Enter the password
Passwd:all authentication tokens updated successfully← password modified successfully
2, create the Mkbootdisk command for the boot disk
If the system is installed without a boot disk, or if the boot disk is compromised, you can create a new boot disk with the Mkbootdisk command after the system is installed:
[Email protected] root]# mkbootdisk ' uname-r '
Execute the instructions above to successfully create a boot disk. Please save the shavings and have it ready for urgent use.
3, display date, clock, and Ntpdate command with set time
The date command can display the current date time. Examples are as follows:
[[Email protected] rony]$ Date
-September 8 10:00:00 CST 2006
CST for Central Standard Time
The clock command can also display the current date and time of the system, but the clock command does not allow the normal user to execute by default, please use the root account:
[Email protected] root]# clock
September 8, 2006 CE (Friday) 10:00 00 sec 0.112604 seconds
You can use the date command to set the time if the system time is incorrect to change. Use the root account to do the following:
[[Email protected] root]# Date 09091200← set the time to September 9 12:00
Users may sometimes suffer from a lack of knowledge of standard time. It doesn't matter, the standard time provided by the server for proofreading is also available on the current network. Therefore, the ntpdate command is executed to set the system time to coincide with the school time server:
[Email protected] root]# ntpdate stdtime.microsoft.com← with Microsoft School when the server is in school.
Then execute the date command again, and you will see that the system time has changed. However, this is not the end, and you need to execute the clock–w command to write the time of the change to the computer's CMOS so that the changed time is not used on the next boot. Examples are as follows:

[Email protected] root]# clock–w

The basic commands that we use are introduced here, and now we are going to talk about some of the problems that novice users encounter in the process and some of the techniques used in the process of operation.
First, how to enter the text mode
When you install Linux, you can choose to enter text mode or when graphics mode automatically. If you select the text mode you can skip this description, if you go directly to the X Window graphics mode, you can still use the following methods to enter the text mode:
1. Open the Text Mode window in X Window
In the Default Gnome window environment, for example, the simplest way to enter text mode under X Windows is to click the right mouse button on the left side of the desktop and execute "new Terminal command" to open the Text mode window. In the text mode window, you can use the Shift+page up and shift+page dwon keys to scroll through the contents of the window.

2. Switch virtual main console into text mode
The Linux host provides 7 virtual consoles under the main console (console) and can run their own programs in each virtual host console. You can switch to the other virtual consoles at any time after landing the X Window System by pressing the CTRL+ALT+FN key. The FN is the function key of F1~f7.
3, launch direct into text mode
To set the startup to enter text mode directly, you can use any text editor, open the/etc/inittab file, find "Id:5:initdefault:" In the file, and change it to "Id:3:initdefault:".
Second, Etc/inittab Setup error, cause unable to start
If you do not start properly after modifying the/etc/inittab, you can enter the system in single-player mode at startup and re-modify the Inittab settings file to resolve the problem.
If you use grub as the boot loader, simply press the A key when you start the Display menu screen and enter the parameters at the command line to enter single-player mode:
Grub Append > Ro root=label=/s← simply add "s" after the command line's original statement
When using Lilo as the boot loader, press ctrl+x to switch to the Lilo login screen in text mode and enter the following parameters when you start to display the Lilo menu screen:
Boot:linux s← says the system goes straight into single-player mode
Third, how to query the use of commands
In a Linux system, you can use the man command to query for help if the functionality of a user command is not clear:
[[email protected] root]# man shutdown← use the man command to query the usage of the shutdown command to be introduced later.
The syntax for most commands can also be queried by the-H or-help parameters. For example the syntax of the shutdown command can be run Shutdown–h or the above man shutdown command is checked.
Iv. avoid pressing Ctrl+alt+del to restart the system
If you do not want anyone to restart your computer with this set of keys when you press Ctrl+alt+del three keys directly in Linux, modify the/etc/inittab file with a text editor:
#ca:: Ctrlaltdel:/sbin/shut down–t3–r now← Add "#" before this.
After saving, restart the calculation, you will not be able to restart with the Ctrl+alt+del key.

Five, text mode of Chinese information garbled, how to do
In this version of Red Hat Linux, if you open the Text Mode window in X window and operate in text mode, all Chinese filenames, months, and even some of the information can be displayed in Chinese correctly. However, in the text mode of the Virtual Console, these Chinese information will become garbled, at this time, please do the following, you can change this information to display in English:
[Email protected] root]$ lang=c
[Email protected] root]# ls–l

Run the Lang=c command after the original in Chinese display (garbled) part, into English
If you want to change back to your original settings, simply execute the LANG=ZH_CN command again:
[Email protected] root]$ LANG=ZH_CN
Vi. cannot see the Chinese file name
If the loaded storage media contains Chinese file names, you need to run the Mount command again, plus the "-o iocharset=cp950" parameter to see the Chinese file name in this saved media. For example, loading a disc allows you to execute the following command:
[Email protected] root]# Mount–o Iochatset=cp950/dev/cdrom/mnt/cdrom
Vii. How to swap discs
When the disc has been loaded into a directory, pressing the exit button on the optical drive will not eject the disc, you must first unmount the disc before exiting the disc.
If the current location is the CD-ROM loading directory (such as/mnt/cdrom), or there are other users in this directory, will not be able to successfully uninstall it, of course, can not exit the disc:
[Email protected] root]# Umount/mnt/cdrom
Umount:/mnt/cdrom:device is busy← this disc is in use
You can uninstall the directory and exit the disc by switching the working directory elsewhere or requiring other users to leave the directory. After changing the shutdown, remember to load the disc again before you can use it.
Viii. allow normal users to load discs or floppy disks
The Linux operating system only allows the root user to run the Mount command by default, and if the average user executes the above command, the following error message appears:
[Email protected] root]# Mount/dev/cdrom/mut/cdrom
Mount:only Root can do that← only the root user can execute this command
Therefore, to allow normal users to load discs or floppy disks, modify the/ect/fstab/settings file:
/dev/cdrom/mut/cdrom udf,iso9660 noauto,owner,kudzu,ro,user← to let the general user also load the disc, add the ", User" item here.
There are many other application directives for Linux, and we will follow them in future learning and application.

Go: Linux basic commands Daquan

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.