[linux] file system and basic commands

Linux and Unix systems have the following interpretation of files: everything is a file; if it is not a file, it is a process.

Linux treats files and directories as the same, because a directory is just a file with other filenames in it. Programs, services, text, pictures, etc. are all files. To the system, input and output devices, basically all devices, are treated as files.

As shown in the figure above, the file system of the Linux system is not composed of multiple drive letters unlike the Windows system. All files are managed in a tree structure under the same file system. The "root" of the tree is /

/ is the root directory, it has the following basic folders:

/bin (binary) - necessary binaries stored in but available in user mode , available to all users, such as cat, ls, cp, etc.

/dev ( device ) - stores the necessary device files

/home - the user's home directory, including saved files, personal configuration, etc.

/lib< architecture_bits > - necessary file library for alternate format

/media - mount point for removable multimedia (eg CD-ROMs , USB sticks)

/mnt - Temporarily mounted filesystem

/opt ( add-on application software ) – optional application software package

/root - the home directory of the root user

/sys

/usr - The second level stores the user's institutional data; contains (multiple) users' main public files and reference programs

/boot - holds bootloader files such as kernels , initrd , etc.

/etc - holds host-specific system-level configuration files

/lib - store the resource library required by the system

/lost+found - Stores corrupt files generated when the system crashes

 

 

File Types in Linux

Ordinary file (" - ") : The basic file type in linux system.

directory (" d ") : A file composed of other files.

Special files : Paths for input and output. Most special files are stored in /dev .

Linked files (" l ") : A mechanism for having a file or directory appear in multiple places in the system file tree structure. Equivalent to a Windows shortcut.

(Domain) Socket : A special file type, similar to the socket in the TCP/IP protocol, that provides a communication mechanism between processes and is protected by the access control mechanism of the file system.

Named Pipes : Provides an inter-process communication mechanism instead of the network socket protocol.

 

 

Linux file naming rules

  1. All characters are legal except / .
  2. Characters like spaces, tabs, characters @# ¥ % () - etc. should not be used as much as possible.
  3. Avoid using " . " as the first character in normal filenames.
  4. Linux is strictly case sensitive for filenames.

Types of permissions in Linux

r : Readable, the user can open and read the contents of the file, and the permission value is 4 .

w : writable, the user can add, modify and delete the content in the file, the permission value is 2 .

  1. x: Executable, the user can execute the file, and the permission value is 1.

     

    Basic command format of Linux

    Command format: command-option parameter

    ex:ls -la /etc

    Explanation: 1) When there are multiple options, they can be written together.

    2) Two special directories . and .. represent the current directory and the parent directory of the current directory respectively

     

    file processing commands

    1. ls

      Original meaning: list

      Command path: /bin/ls

      Execute permission: all users

      Role: display directory files

      Syntax: ls option [-ald] [directory or file]

      -a Show all files, including hidden files.

      -l show detailed information

      -d View directory properties

      example:

      [userLee @ admin ~] $ ls -l

      Total usage 84

      -rw-r - r--. 1 root 246 4 月 22 14:48 a.tar.gz

      drwxr-xr-x. 2 userLee userLee 4096 4 月 22 14:37 dir1

      drwxr-xr-x. 4 root root 4096 4月 22 14:58 dir2

      -rw-rw-r--. 1 userLee userLee 0 4月 19 03:55 hetc

      -rw-r--r--. 3 root root 47 11月 27 2013 issue.hard

      -rw-r--r--. 3 root root 47 11月 27 2013 issue.soft

      第一个字符表示文件类型(-dl)

      第二到第四个字符表示文件拥有者(owner)(一般指创造者)的权限

      第五到第七个字符表示用户组(group)权限

      第八到第十个字符表示其他组(other)的权限

       

    2. cd

      原意:change directory

      命令路径:shell 内置命令

      执行权限:所有用户

      功能描述:切换目录

      语法:cd [目录]

      Ex: cd / 切换到根目录

      cd .. 回到上一级目录

    3. pwd

      命令原意:print working directory

      命令路径:/bin/pwd

      执行权限:所有用户

      功能描述:显示当前所在的工作目录

      语法:pwd

       

      结合cd命令查看和更改目录:

      [userLee@admin ~]$ pwd

      /home/userLee

      [userLee@admin ~]$ cd ./dir1/

      [userLee@admin dir1]$ pwd

      /home/userLee/dir1

    4. touch

      命令路径:/bin/touch

      执行权限:所有用户

      功能描述:创建空文件

      语法:touch [文件名]

      Ex: touch newfile

      在Linux用户目录下创建newtest文件

      [userLee@admin dir1]$ touch newtest

    5. mkdir

      命令原意:make directories

      命令路径:/bin/mkdir

      执行权限:所有用户

      功能描述:创建新目录

      语法:mkdir [目录名]

      Ex: mkdir newdir

       

      在dir1目录下创建dir2目录并查看

      [userLee@admin dir1]$ mkdir dir2

      [userLee@admin dir1]$ ls

      dir2 file.gz nefile newfile.gz newtest

    6. cp

      命令原意:copy

      命令路径:/bin/cp

      执行权限:所有用户

      功能描述:复制文件或目录

      语法:cp -r [源文件或目录] [目的文件或目录]

      -r 复制目录

      注:可多个文件同时复制。

      [root@admin userLee]# ls dir2/

      dir1 dir_1.tar.gz dir_3

      [root@admin userLee]# cp newfile2 newfile_1 dir2/

      [root@admin userLee]# cp -r newdir/ dir2/

      [root@admin userLee]# ls dir2/

      dir1 dir_1.tar.gz dir_3 newdir newfile_1 newfile2

     

    1. mv

      命令原意:move

      命令路径:/bin/mv

      执行权限:所有用户

      功能描述:移动文件、更名

      语法:mv [文件或目录名] [目的目录]

      Ex: mv file1 file2

      将当前目录下文件file1更名为file2

      mv file2 dir2

      将file2移动到目录dir2下

      [root@admin dir2]# ls

      dir1 dir_1.tar.gz dir_3 newdir newfile_1 newfile2

      [root@admin dir2]# ls dir1/

      file.gz nefile newfile.gz

      [root@admin dir2]# ls dir1/

      file.gz nefile newfile1 newfile.gz

      注意:如上所示,可以在移动到别的目录时更改名字,如果移动别的目录时目录后不加更改后的文件名,默认与原来重名。

       

    2. rm

      命令原意:remove

      命令路径:/bin/rm

      执行权限:所有用户

      功能描述:删除文件

      语法:rm -r [文件或目录]

    -d:直接把欲删除的目录的硬连接数据删除成0,删除该目录;

    -f:强制删除文件或目录;

    -i:删除已有文件或目录之前先询问用户;

    -r或-R:递归处理,将指定目录下的所有文件与子目录一并处理;

    --preserve-root:不对根目录进行递归操作;

    -v:显示指令的详细执行过程。

    Ex: rm file2

    删除文件file2

    rm –r dir1

    删除目录dir1

    [root@admin dir2]# ls

    dir1 dir_1.tar.gz dir_3 newdir newfile2

    [root@admin dir2]# rm -r newfile2 newdir/

    rm:是否删除普通文件 "newfile2"?y

    rm:是否删除目录"newdir"? y

    1. cat

      命令原意:concatenate and display files

      命令路径:/bin/cat

      执行权限:所有用户

      功能描述:显示文件内容

      语法:cat [文件名]

      Ex: cat /etc/issue

      cat /etc/services

    2. more

      命令路径:/bin/more

      执行权限:所有用户

      功能描述:分页显示文件内容

      语法:more [文件名]

      (空格)或f 显示下一页

      (enter) 显示下一行

      q或Q 退出

      Ex: more /etc/services

    3. head

      命令路径:/bin/head

      执行权限:所有用户

      功能描述:查看文件的前几行

      语法:head -num [文件名]

      -num 显示文件的前num行

      Ex: head -20 /etc/services

    4. tail

      命令名称:tail

      命令路径:/bin/tail

      执行权限:所有用户

      功能描述:查看文件的后几行

      语法:tail -num [文件名]

      -num 显示文件的后num行

      -f 动态显示文件内容

      Ex: head -20 /etc/services

    5. ln

      命令原意:link

      命令路径:/bin/ln

      执行权限:所有用户

      功能描述:产生连接文件

      语法:ln -s [源文件] [目标文件]

      -s 创建软连接

       

      Ex: ln –s /etc/issue /issue.soft

      创建文件/etc/issue的软连接/issue.soft

      ln /etc/issue /issue.hard

      创建文件/etc/issue的硬链接/issue.hard

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324844050&siteId=291194637