[Linux Learning] Record the common basic instructions of Linux~

1. Linux is an operating system, which is in a "parallel" relationship with windows. Linux has become "the world's largest operating system".

2. What is the benefit of using commands in Linux over the graphical interface?

(1) Saving system resources: running a graphical interface requires the system to pay some additional overhead;

(2) Save network bandwidth: If you access the server through the network, you need to transmit images frame by frame when using the graphical interface, but you only need to transmit simple strings when using the command line;

(3) Easy to perform tasks in batches: You can execute tasks in batches through some "script" codes (Linux Shell), and complete some simple programming tasks (such as timing backup files, deleting files, etc.).

Linux common commands

1、ls 表示显示所有文件
深蓝色的表示文件夹;
白色的表示普通文件;
浅蓝色的表示链接文件。

    ls -l 表示列出文件的详细信息,可以简写为ll。

2、pwd 表示显示当前文件的路径

3、cd~ 表示回到根目录

4、输入文件名的时候可以按Tab键补全

5、shift + insert 表示粘贴到界面

6、Ctrl + insert 表示复制

7、Ctrl +C 表示终止当前操作

8、man  表示查看文档

Operations on files

touch 文件名:新建一个文件
cat 文件名:查看当前文件
echo “要写入的内容” > 文件名:往文件里面写内容,会将原来的内容覆盖掉;用两个>>不会覆盖,另起一行追加到内容后面。

create file mkdir

mkdir 文件名:创建一个文件
mkdir -p 111/222/333 :用/隔开,表示创建指定目录下子目录 。111文件夹下有222,222下有文件夹333;
mkdir 111 222 333:一次创建多个同级目录

delete file rm

rm 文件名:删除文件
rm -r 文件夹名:删除文件夹
rm -rf 文件名或文件夹名1 文件夹名2  文件夹名3:加-rf表示删除文件夹名不提示(一般不要使用rm -rf)

copy file cp

cp 要复制的文件 复制到的路径和名称
   后面直接写路径,但是没有指定文件名,则文件名和原文件名相同。
cp test1.txt test2.txt

move file mv

mv 要移动的文件或目录 移动的路径和新文件名称
   也可以在本地移除,命名A文件为B

Turn the page to view the content of the file less


less 文件名
表示翻页查看文件内容(与cat的区别:不会将所有内容都加载到内存中)

head and tail 

#head与tail从文件的第一行和最后开始加载

1、head -n行数 文件名
    表示从头开始显示多少行 

比如:有一个文件有100行,请将第50行取出   
   head -n50 test > temp
    表示将前50行转入临时文件temp
   tail -n1 temp    #得到中间行

tail用的比较多,查看日志。

time date

date指定格式来显示时间:date+"%Y-%m-%d %H:%M:%S"
时间转化为时间戳: date+%s
时间戳转化为时间: date -d@1508749502(要转换的时间戳)

text editor vim 

vim是一个文本编辑器,相当于记事本

(1)vim 文件名
    准备新创建一个文件;
(2)vim打开文件默认是普通模式,按i键进入编辑模式;
(3)保存:在插入模式下不能保存文件,输入内容后按esc回到普通模式。在下方写
    :wq 表示写入并退出,按下回车即可
    :q 表示只退出不保存
    :w 保存文件

(3)普通模式下按Ctrl Z 后,vim到后台运行;fg又切换到后台vim。

 Find the specified string grep

grep用于查找文件中是否包含指定的字符串,并显示对应的行
grep "hello" hello.java

ps view system process

ps aux #显示系统当前所有的进程
ps aux | grep 进程名
ps aux | grep 进程id

netstat View system network status

netstat -anp  显示所有开通的网络
netstat anp | grep 进程名
netstat anp | grep 端口号

netstat -anp | grep 3306:显示使用3306端口的信息 

Username and permissions

超级用户 root  提示符#
普通用户 提示符 $

切换用户: su 用户名

 

Guess you like

Origin blog.csdn.net/qq_48479056/article/details/131585025