Linux Common Simple commands

Source: Internet
Author: User
Tags clear screen save file disk usage

Remember to keep up to date when installing VMware, reinstall VMware Tools, and follow the instructions below the virtual machine. Install additional software in the Ubantu system, the software format is. Deb, take sublime-text-3 as an example, copy and paste directly from Windows into/OPT, and enter sudo dpkg-i/opt/sublime-text-3.deb in the terminal. (Terminal in the application market, when sublime installed successfully, in the terminal input SUBL open)

today's requirement: Learn about Linux and related files, system instructions.

First, Linux

Linux, Winsows, Mac, Android, iOS are the operating systems you know today, and they act as a link between devices and applications. Linux and Windows, just as the current market in the personal desktop this Windows everyone contact, but on the server side, Linux is more prominent, it is free, efficient, stable and so on. And it is widely used in the field of embedded.

Second, the order

2.1 Files and directories

Home directory for/home/user or ~

The catalog is divided into two categories:

Absolute directory, starting from the root directory

Relative directory: Start writing relative to the current location

Format of the 2.1.1 command

command [-options] [Parameter1][parameter2] ...

Command: Order name, equivalent to do;

Options: The option, which is equivalent to how, the command is regulated, sometimes several can be used simultaneously, in most cases no order (currently known as Packing-F must be placed at the end); sometimes it can be omitted.

Parameter: The object of the command.

Notes: View the location of the command: which command

Auto-complete commands press the TAB key

The UP and DOWN ARROW keys can quickly switch to the previously entered command, enter history to see all input commands directly (history | More split screen, Q key exit)

Exit General Press Q key, invalid case press CTRL + C key, CTRL + Z is the process temporarily suspended, FG run again, BG background run.

Help for the 2.1.2 command

There are two ways to help when you have a problem with the command. (Take LS as an example)

    • --help: ls--help
    • Man:man 1 ls

The man manual is divided into 8 categories, the first of which is a standard command, and if you do not enter a category, it is searched in 1-8 order.

B key Previous page, space next page, H key manual guide, q key exit. (Man ls | More split-screen display ls--help | More

2.2 File Management commands

2.2.1 Switch working directory CD

The catalog is divided into two categories: The absolute directory starting with the/root directory and the relative directory starting from the./Current directory

CD ~ Direct Switch Home directory/home/user/

CD. (CD./) directory unchanged

Cd.. (CD..) /) switch to the previous layer Mulu

CD-Switch to the previous level directory location

The CD can be directly followed by the absolute directory and relative directory

Show current path pwd; Clear screen Clear (shortcut key ctrl+l)

2.2.2 Viewing the file directory in the current directory LS

Ls-a also displays hidden files in the current directory

The ls-l is displayed as a list showing the details of the file (including permissions, number of hard links, last modification time, file name, and so on).

Ls-lh displayed as a list of additional file sizes (-H not used separately)

Wildcard: * Can be substituted for more than one character, which is a character, the escape character \ Makes *,? invalid, invalid when *,? is placed within [], and also fails when placed outside [].

To view the file name starting with a: LS A *

To view the file name at the end of the. PY: LS *.py

View filename named *a.py: LS \*a.py

Also: LS a?. Py;ls A[abcd].py;ls a[a-z].py

2.2.3 REDIRECT Instructions

Both LS and cat can,> the contents of the file before re-entering it. >> do not clear, add "cat [filename] At the end of the file content to view the contents of the file"

ls a.py > b.py (cat a.py > b.py) or ls a.py >> b.py (cat a.py >> b.py)

The difference between LS and cat redirection: There is no dividing line between the contents of the file in the new file for LS redirection; In a new document with cat redirection, there is an empty row between each of the two documents.

2.2.4 Pipe and split screen display

|: pipe, use | To separate commands, you can enter n commands at a time (it is possible to create a delete file, and then switch directories to fail).

MORE: Split screen display, General and | shared. (can also be more file name)

2.2.5 Creating directories and deleting directories

To create a directory:

Create a first-level directory and enter the MkDir folder name directly

Create multi-level catalogs, add option-p, such as: Mkdi-p folder name/folder name/folder name/.... (-P is available before and after folder name)

To delete a directory:

RmDir folder name (must be an empty folder)

2.2.6 copy file cp and mobile file MV

Copy files: sudo cp [-options] Original file directory and file name copy files directory and filename (in the same directory without sudo and write file name, the current path is the path of the file can also be omitted)

Option: The file attribute is unchanged when copy-a

-V Copy Progress

-R Copy Folder

-F Copy no longer reminds you of duplicate file name

Move files: sudo mv [-options] Original file directory and file name copy files directory and its file name (in the same directory without sudo and write file name, the current path is the path of the file can also be omitted)

Option:-F does not alert when moving

-I Reminders

-V Show Move Progress

NOTES:MV filename 1 File name 2 Rename file 1 to filename 2

2.2.7 Creating and deleting files

Create:

Touch: Create a file, for example: Touch txet.py

Gedit: Create new Edit Save file, for example: Gedit text.py

Delete: RM: Delete file, for example: RM a.py;

-I: Delete each, confirm each; (yes or y)

-R: the-r option must be added for the folder;

-F: Delete files that do not exist, without prompting.

2.2.8 creating a linked file: ln

ln soft-link files resemble Windows shortcuts, hard links are similar to copy-and-paste, and only files can be linked.

Cross-catalog words suggested by: sudo ln [-s]/original file location//Link Location/

2.2.9 finding a file Find Find/directory to find/[-options] ' string '

Find/directories to look for/-name file name

Find/directories to look for/-name ' *.py '

Find/directories to look for/-name "[a-z]*" (file name this block is not distinguished by a double parenthesis and a single parenthesis)

Find/directories to look for/-size +4k-size-2m

Find/directories to look for/-perm 777 (or 0777, few zeros matter)

2.2.10 Text Search grep grep [-options] ' string '

Option:-V lines other than the input string

-N Display number of rows

-I search is case insensitive

Wildcard characters:

Grep-n ' ^a ' file name searches for a line that begins with a

Grep-n '. py$ ' file name searches the file for. Py End Line

grep-n [ll]ik[ee] File name searches for a line in a file like, like, like, like

The grep-n ' e.e ' file name (. Represents any one by one characters) searches the file for a three-character string that is in the same line as the middle character of the string.

2.2.11 Archive Package Tar tar [-options] package name. Tar is packaged file name 1 is packaged file name 2 ... (-F cannot be saved)

Option:-C Package

-X Unpacking

-V Show Progress

-f Specifies the packaged file name, which must be placed at the last option followed by the package name. Tar

-T lists the items in the package (TAR-TF package name. Tar)

2.2.12 File Compression Decompression

    • Tar-z (-j) compression command: The ZIP package name can be: Name tar.gz, or TAR.GZ2, or name. tar.bz, or name. tar.bz2

Compression: TAR-CVZF Package Name Compressed package Name 1 Compressed package Name 2 ...

Decompression: Tar-xvzf Compressed package name (unzip to the specified directory, add-c/directory after the ZIP package name)

    • Gzip Compression command:

Compression: gzip [-r] Compress package name. Tar

Decompression: gzip-d compression package name. tar.gz

    • Zip/unzip

Compression: Zip [-r] Package name (. zip) Compressed Package Name 1 Compressed package Name 2 ...

Unzip: unzip-d the Directory compressed package name after decompression. zip

2.3 Linux Commands-user, rights management

User is an important part of unix/linux system, user management includes user and group account management. In the Unix/linux system, either by the local or remote login system, each system must have an account, and for different system resources have different use rights. The root account in the Unix/linux system is typically used for system maintenance and management, and it has unrestricted access to all parts of the Unix/linux operating system. In the Unix/linux installation process, many user accounts are created automatically, and these default users are called "Standard users". In most versions of Unix/linux, it is not recommended to log into the system directly using the root account.

Exit: Exit terminal (open with ctrl+alt+t)

WHOAMI: View the current user's identity (view system user information: CAT/ETC/PASSWD)

Who: View user information for all currently logged in systems

Options:

-Q (--count) shows only the number of user names and users logged in

-U Displays the time interval that the user last action to now

--heading Display column headings

Switch User: Su

sudo su [-] User (no user means switch to root user)

-: Indicates that the directory also switches to the new user home directory after switching users

None-: Only the user is switched, the directory is not changed

Note: If you have an Ubuntu platform, you need to add "sudo" before the command, and if you need an administrator to operate on some operations, Ubuntu does not need to switch to the root user to operate, just add "sudo". sudo is a tool under the Ubuntu platform that allows the system administrator to let ordinary users perform some or all of the root commands, reducing the login and administration time of the root user and improving security.

Add, delete user group accounts Groupadd, Groupdel (View system Users group: Cat/etc/group)

Add: sudo groupadd group account

Delete: sudo groupdel group account

Modify User Group Usermod

USERMOD-G Group account user name

Add user account: Useradd USERSDD [-Options] User account

Option:-G Specify group name

-M Automatic Directory creation

-D actively establish the home directory, otherwise the home directory will be automatically created with the same name as the user name of the home directory

Notes: Linux users must have a home directory, usually in the/home directory, the user's main directory and user name are generally the same.

Delete user account: Userdel

Userdel [-r] User name

-R Indicates whether to delete the user's home directory while deleting it

Set User password: passwd passwd user Name

Modify file Permissions: chmod

    • First: Alphabetic method chmod u/g/o/a +/-/= rwx file name

U:user, user, G:group, user group, o:others, other user group, A:all, all users.

+: Add permission;-: Remove Permissions, =: Re-grant permissions.

R:read, with permission to browse, such as browse the contents of the directory, W:write, with edit permissions, such as: Create a new file, X:execute, with permissions to run, such as: Switch permissions to the directory.

    • The second type: Digital method chmod 777 file name

R=4,W=2,X=1,-=0,RWX the location permission corresponds to the number added. such as: rwxrw-r--corresponds to a number of 764;rwx------corresponding number is 700.

Note: If you want to recursively add the same permissions to all directories, you need to add the parameter "-R". Example: chmod 777 test/-R All files in the recursive test directory plus 777 permissions (-R position can be before)

Modify file Owner: Chown chown User name file

Modify file belongs to group: chgrp chgrp user Group file

2.4 System Management

Cal: View calendar-y view calendar year-round

Date: Display time

Format time: sudo date mmhhmmccyy.ss (mm month, hh hour, MM min, cc year top two, yy year two, ss sec)

PS: View process information PS [-]options

Option:-A displays all processes on the terminal

-X shows no control of the terminal process

-R Show Running processes

-U display Process details

Kill: End Process Kill [-signal] PID (PID via PS view, signal value from 0 to 15, where 9 is absolute termination, can handle the process of general signal cannot terminate.) )

Top: Dynamic Display process-d specifies the time interval, in units: s

M key: Sort by memory share

P Key: Sort by CPU share

T key: Sort by run time

U key: Enter user name filter process, enter; exit: Ctrl + C

K Key: Input PID to end process, enter, exit: Ctrl + C

H Key: Help

Q Key: Exit

Reboot: Reboot (equivalent to init 6)

Shutdown-r Now: Restart and notify other users

Shutdown-h now: Shutdown (equivalent to init 0)

Shutdown-h time: Power-off at times

Shutdown-h Auto Power off after +time:time time

DF: Check the disk footprint and availability of the file system (DF: Show only non-empty cases)

Option:-T: Displays the type of file system

-T file system: Displays disk occupancy and availability for the specified file system

-M: Displayed in 1024-byte units

-A: Displays disk usage for all file systems

Du: Statistics directory or file size for disk space

Options:-A directory: recursively displays the size of the files in each file and subdirectories in the specified directory for disk space

-S directory: Displays the size of the specified file or directory for the disk (-a detailed description,-s only counts the overall size)

-B: Displays the size of the disk in bytes

-L: Calculates all file sizes, including hard links

Network card information: View network card information: ifconfig

Change Ip:sudo ifconfig network card Code new IP (network card code: ENS33, eth0, etc.)

Test remote host Connectivity: Ping (the case of running has been connected)

Ping ip address (URL)

Linux Common Simple commands

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.