linux文件目录操作_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文件和目录操作。 我们将研究这些操作以涵盖基础知识。 在本教程中,我们将学习lscdmv类的命令。

列出目录和文件 (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 Directories and Files
List Directories and Files
列出目录和文件

列出隐藏的文件和目录(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
List Hidden Files and Directories
List Hidden Files and Directories
列出隐藏的文件和目录

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
List Files and Folders Recursively
List Files and Folders Recursively
递归列出文件和文件夹

变更目录(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 /
Change Directory
Change Directory
变更目录

转到用户主目录(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
Go Given Path
Go Given Path
给定路径

显示工作目录(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
Show Working Directory
Show Working Directory
显示工作目录

删除文件和目录(Delete File and Directory)

We may need to delete a file or folder. rm and rmdir are commands used to delete file and directories.

我们可能需要删除文件或文件夹。 rmrmdir是用于删除文件和目录的命令。

$ 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选项将使删除递归强制执行。

LEARN MORE  Linux pwd Command Tutorial With Examples
了解更多Linux pwd命令教程和示例

移动文件和目录(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文件目录操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值