Linux (Ubuntu) Notes

Source: Internet
Author: User
Tags alphabetic character parent directory parse string egrep

View command Help (XXX/? In Windows)
Command--help (-h)
Mans command
Info command

View Help for Linux built-in commands
Help command
Help Export
Help for

Ls-al | More Flip screen (blank flip screen Q exit) (dir in Windows) (-H user-readable)
1.sudo reboot//Restart
2.sudo Shutdown-r Now
sudo halt-p//shutdown, power off
Uname-a (--all)//view system kernel information

View the directory of commands which whoami
Echo $path (echo%path% in Windows)
bin//Binary Files Directory
sbin//Binary Files Directory
Dev//device, Equipment Catalog
etc//the directory where the configuration files are located, environment configuration information
lib//Library Files (so:shared object shared objects, equivalent to DLLs)
Root//root User Home Directory
pwd//Current Folder


SU root//Switch User
Su passwd//set root password
mkdir//-P does not exist parent directory is created
Find. | grep A//pipe (tree in Windows)
Rm-f-R a//Force recursive Delete directory (del in Windows)
echo Hello > hello.txt//Append
echo Hello >> hello.txt//Overlay
Cat (type in Windows)
Nano Editor
Control+o Save
Control+x exit
Control+k Cut
control+ Resume Clipping

CP Hello.txt A/B/C
Simultaneous renaming of the CP hello.txt a/b/c/b.txt copy
Cp-r B.. /Copy Folder
MV A AA moving in the same directory is renaming
MV B.. /Move the B folder to the parent directory
Head hello.txt//Print first 10 lines
Head-3 hello.txt//print Top 3 lines
Tail Hello.txt
Tail-3 Hello.txt
More Hello.txt

Hostname Viewing host names
(Host fame in/etc/hostname file)
File file name (view file type) (Usr/bin/file)

TAR-CF archive.tar foo bar #Create archive.tar from files foo and bar
TAR-TVF archive.tar#list All files in Archive.tar verbosely do not archive to view the contents of the TAR Package
TAR-XF archive.tar#extract all files from Archive.tar
TAR-XVZF *.tar.zg#tar Open
TAR-RF Mytar.tar xxx# Append file
Gzip-1 mytar.tar# in situ compression (In-place) Time first
Gzip-9 mytar.tar# Space First
Gunzip = = gzip-d# Unzip the file

Xargs (Usr/bin) #将管道的输出内容合并成一行数据, use spaces to separate
ls | grep. txt | CP ' Xargs './b

Mount the optical drive


1. Hard link
ln hello.txt HELLO.TXT.LN
Two identical files, take up twice times of disk space, both live synchronously delete one another without deleting
2. Symbolic links (symblic link)
Ln-s Hello.txt Hello.txt.ln
Equivalent to a win shortcut that does not consume too much disk space
If the source file is deleted, the link fails (red, does not mean delete)

grep special characters need to be escaped
Ls-al | grep "\->"

Show All background jobs

Kill process

Process display
Ps-af | More (a All-process f all formats)

Kill kills the process

Cut Cut (Usr/bin/cut)
Cut-c 1-hello.txt
ps-al| Cut-c 10-15

Cut-c 1-xxx
Cut-c 1-5 XXX

View disk information, partitioning
sudo fdisk-l/dev/sda

DF View Disk Utilization

DirName viewing the directory where a file or folder is located
Suffix suffix

BaseName the base name of the output file (remove directory) (parse string only does not determine if this directory exists)
basename/home/ubuntu/hello.txt# Output Hello.txt
Basename/home/ubuntu/hello.txt. txt# Output Hello

echo $ (hostname) #类似于echo ' hostname ', all for dynamic command execution
echo $ ($ (cat hello.txt))

Cd-p folder (symbolic link) #进入物理目录

Output environment variables
Echo $PATH
Echo ${path}
echo "$PATH"

Export (Import environment variable, valid only in current session) (built-in command)
Expired after export Mypath=/home/ubuntu#reboot
Windows uses ";" Partitioning, Linux using ":"
Export yourpath=${path:-$mypath} #PATH存在则yourpath = $PATH otherwise yourpath= $mypath

Installing the Virtual Machine Enhancement tool
1.vmware-> Installing VMware Tool
2. Open the optical drive file
3. Copy vmware-tool-xxxxx.tar.gz to desktop, unzip
4. Enter the terminal and enter the Vmware-tools-distrib
5. Execute sudo./
6. Return
7.Enjoy ... It worked

Client Screen Adaptive
1. Shutting down the client
2. Edit Client Settings
3. Specify display settings, display, virtual machine, virtual machine settings

Client and host shared folders
1. Edit Client Settings
2. Shared folders, options, virtual machine, virtual machine settings, and so on
3. Enter/mnt/hgfs

Client and Host shared clipboard
1. Edit Client Settings
2. Client isolation, options, virtual machine, virtual machine settings
3. Select the check box

if commands; then commands; [elif commands; then commands;] ... [Else commands;] Fi
if RM b; then echo OK; else echo error; Fi
if[$#-lt 1] #参数个数小于1
if[$#-GT 1] #参数个数大于1
if[-e XXX] #是否存在xxx
if[-d XXX] #xxx是目录吗

0 indicates a successful command execution 1 indicates a failure
echo $? #返回刚刚执行命令的返回结果
$# #参数个数
The $0# command itself
$1# first parameter, this analogy ... n
[Email protected] #得到所有参数rm-R bin [email Protected]==-r bin
shift# move the parameter to the left,

Command combination
A && b#a execute the b command after successful execution
A | | B#a execution failed, then execute B command, a successful execution does not execute B
A B#a executes after execution b
(A; b) #同上, do not switch directories

NetCat (NC)
Swiss Army Knife
Tcp / ip
Transfer control protocal, Internet protocal
Analog TCP, UDP network communication
Implementing port Scanning
Socket//server, Listener, port
Serversocket//connection, Port

Nc-l 8888# Open Server listening 8888 port
Control + z# Background run
jobs# Show All Jobs
Kill%1# kills the job
Nc-l 8888 & #开启服务器监听8888端口, running in the background

NC IP port# Specifies the IP and listening port number of the server

FG%1# Switch 1 to reception

Transfer files
Nc-l 8888 > readme.txt# redirection
NC IP 8888 < readme.txt

Port scan
NC ip-z port1-portn# Specify host IP and port range
Nc-v-W 2 s1-z 1-100
-V Detailed information
-W Connection timed out
-Z Port scan

Command foreground background execution switch
1. Start the command directly in the background
Nc-l 8888
2. Pause the current process and put it in the background to become a job
jobs# View all jobs running in the background, [Jobid]
3. Activate the background job and run it in the background
4. Switch background jobs to foreground run

Kill%jobid# kills Job

Directories and Permissions
Drwxr-xr-x 6 ubuntu Ubuntu 4696 21 18:50
Control permissions
R:read Read
W:write Write
X:execute execution
-:none no this permission

D: Catalogue
-: File

User (owner)
group//Group, the user belongs to a group, can belong to more than one group, but only belong to a primary group, can be subordinate to multiple secondary group
111 = 7
Type owner group Other
D rwx R-x R-x
111 101 101
7 5 5

ugo+ (or-or =) rwx 777

Chmod:change mode
chmod ugo+rwx Hello.txt
chmod hello.txt
chmod U+RW Hello.txt
chmod A+RW Hello.txt
Ls-al Hello.txt

Permission Description
Files: Viewing the contents of a file
Folders: Viewing the resources contained in a folder
Files: Modifying file contents
Folders: Creating and Deleting files
File: Executable file
Folder: Whether you can enter

chmod 777 XXX

Add user
1.useradd (user/sbin/)
is the bottom-level add user command, it is recommended to use AddUser
2.adduser (user/sbin/)
adding users via AddUser
Deluser--remove-home UBUNTU2

Apt-get (Usr/bin) (Advanced Packages Tookit Premium package management tools)

Ubuntu Modify software Source
sudo nano/ect/apt/soutces.list
sudo apt-get update# update
sudo apt-get upgrade# upgrade

Ubuntu Package operation
sudo apt-get install xxx# installation
sudo apt-cache search xxx
sudo apt-cache search jdk

sudo apt-get remove xxx# remove uninstall software
sudo apt-get purge xxx# removing software and configuration files
sudo apt-get update
sudo apt-get upgrade
sudo dpkg-l | grep xxx

Modify Ubuntu's software source (163 source
1. Back up the sources.list in the current directory
sudo mv/etc/apt/sources.list/etc/apt/sources.list.bak
2. Create Sources.list
sudo touch/etc/apt/sources.list
3. Modify Sources.list ()
sudo nano/etc/apt/sources.list

Deb Http:// main restricted universe multiverse
Deb Http:// main restricted universe multiverse
Deb Http:// main restricted universe multiverse
Deb main restricted universe multiverse
Deb Http:// main restricted universe multiverse
DEB-SRC main restricted universe multiverse
DEB-SRC main restricted universe multiverse
DEB-SRC main restricted universe multiverse
DEB-SRC main restricted universe multiverse
DEB-SRC main restricted universe multiverse
4. Update packages
sudo apt-get update
5. Upgrading packages
sudo apt-get upgrade

6. Installing the Software
sudo apt-get install xxx

Install desktop
1. Update packages
sudo apt-get update
2. Upgrading packages
sudo apt-get upgrade
3. Search for Packages
sudo apt-cache Search Desktop | More
sudo apt-cache search Ubunut-desktop | More
4. Install the Package
sudo apt-get install xxx

Install the desktop locally
1. Obtaining the ISO file
2. Mount the ISO file to/mnt/
3. Modify the/etc/apt/sources.list file (to be backed up before modification)
Deb File:/mnt/cdrom./
4. Update and upgrade the software source
sudo apt-get update
sudo apt-get upgrade
5. Search Software
sudo apt-cache search Ubuntu-desktop
6. Installing the Software
sudo apt-get install Ubuntu-desktop

Note: Continue? : Y
Install these packages without verification [y/n]?y

Dpkg (Usr/bin)
Install the. deb file directly
-i|--install <.deb file Name> ...
sudo dpkg-i gedit_3.4.1-xxx.beb
To see if the installation was successful
Which gedit

Dpkg-qurey (User/bin)
-l|--list [<pattern> ...] List packages concisely. List Local Packages
Dpkg-query-l | grep gedit
sudo--remove gedit

Ubuntu Local Software Source production

sudo apt-get install Dpkg-dev
mkdir ~/software
cp-r-v/var/cache/apt/archives/* ~/software
sudo dpkg-scanpackages ~/software/dev/null | gzip > ~/software/packages.gz
Copy the entire software folder to the host computer
Install a new Ubuntu client
Copy the software folder to the home directory from host hosts
Edit/etc/apt/source.list File
Deb File:/home/ubuntu/software./
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xxx# now installed from local software source

Ubuntu ISO file production

1. Installing Mkisofs
sudo apt-get install Mkisofs
2. Using Mkisofs to make an ISO file
sudo mkisofs-r-o xxx.iso/targ

Ubuntu mounts ISO files for sharing via optical drive
1. Virtual machine mount ISO file
A. Specify the ISO file with the optical drive settings, virtual machine
B. Connection
2. Mount the CDROM to the/MNT directory
sudo mkdir/mnt/cdrom
sudo mount/dev/cdrom/mnt/cdrom

Cloning a client
1. Click on the virtual machine---right---management--clone

Ubuntu Network Connections in several ways
1. Bridging
Simulation into a physical host, can configure IP, access to the Internet, LAN visits, such as no network can not connect with each other
Net Address Transform
and host to form a local area network, the host does NAT and DNS, access to the Internet, other hosts within the LAN can not access the client, there is no network between the host and the client is still able to connect
Similar to NAT, no access to the extranet, security considerations, i.e. client and host form a closed LAN

Configure client as static IP
View Gateway
VMware Virtual Machine--Edit menu--Virtual network Editor--open Window--check vmnet8 virtual NIC-->nat Settings--View Gateway (

View available IP Segments
VMware Virtual Machine--Edit menu--Virtual network Editor--open Window--check vmnet8 virtual NIC-->dhcp Settings--View network segment ( )
Pick an IP
Configure the static IP for Ubuntu
To edit the network card configuration file/ect/network/interface
Auto Lo
Iface Lo inet Loopback
#iface eth0 inet Static
Iface eth0 inet Static
Auto Eth0
Restart Network Service
sudo/etc/init.d/networking restart

Syntax 1:for NAME [in WORDS ...]; Do COMMANDS; Done
Syntax 2:for ((: for (EXP1; exp2; exp3); doing COMMANDS; done
Equivalent to:
while ((EXP2)); Do

for ((a = 1; a < 4; a = a + 1)); do echo $a; Done
For a in 1 2 3; do echo $a; Done
For a in 1 2 3; Do echo $a >> ${a}.txt; Done
chmod u+x

For a in "[email protected]"; Do echo $a > ${a}; Done #等价于for A; Do echo $a > ${a}; Done

if [[#@ LT 1]]; then echo no Prame!!! ; Exit; Fi

While:while COMMANDS; Do COMMANDS; Done

while ((EXP2)); Do

((a = 1)); while ((a < 11)); do echo $a; (A = a + 1); Done

Equivalent to:
((a = 1))
while ((a < 11)); Do
Echo $a
((a = a + 1))

Print out all parameters using the while loop
((count = $#))
((a = 1))
while ((a <= count)); Do
echo $;
((a = a + 1))

sudo apt-get install vsftp


sudo vim/etc/vsftpd.conf
Modify Configuration
anon_max_rate=20000 #20k

Local User Login

FTP blacklist

Users can only browse the home directory

Set some users to browse only the home directory

Create a virtual user procedure
1. Turn off anonymous users

NL is the line number
Cat is not numbered

Regular expressions
Egrep "^a.*t$" words|wc-c
Matches a string in words that ends with a T, the number of statistics

Egrep "\<[abcd]at\>" words
A string containing [ABCD] opening +at

Egrep "^[[:upper:]]t$" words
String ending with a capital letter T
Character class:
[[: Alpha:]]: Alphabetic character
[[: Lower:]]: lowercase characters
[[:d Igit:]]: Numeric characters
[[: Space:]]: space
[[: Graph:]]: all characters except NULL

Shell programming
Name extension sh

Wildcard characters
* Any length character
? Any one character

Cat-n Display Line numbers
More Display split screen
Head Display Top 5 lines
Tail-n 5 shows the following 5 rows
Less to flip
grep PS1 filename Displays the line of text in FileName that contains PS1

Find/-name *bash* search for files containing bash in the current directory

Locate Bash Quick Search

Whereis Find
Whereis-b Find

which LS
which which

Uname-a Getting native information
Uname-r Getting system kernel information
Whatis ls command content
Apropos search Find related commands

Anti-virus software


Mounting discs
sudo mkdir/mnt/mycdrom
sudo mount/dev/cdrom/mnt/mycdrom/
sudo umount/dev/cdrom

Mount the hard drive
sudo mkdir/mnt/hard2
sudo mount/dev/sdb/mnt/hard2/

DF: View disk mount information

sudo fsck/dev/sdb
sudo fsck [mount point] repair mounted disk

MKFS Format File System setup
sudo mkfs-t ext3/dev/sdb1
Check the car file system is working properly

Compress files
Gzip FileName

Unzip the file
Gunzip Compressed Package file name
Gunzip hello.gz
Gzip-d Compressed Package file name

viewing compression effects
Gzip-l Compressed Package file name

Check Compression Package Integrity
GZIP-T Compressed Package Name
No information is output if complete

GZIP-TV Compressed Package file name
If the full output OK

Packaging the current directory
TAR-CVF Example.tar./
Tar xvf unpacking file
Will unzip the file into the current directory

The file name that TAR-CWVF is packaged into.
Ask me every time we pack

Create an archive file and compress
TAR-CZVF example3.tar.gz./

Unzip the archive file
Tar-xzf example3.tar.gz

Create an ISO file
DD If=/dev/chrom Of=ubuntu.iso

Partition command
Ls/dev |grep SD
View disk conditions

sudo fdisk/dev/sdb

Linux (Ubuntu) Notes

Related Article

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: 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.