Linux systems commonly used commands (1)

1. The user directory

pwd command: View current directory.

(1) absolute path: from the root directory to start writing / home / yj_coder / aa

(2) a relative path: bb relative to the current working directory concerned

                  .   -> the current working directory

                  ..   -> current parent directory

                  -   -> between two adjacent switch directories cd -     (to switch between the two most recent catalog entry)

(3) yj_coder @ ubuntu: ~ $ ($ ago - description of the current user's home directory directory)

                  yj_coder: Current User

                  @ And 在

                  ubuntu: hostname

                  ~: The user's home directory (home directory) (equivalent / home / yj_coder)

                  $: The current user is a normal user

                  #: Superuser (root) (switching command with sudo su to root) becomes: root @ ubuntu: / home / yj_coder / aa #

2. ls and use of tree

File and directory operations

(1) View my directory (tree directory tree structure of the directory lists)

         1) tree (tree directory tree structure of the directory lists) - The software must be installed (sudo apt-get install tree)

         2) ls (ls directory lists visible directory or file in this directory), if you can add parameters ls -a hidden files will be listed, hides file name the first character is a point ' . ' If the plus ls -l parameters will list details, as shown below:

             All of which can be found in the directory are the size of disk space occupied by 4096, which does not include the file size.

3. create files and directories

(1) Create a directory: mkdir command   

               1) mkdir directory name (create a directory, if the directory name already exists, you are prompted to already exist)

               2) mkdir -p dir / dir1 / dir2 (plus parameter -p, create a complex directory)

(2) create file: touch command

               1) touch the file name (create an empty file, if the file name already exists, it will modify the access time of the file)

4. Delete files and directories

(1) Delete the directory: rmdir command

               1) rmdir directory name (delete a directory, the directory must be empty)

               2) rm -r directory name (directory and delete everything in the directory)

(2) delete the file: rm command

               1) rm file name (deleting a file)

5. Copy files and directories

(1) copy of the file: cp command

               1) cp file 1 file 2 (1 copy of the contents of the file to 2 files, if the file does not exist until you create another 2 copies, if so which existed before the contents of the contents of the file will be overwritten 1)

(2) Copy directory: cp -r command

               1) cp -r Contents 1 Table of Contents 2 (2 if there is no table of contents before you first create, then copy the contents of the directory 1 2 go into the directory; if it existed before the contents of the directory and the directory to copy the whole 11 Contents 2 go, become the equivalent of Contents 1 Contents 2 a subdirectory.)

6. Check the contents of the file (cat_more_less_head_tail)

7. mv command

(1) change the name to the file: mv file name 1 File name 2 File name is the original file name 1, this command renamed file name 2.

(2) move files: mv file directory Move the file to the directory.

8. Create a soft connection

(1)ln -s 1234.c 1234.soft       1234.soft作为1234.c的快捷方式被创建出来,其大小为6,是“1234.c”这个相对路径的长度。这个1234.soft只能在与1234.c相同的目录下使用,才能找到1234.c,如果将1234.soft移动到其他位置,因为创建时使用的是相对路径,所以用一个相对路径“1234.c”在当前位置去找,当然就找不到1234.c这个文件了。

(2)ln -s ~/1234.c 1234.soft      此时用绝对路径创建软连接,那么由于1234.soft中保存的是绝对路径,所以这时再将1234.soft移动到其他位置,也可以用其中保存的绝对路径去找到文件1234.c。

(3)ln -s ~/目录名/ 目录名.soft     给目录创建软连接,和前面给文件创建是一样的,注意前面的参数最好用绝对路径,这样可以移动目录名.soft到其他位置。

9. 硬链接的创建

ln 1234.c 1234.hard       此命令给1234.c创建了一个硬链接1234.hard,可以创建多个硬链接,用ls -l命令可以查看硬链接计数,此计数包含原文件。要在磁盘上找到一个文件时,是通过inode结点找到对应的文件的,创建的多个硬链接都是指向这一个inode结点。用ls -l命令可以看到这些硬链接的大小和原文件的大小相同,但是它们本质上是不占用磁盘空间的,因为这些硬链接都是指向一个位置。对某一个硬链接中内容的修改就是对原文件中内容的修改,因为本质上这个文件在磁盘上只有一份。创建的硬链接移动到其他位置也是可以的,因为它是利用inode结点来找到磁盘中的文件,所以与硬链接所在的位置无关。

注:只有文件才能创建硬链接,目录不可以。

10. 文件和目录属性命令(od_wc_du_df)

(1)wc命令用来查看文本文件的属性信息:wc 1234.txt     结果:7 23 120 1234.txt   其中7代表行数,23代表单词数(以空格划分),120代表字节数,1234.txt代表文件名。

(2)od命令用来查看二进制文件的内容:od -tx hello   

    

(3)du命令用来查看某个目录的大小:du -h

(4)df命令用来查看磁盘的使用情况:df -h

11. which命令

12. 修改文件的权限

            

              例:把temp文件给其他人添加写权限:chmod o+w temp

         

               例1:设置temp文件的权限:chmod 765 temp     

               例2:用减法去掉其他人的执行权限:chmod -001 temp

13. 修改文件的所有者和所属组

如上图所示,用户A、B的所属组是Group1,用户C、D、E的所属组是Group2,用户F、G、H、I的所属组是Group3。该文件的所有者是用户B,但其所属组可能是Group1、2、3中的任何一个。假设该文件的所属组为Group2,那么Group2中的用户C、D、E对该文件具有相同的权限,即所属组权限。用户B对该文件具有所有者权限。用户A、F、G、H、I对该文件的权限是其他人权限。

(1)只修改文件的所有者:sudo chown zhangsan temp      把文件temp的所有者修改为zhangsan。

(2)同时修改文件的所有者和所属组:sudo chown Luffy:lisi temp       把文件temp的所有者改为Luffy,把文件temp的所属组改为lisi。

(3)只修改文件的所属组:sudo chgrp itcast temp       把文件temp的所属组改为itcast。

注:目录必须有执行权限,否则将会进不去目录。目录创建出来默认都是有执行权限的。

14. 按文件的属性查找文件 (find命令)

(1)按文件名去查找:sudo find + 查找的目录 + -name + “文件的名字”

         例1:sudo find /home/itcast/ -name "hello.c"     会找到目录下所有名字为“hello.c”的文件,输出它们所在的完整路径。

         例2:使用通配符*,它可以代表0个至多个字符   sudo find /home/itcast/ -name "hel*",会找到目录下所有前缀是hel的文件。

         例3:使用?,它代表1个字符    sudo find /home/itcast/ -name "hel?"。

(2)按文件的大小去查找:sudo find + 查找的目录 + -size + +10k   找到所有目录下大于10k的文件。+为大于,-为小于。

         例1:sudo find ~ -size +10k     找到所有家目录下大于10k的文件。

         例2:sudo find ~ -size +10M -size -100M     找到所有家目录下大于10M小于100M的文件。

(3)按文件类型去查找:sudo find + 查找的目录 + -type + f/d/b/c/s/p/l     找到所有目录下文件类型为设置参数的文件。参数f为普通文件。

15. 按文件的内容查找文件 (grep命令)

grep -r “查找的内容” + “查找的路径”             在路径下的所有文件中找其内容里含有“查找的内容”的所有文件。

         例:sudo grep -r "stdio.h" ~           在家目录下找其内容中有“stdio.h”的所有文件。

16. 软件的安装和卸载

软件列表中保存着软件名字和其对应的下载地址,更新软件列表是从官方服务器更新。在下载安装软件之前,最好更新软件列表,以便在安装软件时可以顺利从软件列表中找到其下载地址进而下载安装。

           

Guess you like

Origin blog.csdn.net/mengyujia1234/article/details/90272120