Common commands (UBUNTU)

Source: Internet
Author: User
Tags clear screen gz file uncompress

1. How to open the terminal

In ubuntu, press the first "Panel homepage (Dash homepage)" on the Left bar (you can press win to bring up the page) and enter terminal to open the terminal, in addition, press CTRL + ALT + T to open the terminal.

 

2.Change User Password

Enter passwd in terminal, press enter, enter the new password, press enter, enter the new password again, and press Enter. Note that the * number is not displayed when you enter the password in Linux, so do not enter an error.

 

3.Enter Root(Super administrator) Permission Method

1) if it is a rethat system, the system will directly enter the root Super Administrator after startup. If the user is not root, enter Su on the terminal and press enter to enter the root user.

2) if it is a Ubuntu system, it is a common user after startup. You need to set the root password first on the terminal. The method isSudoPasswdRoot, Press enter, and then prompt to enter the password. Then press enter, and then prompt to enter the password again to confirm. After confirming the password, press enter to complete the root password setting. Then, just like rethat, enter Su on the terminal and press enter, prompting you to enter the root password. Enter the password you just set.

Note: sudo isSUperUSerDoAbbreviation

4.Install and uninstall software, Update command

Install software: sudo apt-Get install <Software Package Name>

For example, install scim Input Method: sudo apt-Get install scim

Uninstall software: sudo apt-Get remove
<Software package name>

Uninstall the scim Input Method: sudo apt-Get.
Remove scim

If an associated object is to be detached, the system will automatically prompt you to use sudo apt-Get.
Autoremove to automatically clean up.

Upgrade: sudo apt-Get
Update

For example, upgrade VI to "sudo apt-Get install Vim"

5.Shutdown, restart, logout, switch user, exit terminal, clear screen command

Shutdown-H
Now

Restart: shutdown-R
Now
Or reboot

Switch User: SU (SWitch
USer)

Logout: Logout (only shell in command-only mode is available)

Exit terminal: Exit

Clear screen: Clear

6.Use viEditor (available for writing)Program, Text, etc.).The compiler is vi..

VI has three modes: command line mode, insert mode, and bottom line mode. However, some command line and baseline modes are combined into two modes: Command Line and insert.

1) Enter
VI
Filename. suffixname (for example
VI first. C or VI second. cpp) Press enter to confirm, which is equivalent to creating a new notepad file but not saving it. (Note that the command line mode is used, and the characters cannot be entered)

2) press I to enter the insert mode (to enter the insert mode, enter characters) and then enter the program.

3) Press ESC to exit the insert mode (entering the command line mode for copying, pasting, and deleting characters)

4) In command line mode, enter the colon ":" To exit the command line mode and enter the baseline mode (the cursor is located at the bottom line of the screen, and you can save or exit the file ).

5) in baseline mode, press W to save, Q to exit, and Q! Force exit and do not save, X exit and save. Generally, you can directly enter WQ and press enter to save and exit.

6) run the LS (list) command to view the current folder and use LS-L to view the detailed information of the file.

7) Compile the c file just saved with the GCC compiler.

Method: ① gcc
Filename. C (or GCC filename. cpp) is named A. Out by default.

② GCC filename. C-o
Filename. Out. In this way, the name of the compiled. Out file will not be named A. Out by default, but file_name.out.

8) If you want to edit an existing file, for example, if the previously written C program has an error and you want to modify it, enter

VI
Filename. C (or VI filename. cpp) to edit the file.

9) modify the file name: MV oldname newname (note that the terminal interface should be used instead of the VI command interface)

10) Run filename. the out file directly uses ". /filename. out, that is, the GCC compiler C "file compiled into". after "out", run ". "Out" file, directly add "..


Note: gcc
(GNU Compiler
Collection
)

VI commands for deleting and modifying files (note that files are in edit mode rather than insert mode ):

X: Delete the character of the cursor.

DD: Delete the column where the cursor is located.

R: Modify the character where the cursor is located and the character to be corrected after R.

R: Enter the replacement status. The new text will overwrite the original text until you press
[ESC] Return to the command mode.

S: Delete the cursor character and enter the input mode.

S: Delete the column where the cursor is located and enter the input mode.

7. Copy and move the deleted file

1) Copy

CP
[
Option]
Source file or directory

Target file or directory

The options are as follows:

-
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
In contrast to the f option, 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, CP also copies the modification time and access permissions to the new file.

-R
If the source file 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, just link the file.

2) Delete(Use RM to delete recoverable and unrecoverable shred files)

Rm
[
Option]
File

-F
Ignore non-existing files and never give a prompt.

-R
Indicates that Rm recursively deletes all directories and subdirectories listed in the parameter.

-I
Interactive deletion.

3) Move (rename)

MV
[
Option]
Source file or directory

Target file or directory

When the target is a file, rename the source file to the target file name. If the target is a directory, move the source file or directory to the target directory.

8. display your current directory

PWD (present which dirctory)

9.Add User

Useradd user_name
Adduser user_name

10.Change Password

Passwd
User_name (if user_name is not followed, the password is set for the current user)

11.Create directory

Mkdir [Option]
[Dir_name]

Option:
-P: Make sure that the user exists. If the user does not exist, create

-M: Set the access permission for the new directory.

12.Modify file directory owner
Chown(Change owner)

Mkdir-P
/Home/user_name
(P indicates path)

Chown user_name: usrgp_name
/Home/newuser (note that there is a space in front of/and name in front of home, otherwise an error will occur)

13.Delete a user

Userdel
User_name)

If userdel-R is used
User_name, the user file and user directory will be deleted (the directory containing the User File)

If you use adduser to add a user, use deluser user_name to delete the user.

14. LinuxView User Group Information

Groups
View group information of the currently logged-on user

Groups
User_name
View the group of user_name users and group members

Whoami
View Current logon Username

Who

Displays the user information of the directory to log on to the system.

Whois user_name

Search for and Display User Information

W

Displays the user information currently logged on to the system.

Finger
Query user information

15. Linux running level (7 in total)

Command: init
[0123456]

0
Shutdown

1
Single User

2
No network service in multi-user status

3
Multi-User statuses with Network Services

4
The system is not used and retained to the user.

5
Graphic Interface

6
System restart

Modify the default running level file:

In the/etc/inittab, ID: 5: initdefault: number in this row, for example, change 5 to 1.

16. Modify the user name

Use VI to edit/etc/passwd under the root directory, and change the user name in the last line, after modification, WQ is saved and exited, and then restarted with reboot (first, convert Su to root)

 

"GNU grub" or "grub" is grand
Uniied
The abbreviation of bootloader is a multi-operating system startup manager. It is used to guide different systems, such as Windows and Linux.

17. Compress and decompress (package and decompress)

 




Compress and package related commands

Command

Command description

Format

Bzip2

. Bz2 File compression (or decompression) Program

Bzip2 [Option]
Filename

Bunzip2

. Bz2 file decompression program

Bunzip2 [Option]
Filename.bz2

Bzip2recover

Repair damaged. bzw files

Bzip2recover.bz2 compressed file

Gzip

. GZ File compression program

Gzip [Option]
Filename

Gunzip

Decompress the compressed GZIP file.

Gunzip [Option]
Filename.gz

Unzip

Decompress the. ZIP file of winzipzip

Unzip [Option]
Filename.zip

Compress

Early Compression or decompression programs (after compression, the file name is. Z)

Compress [Option]
Filename

Tar

Package or unpackage files or directories

Tar [Option] [filename] list
Of File

 

1) gzip: compress and decompress the file, and gzip will automatically identify the compression or decompression according to the file type.

Format:Gzip [Option]
Filename







 Gzip parameter list 

parameters

parameter meaning

-C

write the output information to the standard output and keep the original file

-D

decompress the compressed file

-L

the following fields are displayed for each compressed file: size after compression, size before compression, compression ratio, file name before compression

-r

Search for the specified directory and compress or decompress all the files in it

-T

test and check whether the compressed file is complete

-v

display the file name and compression ratio for each compressed and decompressed file

 

2) tar: package or unpackage the file directory.

 




Tar
List of common Command Parameters

Option

Parameter description

-C

Create a new packaging File

-R

Append an object to the end of the package.

-X

Decompress the file from the package file

-O

Unbind files to standard output

-V

Output related information during processing

-F

Operations on common files

Z

Call gzip to compress the package, and call gzip to decompress the package when it is associated with-X.

-J

Call Bzip2 to compress the package, and call Bzip2 to decompress the package when it is used with-X.

-Z

Compress is called to compress the package, and compress is called to decompress the package when it is used with-X.

Example:


Tar-CVF
A.tar


Create the tar package of file


Tar-tvf
A.tar


View files contained in the TAR package


Tar-xvf
A.tar


Release the tar package file


Tar-RVF
A.tar B


Add file B to tarpacket a.tar


Tar-aVF
A.tar c.tar

Add the c.tarpackage to the a.tar package


Tar-zcvf
A.tar.gz

Create a gzip compressed tar package for file


Tar-ztvf
A.tar.gz

View the tar Package content of file



Tar-zxvf
Aa.tar.gz

Release the aa.tar.gz package


Tar-jcvf
Aa.tar.bz2 AA
 
Create a bzip compressed tar package for file


Tar-jtvf
Aa.tar.bz2

View the tar Package content of file


Tar-jxvf
Aa.tar.bz2

Release aa.tar.bz2 package

 



 





List of common Linux compression and decompression commands


File suffix


Decompress command


Example

.

Tar XV

Tar XV hello.

. Z

Uncompress

Uncompress
Hello. Z

. GZ

Gunzip

Gunzip hello.gz

. Tar. Z

Tar xvzf

Tar xvzf
Hello.tar. Z

.Tar.gz/. tgz

Tar xvzf

Tar xvzf
Hello.tar.gz

. Rpm

Installation: rpm-I

Installation: rpm-I
Hello. rpm

Decompress: rpm2cpio

Decompress: dpkg-I
Hello. Deb

. Deb

Installation: dpkg-I

Installation: dpkg-I
Hello. Deb

Decompress: dpkg-Deb
-- Fsys-tarfile

Decompress: dpkg-Deb
-- Fsys-tarhello hello. Deb

. Zip

Unzip

Unzip hello.zip

Note: The Role of the tar command is to package or unpackage the file. Note that package and decompress are different.

Package: convert some files or directories into a total file (convert many files into a single file ).

Compression: compress a large (note: "One") FileAlgorithmTo a small file.

In Linux, many compression programs such as gzip can only compress one file. In this way, when you want to compress more files, you must compress these files into a package using other tools, then, compress the package with the compression program.

18. view and modify file read/write permissions
In the preceding example, the read/write permission of the file is LS-L.
XXX. XXX (XXX. XXX is the file name)

Modify the file read and write permissions: chmod XXX ***. *** (XXX is a three-digit file name, And ***. *** is a file name)

Example: chmod 700
Name.txt (indicates that the file owner has three permissions: read, write, and execute, while all file groups and other users in the system have no read, write, or execute permissions ), you can modify the three digits in the middle to modify different permissions.

Example:-rwx -- r --

The preceding example contains 10 characters,
The first note: indicates the file type. In the previous example, "-" indicates a common file. In addition, there are:
Directory file (represented by "D)
Link file (represented by "L)
Character device (represented by "C)
Block device (represented by "B)
Named Pipe (represented by "p)
Stack file (represented by "F)
Socket (represented by "S)
Each of the following nine characters is divided into three groups.
Group 1: file owner (u, user)'s permissions on the file
Group 2: permissions of all file groups (G, Group) on files
Group 3: permissions of other users (O, other) on files
In these three groups, the three characters in each group are displayed in order: read, write, and execute (read, write, and execute)
The three characters in each group can be represented by an octal number. The octal number is converted from binary. The method is as follows:
For example, rwx is represented by binary 111, r -- is represented by 100,-w-is represented by 010, -- X is represented by 001, and --- is represented by 000, the binary numbers 100,010,001 and 000 are represented by octal values 4, 2, 1, and 0, respectively.

If the file is readable and writable, that is, rwx, rwx can be expressed by numbers 7 (4 + 2 + 1) and 4 can be read by r -- (100 ), 2. You can write-w-(010) and 1 to execute -- X (001 ).

R --
-W-
-- X
Rwx
(R -- +-w-+ -- X) = rwx
For example, chmod 700
Name.txt, modify the access attribute of the name.txt file. In 700, the first digit indicates the permissions of the file owner, the second digit indicates the permissions of all groups of the file, and the third table.
Shows the permissions of other users in the system. 7: 42.1622.161(rwx), the file owner has three permissions to read, write, and execute the name.txt file, and the second and third are both 0
0100000100000(---133, all groups of hosts files and other users of the system do not have the permission to read, write, and execute name.txt. (Of course, this is just an example. In fact, TXT files are not allowed.
Executed)

19. Restart X-Windows(Explorwindwos的explorer.exe)Method

By default, restart X-Windows in Ubuntu with ALT + print + k

20. Ubuntu Desktop shortcut
CTRL + super + d (Super is the Windows key, that is, the one between CTRL and ALT)
Tip: press the super key to display all the shortcut keys.

21. Set the Linux update source

First backup: $ sudo CP
/Etc/APT/sources. List ETC/APT/sources. list_backup

Modify: $ sudo gedit
/Etc/APT/sources. List

(Open Sources. List with gedit)

22. Check the Linux system version and kernel version.

1) view the kernel

CAT/proc/version

Uname-

Uname-R

2) view the Linux version

Lsb_release-

CAT/etc/issue

3) log on to Linux and run CAT/etc/RedHat-release, for example:

[Root @ q1test01 ~] # Cat/etc/RedHat-release

Red Hat Enterprise Linux as Release 4 (nahant Update 2)

Note: In this mode, you can see the specific version number, such as as4 update 1.

4) log on to Linux and execute rpm-Q RedHat-release, for example:

[Root @ q1test01 ~] # Rpm-Q RedHat-release

Redhat-release-4AS-3

23. Use commands on the terminal to view the number of files in a folder

Ls | WC

24. Shortcut Keys for switching to a command-only terminal (called the virtual console)

CTRL + ALT + F1-F7, where the F1-F6 is 6 pure command terminals, F7 is X Window (I .e. graphical interface), 6 pure command terminals called: tty1, tty2, until tty6, tty, I checked it online. It is the abbreviation of teletype. teletype is the meaning of teletype.

25. Search for the process ID of a process

PS-Ef | grep httpd (httpd is the process name)
Netstat-ant (find the port number)

26. Ubuntu Method

1) full screen screenshotDirectly press the pirntscreen key on the diskThen, you can drag the left mouse button to select the screenshot area, drag the left mouse button to open the dialog box, you can choose to copy to the clipboard or save the image.

2) area screenshotsShift and then pressPirntscreen keyThen, you can drag the left mouse button to select the screenshot area, drag the left mouse button to open the dialog box, you can choose to copy to the clipboard or save the image.

27. view disk capacity usage
DF-H (Capacity Calculation carry 1024) or DF-Hi
DF-H (capacity Computing Unit: 1000)

Note: DF is short for Disk Free.

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.