一.Linux常用命令(I Linux common commands)

1. ls  list:列出文件和目录

(1)常用参数:-l:long 列出文件的详细信息  -a:all 列出全部文件,包括隐藏文件

2. cd  change directory:切换目录

(1)用法:

cd /home # 切换/进入home目录

cd .   # 进入当前目录(其实啥都不做)

cd ..   # 进入上一级目录(父目录)

cd ../..     # 到父目录的父目录

(2). :当前目录  .. :上一级目录

3.cp  copy:复制

(1)参数:

-i:interactive mode:互动模式。若有同名文件,会询问是否覆盖(如果没这个参数,会不提示,直接覆盖)-r:recursive copy:递归复制。复制文件夹时连同子文件(夹)一起复制,如果是对文件夹进行操作,一定要带这个参数

(2)用法:

cp -ir sourceDir/ home/targetDir/   # 把当前路径下的sourceDir文件夹复制到home目录下,取名为targetDir,且带参数-i和-r  ***

4.mv  move:移动。即剪切文件。原文件会被删除

(1)参数:

-i:互动模式,若覆盖则会询问

(2)用法:

mv -i sourceFile /home/targetFile   # 把当前目录下的sourceFile剪切到/home目录下并命名为targetFile

5.rm  remove:删除

(1)参数:

-i:互动模式,同上

-r:递归删除,同上

(2)用法:

rm Dir/(错误示例,会报错)

rm -r Dir/(正确,对文件夹操作,一定要带-r)

6.mkdir  make directory:创建文件夹

(1)用法:mkdir newDir/   # 在当前路径创建一个空文件夹newDir/

7.rmdir  remove directory:删除文件夹

(1)用法:rmdir oldDir/   # 在当前路径删除oldDir文件夹及其子文件(夹)

8.chown  change owner:更改所有者

(1)参数:-R:同-r,同上

(2)用法:chown user -R myDir/   # 把文件夹myDir的所有者改成user

9.chmod  change mode:更改文件的权限模式

文件权限模式针对三类对象:当前用户user(这里也是文件的所有者),组group,其他用户other。(属主,属组,其他用户)文件权限有 读:read,写:write,执行:execute

(1)参数:

chmod参数:u: user,权限对象为当前用户(这里是所有者)g:group,权限对象为所有者和组o:other,权限对象为其他用户r:read = 4,读权限w:write = 2,写权限e:execute = 1,执行权限+:u/g/o与r/w/e组合使用,加入-:删除=:设置

4:读  2:写  1:执行4:仅读5:仅读+执行6:仅读+写7:读+写+执行

(1)用法:

chmod 754 myDir/   # 当前用户(所有者)可读+写+执行,组group可读+执行,其他用户可读

chmod g+w myDir/   # 为组group添加写write权限

10. find  查找

(1)参数:

-name:根据文件名查找-mtime n:n为数字,表示找出在n天前的当天被更改过的文件(0表示今天)-mtime +n:查找在n天前(不包括n天当天)被改过的文件-mtime -n:查找在n天之内(包括n天当天)被改过的文件-size +/-:查找比XXsize大/小的文件

(2)用法:

find /home -name myFile   # 在/home目录下查找文件名为myFile的文件(注:myFile也可以搭配正则表达式使用)find /home -name *.txt       # 在/home目录下查找以txt为后缀的文件find /home -mtime 0       # 在/home目录下查找今天内被改过的文件find /home -mtime +1       # 在/home目录下查找昨天之前(不包括昨天)被改过的文件find /home -mtime -1        # 在/home目录下查找昨天至今(即昨天和今天)被改过的文件find /home -size +100M   # 在/home目录下查找大于100MB的文件,注意c表示byte

11. |  管道  将前一个命令的输出结果像管道一样传递给后一个命令作为输入

(1)用法:

ls | find -name myFile   # 列出当前路径的文件(夹)并查找名字为“myFile”的,打印出来

12. grep  按行查找并匹配

(1)参数:

-R:递归查找所有子文件(夹)

-i:insensitive search,忽略大小写

-l:显示文件名称,而非匹配到的行的内容

-v:反向选择,显示出没有匹配到的行的内容

(2)用法:

grep -i mystring file.txt   # 忽略大小写,在file.txt中查找并打印出有“mystring”的行

ls -l | grep -i mystring   # 在ls -l的输出中把有“mystring”的行打印出来(忽略大小写)

13. tar:打包,压缩,解压

(1)参数:

-jcv:压缩

-jxv:解压

(2)用法:

tar -jcv myDir/   # 压缩myDir文件夹

tar -jxv DownloadDir.tar.gz myDir/   # 解压DownloadDir.tar.gz到当前文件夹下,并命令为myDir

14.cat  打印文件内容

(1)用法:

cat myFile   # 显示myFile

15.ps  process select:查看进程

(1)参数:

-A:显示所有进程-a:不与terminal有关的所有进程-u:有效用户的相关进程-x:一般与-a一起用,列出完整的进程信息-l:long,详细列出PID的信息

(2)用法:

ps Aux   # 查看系统所有的进程数据

ps ax

16. kill  杀死进程

(1)参数:

-SIGHUP:启动被终止的进程-SIGINT:相当于ctrl+c,中断进程-SIGKILL:强制中断进程-SIGTERM:以正常的结束进程方式来终止进程-SIGSTOP:相当于ctrl+z,暂停进程

(2)用法:

kill -SIGKILL 10876   # 强制中断PID=10876的进程(PID可以通过ps查到,有时可以加上| grep进行筛选)

17.passwd  修改密码

(1)用法:

passwd # 修改当前用户的密码

18. pwd  print work directory:显示工作目录

(1)用法:pwd

19. tee   显示并保存。显示内容并将内容保存在文件中

(1)用法:

python3.6 test.py | tee result.log   # 运行test.py文件,显示编译与运行结果并保存成result.log文件

20.reboot  重启

(1)用法:

reboot # 输完立马重启(记得保存文件)

————————

1. LS list: lists files and directories

(1) Common parameters: – L: long list file details – A: all list all files, including hidden files

2. CD change directory: switch directories

(1) Usage:

CD / home # switch / enter home directory

cd . # enter the current directory (actually do nothing)

cd .. # enter the upper level directory (parent directory)

cd ../.. # to the parent directory of the parent directory

(2). : Current directory..: Upper level directory

3. CP copy: copy

(1) Parameters:

-i: Interactive mode: interactive mode. If there is a file with the same name, you will be asked whether to overwrite it (if there is no such parameter, you will not be prompted to overwrite it directly) – R: recursive copy: recursive copy. When copying a folder, it is copied together with sub files (folders). If you are operating on a folder, you must take this parameter

(2) Usage:

cp -ir sourceDir/ home/targetDir/ # copy the sourcedir folder under the current path to the home directory, named targetdir, with the parameters – I and – R***

4. MV move: move. That is, cut the file. The original file will be deleted

(1) Parameters:

-i: Interactive mode, if it is overwritten, it will ask

(2) Usage:

mv -i sourceFile /home/targetFile   # Cut the Sourcefile in the current directory to the / home directory and name it targetfile

5. RM remove: delete

(1) Parameters:

-i: Interactive mode, ibid

-r: Recursive deletion, ditto

(2) Usage:

RM dir / (error example, error will be reported)

RM – R dir / (correct, for folder operations, be sure to bring – R)

6. MKDIR make Directory: create a folder

(1) Usage: MKDIR newdir / # create an empty folder newdir in the current path/

7. Rmdir remove Directory: deletes a folder

(1) Usage: rmdir olddir / # delete the olddir folder and its sub files (folders) in the current path

8. Chown change owner: change owner

(1) Parameter: – R: same as – R, ditto

(2) Usage: chown user – R mydir / # change the owner of the folder mydir to user

9. Chmod change mode: change the permission mode of the file

The file permission mode is for three types of objects: the current user (also the owner of the file here), the group, and other users. (primary, group, other users) the file permissions are read: read, write: write, execute: execute

(1) Parameters:

Chmod parameters: u: user, the permission object is the current user (here is the owner) g: group, the permission object is the owner and group O: other, the permission object is other users R: read = 4, read permission W: write = 2, write permission e: execute = 1, execution permission +: U / g / O combined with R / w / E, add -: delete =: Set

4: Read 2: write 1: execute 4: read only 5: read only + execute 6: read only + Write 7: read + Write + execute

(1) Usage:

Chmod 754 mydir / # current user (owner) can read + Write + execute, group can read + execute, and other users can read

CHMOD G + W mydir / # add write permission for group

10. Find

(1) Parameters:

-Name: search according to the file name – Mtime n: n is a number, which means to find the file changed on the day n days ago (0 means today) – Mtime + N: search for the file changed n days ago (excluding the day n) – Mtime – N: search for the file changed within n days (including the day n) – Size + / – search for the file larger / smaller than xxsize

(2) Usage:

find /home -name myFile   # Find the file named myfile in the / home directory (Note: myfile can also be used with regular expressions) find / home – name * txt       # Find the file with txt suffix in the / Home Directory Find / home – Mtime 0 # find the file changed today in the / Home Directory Find / home – Mtime + 1       # Find the file changed before yesterday (excluding yesterday) in the / Home Directory Find / home – Mtime – 1        # Find the modified files from yesterday to now (i.e. yesterday and today) in the / Home Directory Find / home – Size + 100m # Find files larger than 100MB in the / home directory. Note that C represents byte

11. | the pipeline passes the output result of the previous command to the latter command as input like a pipeline

(1) Usage:

Ls | find – name myfile # list the files (folders) in the current path, find the one named “myfile” and print it out

12. Grep find and match by line

(1) Parameters:

-R: Recursively find all sub files (folders)

-i: Insensitive search, ignoring case

-l: Displays the file name instead of the contents of the matched line

-v: Reverse selection to display the contents of rows that do not match

(2) Usage:

grep -i mystring file. Txt # ignore case, in file Txt and print out the line with “mystring”

LS – L | grep – I mystring # print the line with “mystring” in the output of LS – L (case is ignored)

13. Tar: package, compress and decompress

(1) Parameters:

-JCV: compression

-Jxv: unzip

(2) Usage:

Tar – JCV mydir / # compress mydir folder

tar -jxv DownloadDir. tar. GZ mydir / # unzip downloaddir tar. GZ to the current folder and the command is mydir

14. Cat print file content

(1) Usage:

cat myFile   # 显示myFile

15. PS process select: view the process

(1) Parameters:

-A: Display all processes – A: all processes not related to terminal – U: related processes of valid users – X: generally used with – A, list complete process information – L: long, and list PID information in detail

(2) Usage:

PS aux # view all process data of the system

ps ax

16. Kill the process

(1) Parameters:

-SIGHUP: start the terminated process – SIGINT: equivalent to Ctrl + C, interrupt process – sigkill: force interrupt process – SIGTERM: terminate the process in the normal way of ending the process – sigstop: equivalent to Ctrl + Z, pause the process

(2) Usage:

Kill – sigkill 10876 # forcibly interrupt the process with PID = 10876 (PID can be found through PS, and sometimes | grep can be added for filtering)

17. Passwd change password

(1) Usage:

Passwd # modifies the password of the current user

18. PWD print work directory: displays the working directory

(1) Usage: PWD

19. Tee} display and save. Displays the content and saves it in a file

(1) Usage:

python3. 6 test. py | tee result. Log # run test Py file to display the compilation and running results and save them as result Log file

20. Reboot restart

(1) Usage:

Reboot # input and restart immediately (remember to save the file)