linux文件目录操作_Linux目录和文件操作
linux文件目录操作
Most basic Linux usage starts with Linux file and directory operations. We will look at these operations to cover basics. In this tutorial, we will learn commands like ls
, cd
, mv
.
Linux的大多数基本用法始于Linux文件和目录操作。 我们将研究这些操作以涵盖基础知识。 在本教程中,我们将学习ls
, cd
, mv
类的命令。
列出目录和文件 (List Directories and Files)
Start of the navigation in the file system starts with listing the directories and files. We will use the ls
command which will list current working directory files and folders.
文件系统中导航的开始从列出目录和文件开始。 我们将使用ls
命令,该命令将列出当前的工作目录文件和文件夹。
$ ls
列出隐藏的文件和目录(List Hidden Files and Directories)
All operating systems have hidden files to hide them from use. It is not a security-related feature. It related to operation and reliability. Showing configuration files in the home directory have no benefits. So by default hiding them is better.
所有操作系统都有隐藏文件,以使其无法使用。 它不是与安全相关的功能。 它关系到操作和可靠性。 在主目录中显示配置文件没有任何好处。 因此,默认情况下隐藏它们会更好。
$ ls -a
We can see that files and folders like .cpan
, .npm
, .config
etc. are listed with the help of -a
option.
我们可以看到.cpan
, .npm
, .config
等文件和文件夹是在-a
选项的帮助下列出的。
递归列出文件和文件夹 (List Files and Folders Recursively)
We can all child files and directories by providing the recursive option. We will provide the -R
option which will list files and folders recursively.
通过提供递归选项,我们可以所有子文件和目录。 我们将提供-R
选项,该选项将递归列出文件和文件夹。
$ ls -R
变更目录(Change Directory)
cd
or change directory command can be used to change to the different directories. We can provide just the relative or complete path to the cd command.
cd
或change directory命令可用于更改到不同目录。 我们可以提供cd命令的相对或完整路径。
$ cd /
转到用户主目录(Go User Home Directory)
We can go to the home directory by using ~
tilde which means current user home.
我们可以使用~
波浪号转到主目录,这表示当前用户的主目录。
$ cd ~
进入上层/父母目录 (Go Upper/Parent Directory)
We can go to the upper directory with double point ..
which means parent directory
我们可以使用双点..
转到上一级目录,这意味着父目录
$cd ..
给定路径 (Go Given Path)
We can go to the log directory
我们可以转到日志目录
$ cd /var/log
显示工作目录(Show Working Directory)
We can work different systems and directories in day to day operation. We may not remember the current directory of the shell. We can get the current working directory with pwd command.
我们可以在日常操作中处理不同的系统和目录。 我们可能不记得外壳程序的当前目录。 我们可以使用pwd命令获取当前的工作目录。
$ pwd
删除文件和目录(Delete File and Directory)
We may need to delete a file or folder. rm and rmdir are commands used to delete file and directories.
我们可能需要删除文件或文件夹。 rm和rmdir是用于删除文件和目录的命令。
$ rmdir output/
rmdir: failed to remove 'output/': Directory not empty
I can not delete the directory because there are files or directories in it. We can force for deletion
我无法删除目录,因为其中有文件或目录。 我们可以强制删除
$ rm -Rf output
-
-Rf option will make deletion recursive and forcibly.
-Rf选项将使删除递归强制执行。
移动文件和目录(Move Files and Directories)
We can use mv command to move files and directories
我们可以使用mv命令移动文件和目录
$ mv mycommand yourcommand
$ mv output/ output2
翻译自: https://www.poftut.com/linux-directory-file-operations/
linux文件目录操作
上一篇: 物联网+金融,被称为天作之合
下一篇: python函数 - bool([x])