Linux note: core idea, commonly used commands and script syntax

Are summarized in the "Bird Brother Linux private kitchens - based learning articles" , the picture is also from there.

main idea

Directory tree structure (directory tree)

Linux system is based on the directory tree structure, which is its core idea . Directory that folder. Linux system is equivalent to a folder, all Linux systems or data corresponding to a folder, or is a file. For example, you create a new user, in fact, created a new folder. A user corresponds to a folder. Directory tree structure:

Pictures from the "Bird Brother Linux private kitchens - based learning articles"

Figure above rectangle is a folder , wavy file , the root directory /. This /is very clever, in macOS, suppose you download the file to test.md /Users/username/Desktop/, then the file will be downloaded to your desktop, this front /is the root directory. If you write Users/username/Desktop/, then the file will be downloaded to currentDerectory/Users/username/Desktop/the next.

Linux systems use a directory tree structure, but in fact the data is stored in the disk partition which, then the question arises: tree and disk partition is God-Malaysia relations? This time it involves a concept called "mount (mount)" in the.

The relationship between the tree and the disk partition

Mount fact, establish the relationship between the tree and disk partitions. Contents just a logo, what we can customize a directory corresponding to a disk partition.

We often use U disk, assuming a U disk is a disk partition, we have a hypothesis called partition1 U disk plugged into a Windows computer, the computer may be on more than one disk F, then the directory is F, equivalent to hang Schedule F uploaded to the U disk, you can access F partition1 access the contents. If a hypothesis called partition2 then plug the U disk, the system will be more than one H-disk, which is equivalent to the directory H mounted on the partition2. F under the assumption that there will be a disk to store a lot of video of moive folder, we can directly mount to the movie folder partition2, this movie where the video is saved to partition2 inside, not the disk space F.

In the Linux system is the same reason, such as when to build a Linux environment, you can be / home to mount on a separate disk partition.

Pictures from the "Bird Brother Linux private kitchens - based learning articles"

Common Commands

command meaning Options Examples
--help ls --help
man manual man man
ls list -a, --all
-h, --human-readable
-l, --long listing format
ls -ah: Displays directory of all folders, including hidden folders
ls -l==ll
cd change directory cdEquivalent cd ~, ~the current user root
cd /root
cd ..layer of
cd ../..two layers of
cd ../<directory>a layer inside a directory
cd <directory>/<directory>to a directory in a directory in the current directory
rm remove -d, --direcorty
-r, --recursive
-f, --force
rm <file>
rm -d <directory>
rm -rf <directory>
rm *.pdf
cat concatenate cat <file>
mkdir make direcotry mkdir <directory>
touch create a file touch <file>
mv move move oldname name
move <file>/<directory> <directory>
cp copy cp test test.bak
zip -r, --recurse zip -r test.zip test/
unzip unzip test.zip
takes tape or archive -f, --file=ARCHIVE
-c, --create
-t, --list
-v, --verbose
-x, --extract
-z, --gzip, --gunzip, --ungzip
tar -cf archive.tar foo bar: Creates the file foo and bar as archive.tar
tar -tvf archive.tar: archive.tar detailed list of all the files
tar -xf archive.tarto extract all files from archive.tar in:
tar xvzf redis-stable.tar.gz: From the redis-stable.tar.gzdetailed extract all files
pwd print working directory pwd
sh run a script sh test.sh Equivalent to ./test.sh
start start notepad++ <file>
start Typora <file>
we visual vi <file>
vim we improved vim <file>

vi / vim three modes

vi <file>And vim <file>are modified <file>after the command, which is an enhanced version of the former, enter this command, there will be three models modified <file>file.

  • General command mode (command mode): You can not see what you type
  • Edit mode (insert mode): directly modify the contents of the file
  • Command-line command mode (command-line mode): the bottom line, :or /or ?at the beginning of

Pictures from the "Bird Brother Linux private kitchens - based learning articles"

  • See the following detailed meanings instruction vim editorWARNING_END

    Common commands

  • General Command mode:

instruction meaning
i The current position into insert mode
I The first character
a The next character
A end
The The beginning of the next column
THE On a beginning
r Replace mode, a substituted
R Has been replaced
in Undo
Ctrl + r Cancel the revocation, the equivalent of U?
0 First row
end / $ End of line
G last row
gg 1 G, the first column
n<enter> N columns moved downward
Ctrl + f fall, to the next page
Ctrl + b before, the previous
x delete
X Previous deleted
dd Delete the current column
d$ Remove columns from the current position to the tail
yy Copy the current column
  • Edit mode:
instruction meaning
Esc Exit edit mode, enter the general command mode
  • Command Mode command line:
instruction meaning
:w Storage
:w! Forced guarantee
:q drop out
:q! Force Quit
:wq Exit and save the equivalent of ZZ
/word Find keywords
: Not set Show Line Numbers
:1,$s/word1/word2/gc Replace word1 word2

/word When lookup, using n jump to the next search result, N jump to previous search results

Script syntax

  • Traversal. Example: A print out the script in the current directory path of all folders named traverse.sh, as follows:
#!/bin/bash

for i in $(ls $(PWD))

do
if [ -d $i ];then
cd $i
pwd
cd ..
fi # if 反向,代表 if 结束
done

Execute the script: sh traverse.sh

Other commonly used commands

## 用户
passwd <username> # 修改用户的密码
whoami # 查看当前用户名

## 日志
less <file> # 查看最新日志
tail -f <file> # 查看实时日志
grep -5 <key> <file> # 查看日志 <file> 关键字 key 上下五行
grep -5 <key> <file1> <file2> # 输出日志 <file1> 关键字 key 上下五行的内容到 <file2> 中

## 进程
ps -ef|grep WeChat # 查看进程名叫 WeChat 的信息,最开头的数字为 id
kill -9 6002(最开头的数字) # 杀死进程 id 为 6002 的进程

sed -i's/word1/werd2/g' <file> # 替换 <file> 的 word1 为 word2(sed -- stream editor)
xclip -sel c < <file> # 不打开 <file> 的情况下复制其内容
df -h # 查看磁盘分区和目录信息(df -- display free disk space)
echo $PATH# 输出 $PATH 的内容

References

Guess you like

Origin www.cnblogs.com/deppwang/p/11593158.html