Common Commands (Ubuntu)

Source: Internet
Author: User
Tags access properties bz2 clear screen unpack uncompress

1. How to open the terminal

Ubuntu in the left column of the first "Panel home page (you can press the win key to recall), in the input terminal can open the terminal, in addition to open the Terminal shortcut key is Ctrl+alt+t

2. Modify user password

Enter the passwd in the terminal, enter the new password, return, enter the new password again, return, fix. Note that the Linux input password will not be displayed with the * number, so be careful not to lose the wrong.

3. How to access root (Super Administrator) permissions

1) If it is a rethat system, it will enter the root super administrator directly after booting, if the user is not root, enter SU in the terminal, return, enter the root user.

2) If it is an Ubuntu system, after booting into a normal user, you need to set the root password in the terminal, the method is sudo passwd root, enter, and then prompt for the password, entered after entering, will prompt to enter the password again to confirm. After confirming the password, enter to complete the root password setting. Then just like Rethat, in the terminal input Su, enter, prompt for root password, enter the password just set, you can go in.

Note: sudo is an abbreviation for superuser do

4. loading and unloading software , update command

installation software: sudo apt-get install < Package name >

If installing SCIM Input method: sudo apt-get install SCIM

Uninstall software: sudo apt-get remove < package name >

Uninstall the Scim Input method you just installed: sudo apt-get remove Scim

If there is an association to uninstall, it is automatically prompted with sudo apt-get autoremove to come clean.

Upgrade: sudo apt-get update

Example: Upgrade VI with "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)

Logoff: Logout (only available in pure command mode shell)

Exit Terminal: Exit

Clear screen: Clear

6. using the VI editor (to write programs, text, etc. ), there is also a vim compiler, which is an upgraded version of VI.

VI has three modes: command-line mode, insert mode, and bottom-line mode. But there are also command-line patterns and bottom-line patterns grouped together, that is, divided into two modes, one is the command line mode, and the other is the insertion mode.

1) Enter VI filename.suffixname (such as VI first.c or VI second.cpp) in the terminal to confirm that it is equivalent to creating a new Notepad file but not yet saved. (Note that this is the command-line mode, the character cannot be entered)

2) Press I to enter insert mode (to enter the insertion mode before entering a character) and then enter the program.

3) Press ESC to exit Insert mode (enter command line mode for copying, pasting, deleting characters, etc.)

4) in command-line mode, enter the colon ":" to exit the command line mode into the bottom row mode (the cursor is located in the bottom row of the screen, the user can save or exit the file, etc.).

5) Press W in the bottom row mode to save, Q exit, q! Forced exit does not save, X exits and saves, generally can be directly entered Wq, enter, so save and exit.

6) then use LS (i.e. list, also use dir) command to view the current folder file, with Ls–l to view the file details.

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

Method: ①GCC filename.c (or gcc fileName.cpp) is named after the compiled file by default a.out

②GCC Filename.c–o Filename.out, so 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, such as the previously written C program has errors to modify, you can enter on the terminal

VI filename.c (or VI fileName.cpp), you can enter the editor.

9) Modify file name: MV Oldname NewName (note to the terminal interface, not the command screen in VI)

10) Run the Filename.out file directly with "./filename.out", that is, after the ". C" file is compiled with the GCC compiler to ". Out", when the ". Out" file is executed, simply precede the filename with "./".

Note: GCC ( GNU Compiler Collection )

VI Delete and modify the file commands (note in edit mode instead of insert mode):

x: Deletes the character of the cursor.

DD: Deletes the column where the cursor is located.

R: Modifies the character of the cursor, and R is followed by the characters to be corrected.

R: Enter the replace state and the new text will overwrite the original text until you press [ESC] back to instruction mode.

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

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

7. Copy move Delete file

1) Copy

CP [ options] source file or directory destination file or directory

The options are as follows:

-A This option is typically used when copying a directory. It retains links, file attributes, and recursively copies the directory, which is equal to the combination of the DPR option.

-Keep links when copying D.

-F Delete a target file that already exists without prompting.

-I and F options, in contrast, will prompt the user for confirmation before overwriting the target file. Answer y when the target file will be overwritten, is an interactive copy.

-P At this point, the CP will also copy the modified time and access rights to the new file in addition to the contents of the source file.

-R If the source file is a directory file, the CP will recursively replicate all subdirectories and files in that directory. The destination file must be a directory name at this time.

-L do not make copies, just link files.

2 Delete (with RM delete recoverable, unrecoverable with shred)

RM [ Options] file

-F Ignore nonexistent files and never give hints.

-R instructs RM to delete all directories and subdirectories listed in the parameter recursively.

-I do an interactive delete.

3) Move (and rename)

mv [ options] source file or directory destination file or directory

When the target is a file, the source file is renamed to the target file name, if the target is a directory, the source file or directory is moved to the target directory.

8. Show your current directory

PWD (present which dirctory)

9. Add Users

Useradd user_name
AddUser user_name

Change Password

passwd user_name (if you do not write user_name, then you set the password for the current user)

One by one . Create a table of contents

mkdir [option] [Dir_name]

Option:-P: Make sure the user exists and does not exist to create a

-M: Set access permissions on the new directory

Modify the file directory owner
Chown (change owner )

Mkdir-p/home/user_name (P is the meaning of path)

Chown User_name:usrgp_name/home/newuser (Note that there is a space in front of the home/and previous name, otherwise an error will occur)

Delete a user

Userdel User_name (only delete the user, do not delete the user files, that is, user_name this file is still in, but can not be logged in with this user name)

If you use Userdel–r user_name, the user files and user directories (the directory containing the user files) will be deleted.

If you are adding users with AddUser, use deluser user_name to delete them.

14.Linux View the user group information below

Groups viewing group information for the currently logged in user

Groups user_name View the group that the user_name user is in, and the members in the group

WHOAMI View the currently logged in user name

WHO displays user information for directory login system

Whois user_name Find and display user information

W Display user information currently logged into the system

Finger querying users ' information

15.Linux Operating level (total 7 levels)

Command: init [0123456]

0 Turn off the machine

1 Single User

2 Multi-user status No NETWORK service

3 multi-user status with network service

4 system not used reserved to user

5 graphical interface

6 System restart

Modify the default run level to modify the file:

Id:5:initdefault in/etc/inittab: The number in this line, such as changing 5 to 1.

16. Modify the user name

Use VI to edit the root directory below the/etc/passwd, in the last line to change the user name on the line, modified after Wq save after the exit with reboot restart on it (first to use Su to root permissions)

The "GNU grub" abbreviation "GRUB" is the abbreviation for Grand Unified bootloader, which is a multi-os boot manager. Used to guide different systems, such as Windows,linux.

17. Compression decompression (Package unpacking)

Compress Packaging related commands

Command

Command meaning

Format

Bzip2

Compressed (or decompressed) programs for. bz2 files

bzip2 [option] filename

Bunzip2

. bz2 File Decompression Program

BUNZIP2 [option] filename.bz2

Bzip2recover

Repairing a damaged. bzw file

bzip2recover.bz2 Compressed Files

Gzip

Compression program for. gz files

gzip [option] filename

Gunzip

Unzip a file that was compressed by gzip

gunzip [option] filename.gz

Unzip

Unzip A. zip file of WinZip compression

Unzip [option] Filename.zip

Compress

The early compression or decompression program (after compressing the file name. Z)

compress [option] filename

Tar

To package or unpack a file or directory

tar [option] [filename] List of file

1) Gzip: Compress and decompress files, and gzip automatically identify compression or decompression based on file type.

Format:gzip [optional] filename

gzip parameter list

Parameters

Parameter meaning

-C

Writes the output information to the standard output and retains the original file

-D

Unzip the compressed file

-L

For each compressed file, the following fields are displayed: Compressed size, pre-compression size, compression ratio, pre-compression file name

-R

Find the specified directory and compress or unzip all files in it

-T

Test, check that the compressed file is complete

-V

For each compression and decompression file, the display file name and compression ratio

2) Tar: Package or unpack the file directory.

Tar command common parameter list

Options

Parameter meaning

-C

Create a new package file

-R

Append files to the end of a packaged file

-X

Extracting files from a packaged file

-O

Unpack the file to standard output

-V

Output related information during processing

-F

Working with normal files

Z

Call gzip to compress the packaged files, and call gzip to complete the decompression when associated with-X

-j

Call bzip2 to compress a packaged file, call bzip2 to complete the decompression when associated with-X

-Z

Call compress to compress a packaged file, call compress to complete the decompression when associated with-X

Cases:

TAR-CVF A.tar A to create a tar package for file a

TAR-TVF A.tar View the files contained in the TAR package

TAR-XVF A.tar Release the tar package file

TAR-RVF A.tar B append file B to tar package A.tar

TAR-AVF A.tar C.tar Append C.tar package to A.tar pack

TAR-ZCVF a.tar.gz A Create a gzip compressed tar package for file a

TAR-ZTVF a.tar.gz View the contents of the TAR package for file a

TAR-ZXVF aa.tar.gz Release the contents of the aa.tar.gz package

TAR-JCVF aa.tar.bz2 AA Creates a bZIP compressed tar package for file a

TAR-JTVF aa.tar.bz2 View the contents of the TAR package for file a

TAR-JXVF AA.TAR.BZ2 releases the AA.TAR.BZ2 package inside

Linux Common compression decompression command list

File suffix

Unzip command

Example

. A

Tar XV

Tar XV hello.a

. 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

Decompression: Rpm2cpio

Decompression: Dpkg-i Hello.deb

. deb

Installation: Dpkg-i

Installation: Dpkg-i Hello.deb

Decompression: Dpkg-deb--fsys-tarfile

Decompression: Dpkg-deb--fsys-tarhello hello.deb

. zip

Unzip

Unzip Hello.zip

Note: The purpose of the TAR command is to package or unpack the file, noting that package unpacking differs from compression decompression.

Packaging: Turning some files or directories into a total file (turning many files into a single file).

Compression: A file that is large (note "one") becomes a small file through some compression algorithms.

Many compression programs in Linux such as (gzip) can only be compressed for one file, so when you want to compress more files, you need to use other tools to make these files into a package, and then compress the package with the compression program.

18, view, modify the file read and write permissions
Above example view file read and Write permissions: Ls-l xxx.xxx (xxx.xxx is the file name)

Modify file Read and Write permissions: chmod xxx ***.*** (where xxx is a three-digit number, ***.*** is the file name)

Example: chmod name.txt (indicates that the file owner has read, write, execute three kinds of permissions, and the file all groups, the system other users do not read, write, execute permissions), modify the middle of the three-digit number can modify different permissions.

Example:-rwx--r--

The previous example has a total of 10 characters,
The first note: Represents a file type, where the "-" in the example above represents an ordinary file, plus:
Catalog file (denoted by "D")
Link file (denoted by "L")
Character device (denoted by "C")
Block device (denoted by "B")
Named pipes (denoted by "P")
Stack file (denoted by "F")
Sockets (denoted by "s")
Each of the following 9 characters is divided into groups of 3 groups per 3
First group: File owner (u,user) permissions on a file
Second group: File permissions for all groups of files (G,group)
Group Three: System other users (O,other) permissions on files
In these three groups, the three characters of each group are expressed sequentially: Read, Write, execute
Each group of three characters can be represented by an octal number, the octal number is converted from a binary, method:
For example: rwx with binary 111, r--with 100,-w-with 010,--x with 001,---000, binary number 100,010,001, 000 with octal, respectively: 4, 2, 1, 0.
If the file is readable and writable, i.e. rwx, then rwx can be represented by the number 7 (i.e. 4+2+1), 4 can read r--(100), 2 can write-w-(010), 1 can execute--x (001).
r--
-w-
--x
Rwx
(r--+-w-+--x) =rwx
such as: chmod name.txt, means to modify the Name.txt this file access properties, 7,003 digits, the first bit represents the permissions of the file owner, the second represents the permissions of all the groups in the file, and the third represents the permissions of other users of the system. 7 that is 4+2+1 (that is, rwx), the file owner to name.txt This file has read, write, execute three permissions, and the second and third is 0,0 that is 0+0+0 (that is,---), the file all groups and other users of the system did not read, write to Name.txt, Execute permissions (this is, of course, just an example, in fact txt files cannot be executed)

19, restart X-windows (similar to the Windwos Explorer.exe) method

Default restart X-windows for alt+print+k in Ubuntu

20. Ubuntu Display Desktop shortcut keys
Ctrl+super+d (Super is the Windows key, which is the one between the CTRL and ALT keys)
Tip: Press and hold the Super key to display all the shortcuts, and the release disappears.

21. Set up Linux update sources

Backup first: $sudo cp/etc/apt/sources.list etc/apt/sources.list_backup

Modified: $sudo gedit/etc/apt/sources.list

(i.e. open sources.list with gedit)

22. View Linux system version and kernel version

1) View kernel

Cat/proc/version

Uname-a

Uname-r

2) View Linux version

Lsb_release-a

Cat/etc/issue

3) Log in to the Linux execution Cat/etc/redhat-release, as follows:

[Email protected] ~]# cat/etc/redhat-release

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

Note: The specific version number can be seen directly in this way, such as AS4 Update 1

4) Log in to the Linux execution Rpm-q redhat-release, for example as follows:

[Email protected] ~]# rpm-q redhat-release

Redhat-release-4as-3

23, in the terminal with the command to see the number of files in a folder

LS |WC

24. Switch the shortcut keys of the Pure command terminal (called Virtual Console)

Ctrl+alt+f1-f7, where F1-f6 is 6 pure command terminal, F7 is the X window (that is, the graphical interface), 6 pure command terminal called: Tty1,tty2, until Tty6,tty, I surf the internet, is the abbreviation of teletype, Teletype is the meaning of the telex typewriter.

25. Find the process number of a process

Ps-ef|grep httpd (httpd is the process name)
Netstat-ant (find port number)

26. Ubuntu method

1) Full Screen screenshot directly press the Pirntscreen key on the keyboard , and then you can press the left mouse button to drag the screen area, drag and drop the left button pop-up dialog box, you can choose to copy to the Clipboard or save the picture.
2) Local Area screenshot press Shift and then press the pirntscreen key , then you can press the left mouse button to drag the screen area, drag and drop the left button pop-up dialog box, you can choose to copy to the Clipboard or save the picture.

27. Check the capacity usage of HDD
Df-h (capacity calculation carry is 1024) or Df-hi
DF-H (capacity calculation Unit is 1000)

Note: DF is the abbreviation for disk free.

«prev: 10 most widely used Linux distributions

Common Commands (Ubuntu)

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.