ubuntu终端常用命令-文件(1)、系统与快捷键

本文详细介绍了Linux系统中常用的文件与目录管理命令(如pwd、cd、cp、mv、rm、mkdir)、系统信息查看命令(如df、du、free、top、uname、lsb_release、ifconfig、adduser)以及快捷键操作,涵盖了从基本文件操作到系统管理的全面指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 pwd 显示当前路径

<span style="font-size:14px;">pwd: pwd [-LP]
    Print the name of the current working directory.
    
    Options:
      -L	print the value of $PWD if it names the current working directory
      -P	print the physical directory, without any symbolic links
    
    By default, `pwd' behaves as if `-L' were specified.
</span>

2 cd 更改工作路径

<span style="font-size:14px;">cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the HOME shell variable.
    
    The variable CDPATH defines the search path for the directory containing DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins with a slash (/), then CDPATH is not used.
    
    If the directory is not found, and the shell option `cdable_vars' is set, the word is assumed to be  a variable name.  If that variable has a value, its value is used for DIR.
    
    Options:
        -L	force symbolic links to be followed: resolve symbolic links in DIR after processing instances of `..'
        -P	use the physical directory structure without following symbolic links: resolve symbolic links in DIR before processing instances	of `..'
        -e	if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status
        -@   on systems that support it, present a file with extended attributes as a directory containing the file attributes
    
    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component back to a slash or the beginning of DIR.
</span>

3 cp 复制单个或多个文件/文件夹

常用:

<span style="font-size:14px;">cp 源文件名 新文件名</span>


4 mv 移动文件/更改文件名

改名:

<span style="font-size:14px;">mv 源文件名 新文件名</span>
移动:
<span style="font-size:14px;">mv 源文件名 新目录</span>

5 rm 删除文件/文件夹
<span style="font-size:14px;">rm [选项]... 文件...
Remove (unlink) the FILE(s).

  -f, --force           ignore nonexistent files and arguments, never prompt
  -i                    prompt before every removal
  -I			在删除超过三个文件或者递归删除前要求确认。此选项比-i 提示内容更少,但同样可以阻止大多数错误发生
      --interactive[=WHEN]	根据指定的WHEN 进行确认提示:never,once (-I),或者always (-i)。如果此参数不加WHEN 则总是提示
      --one-file-system		递归删除一个层级时,跳过所有不符合命令行参数的文件系统上的文件
      --no-preserve-root  do not treat '/' specially
      --preserve-root   do not remove '/' (default)
  -r, -R, --recursive   remove directories and their contents recursively(注:可用于删除目录及其下文件)
  -d, --dir             remove empty directories
  -v, --verbose         explain what is being done
      --help		显示此帮助信息并退出
      --version		显示版本信息并退出

默认时,rm 不会删除目录。使用--recursive(-r 或-R)选项可删除每个给定的目录,以及其下所有的内容。

To remove a file whose name starts with a '-', for example '-foo',use one of these commands:
  rm -- -foo
  rm ./-foo

请注意,如果使用rm 来删除文件,通常仍可以将该文件恢复原状。如果想保证该文件的内容无法还原,请考虑使用shred。</span>

6 mkdir 新建目录
<span style="font-size:14px;">mkdir [选项]... 目录...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=模式   	设置权限模式(类似chmod),而不是rwxrwxrwx 减umask
  -p, --parents     	需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理</span>

(以下参考百度文库
7 man 显示其他命令的手册

<span style="font-size:14px;">相关命令:man command, info command and command --help
按键:方向键移动手册页面,用"q"退出
"man man"查看man命令的手册页
"man intro"查看 "用户命令介绍"(一份简单的linux命令介绍) 
info命令通常比man深入,man命令无效时也可以尝试info
搜索man文件: 
    man -k foo 会搜索关于foo的man文件
    man -f foo 仅仅搜所系统man文件的标题</span>

8 tar 解压缩

<span style="font-size:14px;">格式: tar 选项 文件目录列表
功能:对文件目录进行打包备份
选项:
-c 建立新的归档文件
-r 向归档文件末尾追加文件
-x 从归档文件中解出文件
-O 将文件解开到标准输出
-v 处理过程中输出相关信息
-f 对普通文件操作
-z 调用gzip来压缩归档文件,与-x联用时调用gzip完成解压缩
-Z 调用compress来压缩归档文件,与-x联用时调用compress完成解压缩
  
例如: 
1.将当前目录下所有.txt文件打包并压缩归档到文件this.tar.gz,我们可以使用
tar czvf this.tar.gz ./*.txt
2.将当前目录下的this.tar.gz中的文件解压到当前目录我们可以使用
tar xzvf this.tar.gz ./</span>

9 系统信息类命令

<span style="font-size:14px;">    df:df命令用来查看各个文件系统当前的空间使用状况。"df -h"可能是最有用的选项了-它以M和G为单位输出,而不是以块为单位。(-h 的含义是“便于阅读”)  
    du:du命令可以显示某一个目录使用了多少磁盘空间。它可以显示该目录中的各个子目录分别使用了多少空间,也可以显示当前目录一共占了多少空间。  
    -s 代表”概况、总览“,-h 则代表”易于人阅读“。  
    free:free命令用来查看系统中使用和剩馀的内存情况。"free -m" 将结果以M为单位输出,这对现在的计算机来说非常有用。  
    top:top 命令用来查看linux系统的信息,运行着的进程和系统资源,包括 CPU、内存以及交换分区使用情况和运行着的任务的总的数量。退出 top ,按"q"。  
    uname -a:uname命令的 -a 参数用来查看系统的所有信息,包括机器名,内核名称 & 版本 和一些其它的细节。它最大的用处是用来查看当前所用内核的信息。  
    lsb_release -a:lsb_release命令的-a参数查看当前运行的linux的版本信息  
    ifconfig:显示当前系统的网络接口信息。  
    adduser newuser:创建一个用户名为"newuser"的新用户(为新用户 newuser 创建一个密码,使用如下命令"passwd newuser")</span>

10 快捷键

<span style="font-size:14px;">Up Arrow or ctrl+p:滚动显示你之前输入的命令(译者注,与msdos相似) 
Down Arrow or ctrl+n:回到较近的命令
tab:如果只有一个选项,则自动补全命令或文件名;否则给出所有选项的列表。
ctrl+r:搜索你已经输入的命令.当你已经输入了一条很长很复杂的命令并且要重复它时, 使用这个按键组合,然后输入命令的一部分将会从你的集合历史中搜索. 找到它后,只要轻轻按下回车
ctrl+a or Home:移动游标到行首
ctrl+e or End:移动游标到行尾
ctrl+b:移动游标到上一个或当前单词的前面
ctrl+k:删除从当前游标到行尾的文字
ctrl+u:删除当前整行
ctrl+w:删除游标前的单词. 
</span>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值