Common commands in Linux (UBUNTU)

Source: Internet
Author: User

The following command can be used to obtain more information through -- help.

1. query the list of files in the current directory: ls
By default, the LS command will list all the content in your current folder in ascending order of the first letter, but the information obtained by running this command is relatively small, generally, it can run with the following parameters to query more information:
Ls/show all files and directories under /.
Ls-L provides detailed information about the file or folder.
Ls-A displays all files, including hidden files.
Ls-H returns the file size in KB, MB, or GB, not just bytes.

2. query the current directory: pwd
In the Linux hierarchical directory structure, you can use the mkdir command in any authorized directory to create a new directory, or use the CD command to convert one directory to another. However, there is no prompt to tell the user which directory is currently in. To know the current directory, run the PWD command to display the entire path name.
Syntax: pwd
Note: This command displays the absolute path of the current working directory.

3. Go to another directory: CD
Function: change the working directory.
Syntax: CD [Directory]
Note: This command changes the current directory to the directory specified by directory. If no directory is specified, return to the user's home directory. To change to a specified directory, you must have the execution and read permissions on the specified directory.
For example:

Macroli @ macroli-desktop :~ $ CD/root/
Macroli @ macroli-desktop:/root $ pwd
/Root
Macroli @ macroli-desktop:/root $

4. output the character echo on the screen.
Example: macroli @ macroli-desktop:/root $ echo "Hello"
Hello

5. Show the file content: Cat
Example: macroli @ macroli-desktop:/tmp $ cat temp
Text test temp

6. copy the file: CP
This command is used to copy the given file or directory to another file or directory. It is very powerful like the Copy command in msdos.
Syntax: CP [Option] source file or directory target file or directory Description: This Command copies the specified source file to the target file or copies multiple source files to the target directory.
The options of this command are as follows:
-A this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of DPR options.
-D: the link is retained during copy.
-F delete an existing target file without prompting.
-I and F options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is Y, the target file will be overwritten, which is an interactive copy.
-P in addition to copying the source file content, CP also copies the modification time and access permissions to the new file.
-If the source file provided by R is a directory file, CP will recursively copy all subdirectories and files in the directory. The target file must be a directory name.
-L do not copy, but only link files.
Example: macroli @ macroli-desktop :~ $ Ls
Desktop examples file2.txt new_file.txt
Macroli @ macroli-desktop :~ $ CP file2.txt file2_copy.txt
Macroli @ macroli-desktop :~ $ Ls
Desktop examples file2_copy.txt file2.txt new_file.txt

7. Move the file: MV
You can use the MV command to rename a file or directory or move the file from one directory to another. This command is like a combination of Ren and move in msdos.
Syntax: MV [Option] source file or directory target file or directory
Description
Note: depending on the type of the second parameter in the MV command (whether it is the target file or the target directory), the MV command will rename the file or move it to
In the new directory. When the second parameter type is file, the MV command renames the file. At this time, only one source file (or the source directory name) can be used ), it renames the given source file or directory to the specified object.
File Name. When the second parameter is an existing directory name, there may be multiple source files or directory parameters. The MV command moves the source files specified by each parameter to the target directory. When moving files across file systems,
The MV is copied first, and then the original file is deleted, and the link to the file will be lost.
The meaning of each option in the command is:
-I interactive operation. If the MV operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to Answer Y or N. This will avoid overwrite the file by mistake.
-F prohibit interactive operations. When an MV operation overwrites an existing target file, no instructions are given. If this option is specified, the I option will no longer work.
Example: macroli @ macroli-desktop :~ $ Ls
Desktop examples file1.txt file2.txt
Macroli @ macroli-desktop :~ $ Mov file1.txt new_file.txt
Macroli @ macroli-desktop :~ $ Ls
Desktop examples file2.txt new_file.txt
Macroli @ macroli-desktop :~ $ MV-V file2.txt file2_new.txt
'File2.txt '-> 'file2_new.txt'

8. Create an empty text file: Touch
Example: macroli @ macroli-desktop :~ $ Ls
Desktop examples
Macroli @ macroli-desktop :~ $ Touch file1.txt
Macroli @ macroli-desktop :~ $ Ls
Desktop examples file1.txt

9. Create a directory: mkdir
Function: create a directory (similar to the MD command in msdos ).
Syntax: mkdir [Option] Dir-name
Note: This command creates a directory named by Dir-name. The user who creates a directory must have write permission in the current directory (the Dir-name parent directory), and The dirname cannot be an existing directory or file name in the current directory.
The meaning of each option in the command is:
-M sets the access permission for the new directory. You can also set it using the CHMOD command.
-P can be a path name. If some directories in the path do not exist, after this option is added, the system automatically creates those directories that do not exist, that is, multiple directories can be created at a time.
Example: macroli @ macroli-desktop :~ $ Ls
Desktop examples file2_copy.txt file2_new.txt new_file.txt
Macroli @ macroli-desktop :~ $ Mkdir test_dir
Macroli @ macroli-desktop :~ $ Ls
Desktop examples file2_copy.txt file2_new.txt new_file.txt test_dir

10. delete the file/directory: Rm
You can use the RM command to delete unnecessary files. This command is used to delete one or more files or directories in a directory. It can also delete a directory and all its files and subdirectories. For linked files, the link is closed, and the original file remains unchanged.
Syntax: Rm [Option] File
Note: If the-r option is not used, RM will not delete the directory.
The options of this command are as follows:
-F ignores non-existing files and never gives a prompt.
-R indicates that Rm recursively deletes all directories and subdirectories listed in the parameter.
-I.
Example: macroli @ macroli-desktop :~ $ Ls
Desktop examples file2_copy.txt file2_new.txt new_file.txt test_dir
Macroli @ macroli-desktop :~ $ Rm-r test_dir
Macroli @ macroli-desktop :~ $ Ls
Desktop examples file2_copy.txt file2_new.txt new_file.txt
Macroli @ macroli-desktop :~ $ RM new_file.txt
Macroli @ macroli-desktop :~ $ Ls
Desktop examples file2_copy.txt file2_new.txt
The deletion operation does not prompt security. You can run the following command:
Macroli @ macroli-desktop :~ $ Rm-I file2_new.txt
RM: Do you want to delete the General empty file 'file2_new.txt '? Y

If you set rm-I to the default value, run the following command:
Macroli @ macroli-desktop :~ $ Alias Rm = 'rm-I'

11. query the current process: PS

12, more, less
These are two commands for displaying common text files. If a text file is too long to display more than one screen, it is not ideal to use cat.
Try the more and less commands. The more command can temporarily hold a file with more than one page on the screen. It will not be displayed until you press any key. In addition to more functions, less
You can also use the arrow keys to scroll up or down the network to scroll up the file, so you can browse it at will. When reading the article, less is a good choice.

13, clear
This command is used to clear the screen. It does not require any parameters. It has the same function as the CLR in DOS. If you think the screen is too messy, you can use it to clear information on the screen.

14, PWD
The purpose of this command is to display the current working path of the user. This command does not need to be said.

15, ln
This is another very important command in Linux. Please be familiar with it. Its function is to create a non-same link for a file in another location. The most common parameter of this command is-S. The specific usage is the target file of the Ln-S source file.
When
When we need to use the same file in different directories, we do not need to put a file that must be the same under each required directory. We only need to put it in a fixed directory, put the file, and then
You can use the ln command link in the directory without occupying disk space repeatedly. Example: ln-S/bin/less/usr/local/bin/less
-S indicates the symbol (symbolic.
This
There are two points to note: first, the ln command will keep the synchronization of each link file, that is, no matter which one you change, other files will change the same; second, ln links and soft links
Or hard link. The soft link is ln-s *****. It only generates an image of a file at the position you selected and does not occupy disk space, hard link ln ***, no parameter-S, it will be in your
A file of the same size as the source file is generated at the selected position. both soft and hard links keep the file Changing simultaneously.
If you use ls to view a directory, you will find that some files are followed by a @ symbol, that is, a file generated using LN command, and you can use LS-l command to view it, the link path is displayed.

16, man
For example
If your English is good enough, you can be proficient in Linux without relying on anyone, as long as you use man. Man is actually looking at the help of command usage and learning the operating system of any UNIX class.
The most important thing is to learn to use the man Auxiliary Command. Man is the abbreviation of manual (manual). Its description is very detailed, but it seems a headache because it is both in English. Large recommendation
Go back to man when you need it. Do you have to remember some basic usage.

17. logout
I can see it at a Glance. This is the command to exit the system, and I don't have many.
Said. It should be emphasized that Linux is a multi-user, multi-process operating system, so if you don't need it, you can quit the system. You don't have to worry about shutting down the system, that is the case for the system administrator. However
Remember, even if you use Linux on a single machine, logout cannot be shut down directly because it is not a command to shut down.

Run the following command to decompress the package:

. Zip
Decompress: unzip filename.zip
Compression: Zip filename.zip dirname
---------------------------------------------
. Rar
Decompress: rar a filename.rar
Compression: R ar e filename.rar

---------------------------------------------

. GZ
Decompress 1: gunzip filename.gz
Decompress 2: gzip-D filename.gz
Compression: gzip filename
.Tar.gz
Decompress: Tar zxvf filename.tar.gz
Compression: Tar zcvf filename.tar.gz dirname
---------------------------------------------
. Bz2
Decompress 1: Bzip2-D filename.bz2
Decompress 2: bunzip2 filename.bz2
Compression: Bzip2-Z filename
.Tar.bz2
Decompress: Tar jxvf filename.tar.bz2
Compression: Tar jcvf filename.tar.bz2 dirname
---------------------------------------------
. Bz
Extract 1: Bzip2-D filename. bz
Decompress 2: bunzip2 filename. bz
Compression: Unknown
. Tar. bz
Decompress: Tar jxvf filename.tar. bz
Compression: Unknown
---------------------------------------------
. Z
Decompress: uncompress filename. Z
Compression: compress filename
. Tar. Z
Decompress: Tar zxvf filename.tar. Z
Compression: Tar zcvf filename.tar. Z dirname
---------------------------------------------
. Tgz
Decompress: Tar zxvf filename. tgz
Compression: Unknown
. Tar. tgz
Decompress: Tar zxvf filename.tar. tgz
Compression: Tar zcvf filename.tar. tgz filename

RAR Please download to: http://www.rarsoft.com/download.htm!
After decompression, copy rar_static to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2 TMP] # cp rar_static/usr/bin/RAR
---------------------------------------------
. LHA
Decompress: LHA-e filename. LHA
Compression: LHA-a filename. LHA filename

Lha please: http://www.infor.kanazawa-it.ac.jp /~ Ishii/lhaunix/download!
> After decompression, copy LHA to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2 TMP] # cp LHA/usr/bin/
---------------------------------------------
. Rpm
Unpack: rpm2cpio filename. RPM | cpio-Div
---------------------------------------------
. Tar. tgz .tar.gz. Tar. Z. Tar. BZ .tar.bz2. Zip. cpio. rpm
. Deb. SLP. ARJ. rar. Ace. LHA. lzh. LZX. LZs. Arc. SDA. SFX
. Lnx. Zoo. Cab. kar. CPT. Pit. Sit. Sea
Decompress: Sex x filename .*
Compression: Sex a filename. * filename

Reprinted on http://blog.csdn.net/afeilxc/archive/2008/10/09/3040870.aspx

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.