Linux---Common commands (i)

Source: Internet
Author: User
Tags bz2 clear screen create directory gz file parent directory disk usage

Common command file and directory operations
Command parsing
Cd/home Enter '/home ' directory
Cd.. Return to the top level directory
Cd.. /.. Return to the top level two directory
CD- Returns the last directory in which
CP file1 File2 Copy File1 to File2
Cp-a Dir1 Dir2 Copy a directory
Cp-a/tmp/dir1. Copy a directory to the current working directory (. Represents the current directory)
Ls Viewing files in a directory
Ls-a Show hidden files
Ls-l Show more information
Ls-lrt Show files by Time (l for detailed list, R for reverse sort, t for time sorting)
Pwd Show work Path
mkdir Dir1 Create ' dir1 ' directory
mkdir Dir1 Dir2 Create two directories at a time
Mkdir-p/tmp/dir1/dir2 Create a directory tree
MV Dir1 Dir2 Move/Rename a directory
Rm-f file1 Delete ' File1 '
RM-RF Dir1 Delete ' Dir1 ' directory and its subdirectory contents
View File Contents
Command parsing
Cat File1 Forward viewing the contents of a file starting from the first byte
Head-2 file1 View the first two lines of a file
More File1 View the contents of a long file
TAC File1 Reverse view the contents of a file starting from the last line
Tail-3 file1 View the last three lines of a file
VI File Open and browse files
Text content Processing
Command parsing
grep str/tmp/test Find "str" in file '/tmp/test '
grep ^str/tmp/test Find lines starting with "str" in file '/tmp/test '
grep [0-9]/tmp/test Find all rows in the '/tmp/test ' file that contain numbers
grep str-r/tmp/* Find "str" in directory '/TMP ' and its subdirectories
diff File1 File2 Find out where two files differ
Sdiff file1 file2 Shows the difference of two files in a contrasting way
VI File
Operation parsing
I Enter edit text mode
Esc Exit Edit Text Mode
: W Save current changes
: Q Do not save Exit VI
: Wq Save current changes and Exit VI
Query operations
command parsing
Find/-name File1 Go to root file system to find files and directories from '/'
Find/-user User1 Find files and directories belonging to user ' User1 '
Find/home/user1-name *.bin Find files that end with '. bin ' in directory '/Home/user1 '
Find/usr/bin-type F-atime +100 Find execution files that have not been used in the last 100 days
Find/usr/bin-type f-mtime-10 Find files that have been created or modified within 10 days
Locate *.ps To find files ending with '. ps ', run the ' updatedb ' command first
Find-name ' *. [CH] ' | Xargs grep-e ' expr ' Find ' expr ' in all. C and. h files in the current directory and its subdirectories
Find-type f-print0 | Xargs-r0 grep-f ' expr ' Find ' expr ' in the general file of the current directory and its subdirectories
Find-maxdepth 1-type F | Xargs grep-f ' expr ' Find ' expr ' in the current directory
Compression, decompression
Command parsing
bzip2 file1 Compression file1
BUNZIP2 file1.bz2 Decompression file1.bz2
Gzip File1 Compression file1
Gzip-9 file1 Maximum compression file1
Gunzip file1.gz Decompression file1.gz
TAR-CVF Archive.tar File1 Pack the File1 into Archive.tar (-C: Create compressed archives;-V: Show all processes;-F: Use the file name, is required, is the last parameter)
TAR-CVF Archive.tar file1 Dir1 Pack the File1,dir1 into a Archive.tar
TAR-TF Archive.tar Display the contents of a package
TAR-XVF Archive.tar Release a Package
TAR-XVF ARCHIVE.TAR-C/tmp Release the package to the/tmp directory
Zip File1.zip file1 Create a zipped package in zip format
Zip-r file1.zip file1 Dir1 Compress files and directories into a zip-format package
Unzip File1.zip Unzip a zip-format package to the current directory
Unzip test.zip-d/tmp/ Unzip a zip-format package into the/tmp directory
Yum Installer /tr>
command resolution
yum-y Insta ll [Package] download and install an RPM pack
yum localinstall [package.rpm] Install a RPM package and use your own software warehouse to resolve all dependencies
yum-y update updates the current system installed RPM Packages
yum Update [package] update one RPM package
Yum R emove [Package] Delete an RPM package
yum list List the current system All packages Installed
yum Search [package] search for packages in RPM warehouse
Yum clean [package] Clear Cache directory (/var/cache/yum) packages
yum Clean headers Delete all header files
yum clean all Delete all cached packages and header files
Network-related
Command parsing
Ifconfig eth0 Show the configuration of an Ethernet card
Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Configure the IP address of the network card
Ifdown eth0 Disabling ' eth0 ' network devices
Ifup eth0 Enable ' eth0 ' network devices
Iwconfig eth1 Show the configuration of a wireless network card
Iwlist Scan Show Wireless network
IP addr Show Displays the IP address of the network card
System-related
command resolution
Su- Switch to root privileges (differs from SU)
shutdown-h now shut down
shutdown-r now restart
top
pstree
man ping View reference manuals (such as ping commands)
passwd change password
df-h
cal-3
Cal 1988
date–date ' 1970-01-01 UTC 1427888888 seconds ' Convert a number of seconds relative to 1970-01-01 00:00 to time
Xsheel 5 Related Actions form shortcut keys
Command parsing
Ctrl + u Delete the character before the cursor to the beginning of the line
Ctrl + K Delete the character before the cursor to the end of the line
Ctrl + C Cancels the current line Input command, which is equivalent to CTRL + BREAK
Ctrl + A The cursor moves to the beginning (ahead of line), which is equivalent to the usual home key
Ctrl + E Cursor moves to end of line
Ctrl + F Move the cursor forward (forward) one character position
Ctrl + b Move the cursor back (backward) one character position
Ctrl + L Clear screen, equivalent to executing the clear command
Ctrl + R Show: hint, find relevant historical commands according to user input (Reverse-i-search)
Ctrl + W Remove from the beginning of the cursor position until the current word (word)
Ctrl + t Two characters before the swap cursor position
Ctrl + y Paste the last word that was deleted
Ctrl + Alt + D Show Desktop
Alt + b Move the cursor back (backward) to the previous word
Alt + D Delete from the cursor position to the end of the current word
Alt + F2 Run
Alt + F4 Close the current window
Alt + F9 Minimize the current window
Alt + F10 Maximize Current Window
Alt + Tab Toggle Window
Alt + Left button Move the window (or scroll the mouse wheel in the bottom task bar)

Introduction to Linux and Ubuntu Installation

Linux, free open source, multi-user multitasking system. Linux is based on multiple versions of the derivative. RedHat, Ubuntu, Debian

Install a VMware or VirtualBox virtual machine. Specific installation procedures, to find Baidu.

Install Ubuntu again. Specific installation procedures, to find Baidu.

After installation, you can see the directory structure of the Linux system, see link http://www.cnblogs.com/laov/p/3409875.html

Common directives

LS Display file or directory

-l list File details L (list)

-a lists all files and directories under the current directory, including Hidden A (all)

mkdir Creating a Directory

-P Create directory, if no parent directory, create p (parent)

CD Switch Directory

Touch creates an empty file

Echo creates a file with content.

Cat View File Contents

CP Copy

MV Move or rename

RM Delete File

-R Recursive Delete, can delete subdirectories and files

-F Force Delete

Find searches a file system for a file

WC statistics Text line number, word count, number of characters

Grep finds a string in a text file

RmDir Delete Empty Directory

Tree structure display directory, need to install tree package

PWD Displays the current directory

LN creates a linked file

More, less pagination displays text file contents

Head, tail display file header, tail content

CTRL+ALT+F1 command line full-screen mode

System administration Commands

Stat Displays details of the specified file, more detailed than LS

Who shows online login

WHOAMI Show current Operation user

Hostname Display host name

Uname Display System Information

Top dynamic display currently consumes the most resources process information

PS Display transient process status Ps-aux

Du view directory size Du-h/home with units display directory information

DF View disk size df-h with unit display disk information

Ifconfig Viewing network conditions

Ping Test network connectivity

Netstat Displaying network status information

Man command won't work, find men like: Guy ls

Clear Clear Screen

Alias renamed the Command as: Alias showmeit= "Ps-aux", in addition to de-use Unaliax Showmeit

Kill kills the process, you can first view the process ID with the PS or Top command, and then kill the process with the kill command.

Packaging compression-related commands

Gzip:

BZIP2:

Tar: Packaging compression

-C Archive File

-X Compressed file

-Z gzip Compressed file

-j bzip2 Compressed Files

-V shows the compression or decompression process V (view)

-F Use file name

Cases:

TAR-CVF/HOME/ABC.TAR/HOME/ABC only packaged, not compressed

TAR-ZCVF/HOME/ABC.TAR.GZ/HOME/ABC packaged and compressed with gzip

TAR-JCVF/HOME/ABC.TAR.BZ2/HOME/ABC packaged and compressed with bzip2

Of course, if you want to decompress, just replace the above command TAR-CVF/TAR-ZCVF/TAR-JCVF "C" in the "X".

Shut down/Restart the machine

Shutdown

-R shutdown Restart

-H shutdown does not restart

Now turn the machine off.

Halt shut down the machine

Reboot restart

Linux Pipelines

Use the standard output of one command as the standard input for another command. That is, the combination of several commands to use, the latter command in addition to the results of a previous command.

Example: Grep-r "Close"/home/* | More in the home directory to find all files, including close files, and paging output.

Linux Package Management

dpkg (Debian package) management tool with a. deb suffix. This approach is suitable for systems that are not networked.

For example, install the tree command installation package, first upload tree.deb to the Linux system. Then install it using the command below.

sudo dpkg-i tree_1.5.3-1_i386.deb installation software

sudo dpkg-r tree Uninstall software

Note: There are several ways to upload tree.deb to a Linux system. Vmwaretool, use of Mount mode, use of WINSCP tools, etc.;

APTAdvanced Packaging tool. This method is suitable for the system to be able to connect the internet situation.

Still take tree as an example

sudo apt-get install tree

sudo apt-get remove tree unload tree

sudo apt-get update software

sudo apt-get upgrade

Convert the.rpm file to. Deb file

. RPM is the software format used by Redhat. cannot be used directly under Ubuntu, so you need to convert it.

sudo alien abc.rpm

Vim use

Vim three modes: Command mode, insert mode, edit mode. Use ESC or I or: to toggle the mode.

Command mode:

: Q exit

: q! Force exit

: Wq Save and exit

: Set number Displays line numbers

: Set Nonumber hidden line number

/apache find Apache in the document press N to jump to the next, Shift+n previous

YYP Copy the cursor line, and paste

H (move left one character ←), J (next line ↓), K (previous line ↑), L (move right one character →)

User and User group management

/etc/passwd Storing user accounts

/etc/group Storage Group Account

/etc/shadow Store password for user account

/etc/gshadow Password to store user group account

Useradd User Name

Userdel User Name

AddUser User Name

Groupadd Group Name

Groupdel Group Name

passwd root sets the password for root

Su Root

Su-root

/etc/profile System Environment variables

Bash_profile User Environment variables

. BASHRC User Environment variables

SU user switches the user and loads the configuration file. bashrc

Su-user switch User, load configuration file/etc/profile, load Bash_profile

User and user groups for changing files

sudo chown [-r] Owner[:group] {file| Directory}

For example: Also take jdk-7u21-linux-i586.tar.gz as an example. belongs to user Hadoop, group Hadoop

You want to switch the users and groups to which this file belongs. You can use commands.

sudo chown root:root jdk-7u21-linux-i586.tar.gz

File Rights Management

Three basic permissions

R read value represented as 4

The W write value is represented as 2

X executable value represented as 1

, the permissions for the jdk-7u21-linux-i586.tar.gz file are-rw-rw-r--

-rw-rw-r--altogether 10 characters, divided into four segments.

The first character "-" indicates a normal file, and the "L" link may also appear in this location; "D" means the directory

The No. 234 character "rw-" represents the permissions of the currently owned user. So the value is expressed as 4+2=6

The No. 567 character "rw-" represents the permissions for the group that is currently owned. So the value is expressed as 4+2=6

The No. 890 character "r--" represents other user rights. So the value is represented as 2

So the permission to manipulate this file is represented by a value of 662

Change permissions

sudo chmod [u belongs to user g belongs to group O Other User a All users] [+ Increase permissions-reduce permissions] [r W x] directory name

For example: There is a file filename, the permission is "-rw-r----x", the permission value is changed to "-rwxrw-r-x", with a numeric representation of 765

sudo chmod u+x g+w o+r filename

The above example can be represented by a numerical value

sudo chmod 765 filename

Linux---Common commands (i)

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.