Getting Started with Linux basics

Source: Internet
Author: User
Tags clear screen create directory disk usage yum repolist

Objective:
Recently installed the Linux system, so learn some of the most basic operations, here to write their own summary notes here.


1,v8:192.168.40.10
v1:192.168.40.11
Linux ip:192.168.40.128

2,linux is the difference between an operating system and Windows:
Linux: Graphical interface is simple, performance quickly, in the enterprise as a server to use.
Windows: Graphical interface is very cool, performance is relatively poor, public users.
Server for Windows: windows2003,windows2008,windows2012

The role of 3,linux:
As a server to use

Directory structure in 4,linux:
Bin: Storing binary executable files
Sbin: Store binary executable, only root to access
ETC: Storage System configuration file
USR: system resources used to store shares
Home: The root directory where the user files are stored
Root: Super User Directory
Dev: for storing device files
LIB: The shared libraries and kernel modules required to store and run programs in the file system
Mnt:mount installation point for system administrator to install temporary files
Boot: Store various files used for system boot
TMP: For storing various temporary files
var: used to store files that need to change data at run time (log logs)

5,network Connection:
Host-only: Local and remote Linux communication needs to use this
NAT: Multiple Linux systems communicate with each other

6, using SECURECRT

Linux commands:
Ifconfig: View IP
Service Network restart: restart
Command Category:
Internal command: Executes part of Shell parser, resides in Bash directory, executes fast, does not need to create child process
CD: Toggle Directory Change Directory
PWD: Show current working directory print working directory
Help: Helping

External command: A file program that is independent of the shell parser, performs slowly, and typically resides in bin/sbin/usr/sbin/such a directory, creating child threads when executed.
LS: Displays a list of files and directories
mkdir: Creating a Directory
CP: Copying Files or directories

Commands for manipulating files or directories:
Pwd
Touch: Create an empty file
Echo: Write file content: echo "AAA" >a.txt
mkdir: Creating a Directory
-P Parent Directory does not exist in case of a parent directory
CP: Copying Files or directories
-R: Recursive processing, copy the files under the specified directory with subdirectories
MV: Moving files or directories, renaming files or directories
RM: Deleting files
-R Delete all files in this directory at the same time
-F force Removal of files or directories
RmDir: Delete Empty directory
Cat: Display text file contents
More,less: Pagination Displays text file contents
Head,tail: View the contents of the beginning or end of the text.


To view the Help documentation:
Internal command: help+ command (Help CD)
External command: man+ command (man ls)

7, common commands
=========== Common Commands =============
One, directory and file commands
1, Directory Processing command: Mkdir,rm,ls,find,cd,mv,cp,pwd,chmod
2, Operation File command: touch,rm,find,cat,more,less
3, Compression/decompression command: Gzip,bzip2,tar
4. Other common commands: Head,tail,wc,in,mount

Second, the user Operation command
Useradd,userdel,usermod

Third, user Group Operations Command
Groupadd,groupdel,groupmod

Four, install the software command
yum,rpm

Five, Network command
Ping,ifconfig,netstat


===========================
echo "Welcome to Linux" > a.txt: Writing characters to A.txt
Cat A.txt: See what's in A.txt
Ctrl+l: Clear Screen
CTRL + Z: Exit (Use this key to exit writing when cat > file is written)
VI mode: After editing is complete, click ESC, and then if you want to save exit input: Wq, do not save exit input: q!
Click ESC, SHIFT + z + Z to exit and save
============ detailed ============
mkdir: Create directory (Touch a.txt: Create file)
mkdir dir: Creating a name called the Dir directory, creating a single directory
mkdir dir1 DIR2: Create multiple directories, Dir1, DIR2
mkdir dir{3..10}: Create Dir3 Dir4...dir10


Cp:copy replication
To copy a file:
CP a.txt b.txt: Copy a.txt and the copied file name is B.txt
CP a.txt dir: Copy the a.txt to the Dir folder
CP *.txt dir
Cp.. /*.txt. /DIR2: Copy all txt files from the previous level directory to the Dir2 folder in the previous directory
Cp.. /file*. Copy all file files to the current directory in the top level directory

To copy a directory:
Cp-r dir1 dir2: Copy the Dir1 directory to the DIR2 directory
Cp-r dir/* dir1/: Copy all files and directories in Dir to the Dir1 directory


MV: Directory Move (CUT)
To move a file:
MV File1 file2//If File2 does not exist, rename file1 to File2
MV File2 file1//File2 named File1, if there is content in File1, overwrite
MV dir/* dir1//to move all directories and files in dir to the Dir1 directory


To move a directory:
MV dir dir1//moving the dir directory to the Dir1 directory
MV Dir2 dir3 dir1//move Dir2 and Dir3 to Dir1


Rm:remove Delete
To delete a file:
RM a.txt//Delete a.txt
RM a.txt B.txt//delete a.txt B.txt
RM *txt//Delete all files with the file extension txt
RM-RF dir1/*//force delete all files and directories under Dir1

To delete a directory:
RM-RF dir1//Delete all files and directories under Dir1, F is mandatory to delete, do not need prompt


CD: Switch directories
Cd.. Skip to top level directory
CD ~//Jump to root directory
Cd/usr/local//Jump to the local directory under USR


PWD: Displays the current directory


Touch: Create a file
Syntax: Touch filename

Touch myfile1//creates a single file with a file name of Myfile1
Touch myfile2 myfile3//Create two files at a time
Touch myfile{1..10}//Create multiple files

Cat
Function 1: Query the contents of the file, query all the contents of the file (if the file is too large, will die)
Cat filename//Viewing file name filename filename contents

Feature 2: Can create files and write content
Cat > Myfile10

Feature 3: Merging files, merging content
Cat Myfile1 myfile2 > myfile10//merge content from Myfile1 and myfile2 into Myfile10, content in Myfile10 is overwritten

More: View files, can be paged view
+n starting from the first few lines
-n defines how many lines are displayed on the screen

More myfile//Page view MyFile file
More +3 myfile//start with the third line view MyFile file
More-2 myfile//show two lines per page
More +/pattern myfile//search pattern from myfile, results are displayed in the third row


Less: Viewing files, paging up and down pages


Head: View files, pagination display, only 10 per page
Head myfile//default only 10 per page
Head-n 5 myfile//View Myfile1, 5 records per page
Head-c myfile//View myfile, show only the preceding 12-byte characters


Tail: View files, real-time monitoring files
Tail-f myfile//Real-time monitoring of myfile file changes

Which: Find command
which command
which mv//the alias of the MV Command and the location of the MV are queried


Whereis: Find command
Whereis MV: Find where the command is located, Help documentation, command source


Locate: Find files
Locate myfile//search out the directory myfile, you need to first refresh the DB, using the command: UpdateDB
Newly created files cannot be searched, The newly created file is placed in the Linux file database and requires a property file database to find the

Find: Find file
Find-name myfile//based on the file name, query in the current directory
Find-name "MyFile" No difference from the previous one
find/etc//root/-name "*[a-z]*"//query directory All files starting with a-Z
find/etc//root/-name "*[a-z]*"-exec ls -L {} \;//the query results to the LS command to continue execution, showing the previous query results details.
-exec: Execute, execute the following command, execute the ls-l command
{}: Identify the results of the query on one line to display the
\;: command to use very well, slash is used to escape.


| (Pipeline command)
The previous query results are handed to the following command for execution
Ls-al | more-5//Query all, give the result of the query to the more command to execute


grep (filter command) often used with pipeline commands
Ps-ef | grep svn//query All processes, filter query svn



Ln: Connect command, create Shortcut
Ln-s myfile link//Create a shortcut to MyFile link


Top: Shows the process of consuming resources in the current system
Top//Every 5 seconds shows the resource usage of the Xu puppet process
top-d 2//refreshed every 2 seconds


PS: View process (Common)
ps-ef//View All Processes
Ps-ef | grep Redis//See if the Redis process exists


Kill: Kills the process (common)
Kill-9 PID

DF: Show disk usage
df-h//view Current disk usage, including unit of occupancy


Shutdown: Shut down the machine
Shutdown system shutdown
Shutdown-r Restart immediately after shutting down the machine
Shutdown-h does not restart after shutting down the machine


Halt: Power off after shutdown


Reboot: Restart


============================= Decompression Command
gzip Zip bzip2 compression command

GZIP: Compressed files, not able to compress directories
Gzip file3//compress the File3, compress the file name into: file3.gz

Gunzip: Unzip
Gunzip file3.gz//Extract individual files
Gunzip file1.gz file2.gz//Unzip multiple files
Usually use gzip-d to decompress
GZIP-DV file1.gz//Decompression File1, V is the view can see the decompression process


BZIP2 and gzip compression in the same way


Zip:
Zip myzip.zip file1//file1 compressed into Myzip.zip
Unzip myzip.zip//Decompression


Tar: Package command to compress multiple files into a single file
TAR-CVF Dir.tar dir//Package All the files in the Dir directory into Dir.tar
TAR-XVF dir1.tar//Unpacking

Gzip Dir.tar//compress tar files into dir.tar.gz
TAR-ZXVF dir.tar.gz//decompression dir.tar.gz to Dir
-Z: Unzip file with GZ extension
-X: Unpack the TAR package
-V: Shows the execution process
-F: Specify unzip file

BZIP2 dir.tar//using BZIP2 Compressed tar package: dir.tar.bz2
TAR-JXVF dir.tar.bz2//Decompression bzip2 format pack




==============vim Text Editor
Vim enters the editor
VI has 3 total mode: Insert mode, command mode, low line mode
1, insert mode
I enter insert mode

2, Command mode
ESC enters Command mode

3, bottom row mode
: or/Enter the bottom row mode

In command mode:
Basic:
A: Add text to the right of the current cursor position
I: Add text to the left of the current cursor position
A: Add text at the end of the current line
I: Add text at the beginning of the current line
O: Create a row above the current line
0: Create a row below the current line
R: replace (overwrite) the current cursor position and several subsequent text
J: Merge The row of the cursor and the next line of behavior

Delete, Revoke:
X: Delete the current character
NX: Remove n characters from the beginning of the cursor
DD: Delete When moving forward
NDD: deleting n rows
U: Undo Previous Action
U: Undo the operation of the current line

Search:
/vpser: Searching for Vpser strings under the cursor
Vpser: Searching the vpser string for cursor flash
N: First search action before search
N: Search up previous search action

Jump to the specified line:
n+: Jump down N rows
N: Jump down N rows
NG: line with line number n is transferred to
G: Jump to the bottom of the file

Set line number:
: Set nu//Display line number
: Set noun//Suppress line numbers

Copy and paste:
YY: Copy the current line to the buffer
Nyy: Copies the current row down n rows to the buffer
P: Paste below the current line
P: Paste at the top of the line where the cursor is currently located
YW: Copy cursor to Word ending
NYW: copying n words starting from the cursor
y^: Copy content from cursor to beginning of line
y$: Copy content from cursor to end of line


Replace:
: s/old/new//Replace the first occurrence of old with new in the new word.
: s/old/new/g//Replaces all old words in the current line with new
: n,m s/old/new/g//Replace all old words with new from N to M
:%s/old/new/g//Replaces all old in the current file with new



8, Rights Management
================== Rights Management
-rwxrw-r--
-: Type
RWX: Owning User rights
rw-: Owning group permissions
r--: Other user rights

Highest bit: File type
-: Normal file
D: Catalogue
L: Shortcut file

High three-bit: U-owned User rights (RWX)
Intermediate three-bit: G user-owned group permissions (rw-)
Third place: O Additional user rights (r--)
The first way to set permissions is an example:
----------file1:file1 No permissions (use chmod 0 file1 to cancel all permissions)
Set Permissions: (x: Execute permissions r: Read permission w: Write permission)
chmod u+x file1---->---x------file1
chmod u+r file1---->-r-x------file1
chmod g+w file1---->-r-x-w----file1
chmod g+rx file1--->-r-xrwx---file1
chmod o+rwx file1-->-r-xrwxrwx file1

Chomod o=x file1--->-r-xrwx--x file1


To set permissions The second way is an example of:
Using 421来 to represent rwx, the corresponding relationship is as follows:
421 421 421
RWX rwx rwx

chmod after each digit match three bits: 3=2 (w) +1 (x) 5=4 (R) +1 (x)

chmod 421 FILE1----->-R---W---x file1 (4 for user's Read permission, 2 for group write permission, 1 for other user's execution rights)
chmod 354 file1----->-rwxrwxw-x file1

9, install the software
======================= Installing the Software
RPM: Installation Hassle not recommended
Yum: Support Online upgrade

1, associate DVD disk to Local: Right-click CentOS Select Settings, then find CD/DVD select Connected.



The 2,yum command supports online upgrades, while executing the yum command, detects all repo files under/etc/yum.repos.d/.
Repo file is stored in the URL, yum command to detect the repo file inside the Web site directly to download.
You can change the repo file so that the repo file points to the local DVD disk.
3. Mount the DVD disk to the MNT directory
Mount Command: mount/dev/cdrom/mnt/
Mount success:


4. Modify the Repo file
Back up the repo file first: rename. Repo. bak *//Modify all repo extension files to. bak
Create your own repo file, point to local file: Touch Mine.repo
Enter vim edit Repo file: Vim Mine.repo
[centos6.6]
Name=centos-dvd
Baseurl=file:///mnt
Gpgcheck=0
Enabled=1
Empty yum Source: Yum Clean all
Load yum Source: Yum Repolist All

Installing Mysql:yum Install Mysql-server


Start Mysql:service mysqld Start


Login database: Mysql-uroot p


Query database: show databases;



====================== installing JDK and Tomcat
1, first transfer JDK and Tomcat to the Linux root directory

2. Create a folder under Usr/local to store the JDK and Tomcat installation package: mkdir Hadoop

3, move the root directory under the installation package to the Usr/local directory: MV jdk-7u55-linux-i586.tar.gz apache-tomcat-7.0.47.tar.gz/usr/local/hadoop/


4, unzip the installation package: TAR-ZXVF jdk-7u55-linux-i586.tar.gz
TAR-ZXVF apache-tomcat-7.0.47.tar.gz
5, configure Environment variables: Vim profile
Added on last line: Export java_home=/usr/local/hadoop/jdk1.7.0_55
Export path= $JAVA _home/bin: $PATH

6, Refresh settings: Source/etc/profile
7. See if the installation was successful: Java-version



Problems:
1. Fix/lib/ld-linux.so.2:bad ELF interpreter:no such file or directory issues
Solution: Execute 32-bit program in 64 system if/lib/ld-linux.so.2 appears:
Bad ELF interpreter:no such file or directory,
Install under Glic: sudo yum install glibc.i686
2,error while loading shared libraries:libz.so.1:cannot open Shared object file:no such file or directory
Use: sudo yum install zlib.i686



==================== Install Lrzsz (can upload files to the specified directory)
1, Installation: Yum install Lrzsz
2, after installation use command: cd/usr/local/hadoop/
RZ: Direct pop-up transfer dialog box
3, passing tomcat to the Hadoop directory
4, start Tomcat
cd/usr/local/hadoop/apache-tomcat-7.0.47/bin/
./startup.sh

Category: Linux

Getting Started with Linux basics

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.