Linux-Shell之文件操作

本文详细介绍了Linux Shell中对文件的“增删看改查”操作。内容涵盖创建、删除、查看文件属性、更改文件属性及查找文件的命令,如mkdir、touch、rm、ls、chmod、find等,帮助读者更好地掌握Linux文件操作。
摘要由CSDN通过智能技术生成

  学些了Linux Shell命令行使用,对于文件的操作除了记下来,但还没有找到相应方法掌握,常常混乱。数据库有“增删改查”,因而同样按理来分类文件操作方法,较为清晰。同时作为文件,有权限、大小等文件属性,因而加入“看”来看文件属性。这样就变为“增删看改查”。

1. 文件操作之“增”——创建文件/目录
  • mkdir——创建目录
mkdir dir1 dir2 dir3      # create multiple directories
mkdir -m 777 dir          # new directory with specific permissions
mkdir -p pdir/cdir        # where pdir may not exist
mkdir -v dir              # echo message when new directory created
  • touch——创建文件
touch file1 file2 file3   # create multiple files with various type
  • cp / mv —— 复制和移动文件,相当于创建了新文件。
cp dir1/file dir2/file    # copy file
cp -r dir1/ dir2/         # copy directory
cp dir/*.txt dir2/*.txt   # copy files with regex

mv dir/a.txt dir2/a.txt   # move file, change its path
mv -f a.txt b.txt         # move and rename file, forcible
mv dir/*.txt dir2/*.txt   # move files with regex
  • 重定向—创建文件
>  file                   # redirect output to file
>> file                   # redirect and append output to file
  • vi ———创建文件
vi file1 file2 file3      # vim-create multiple files :n(next file) :N(the last)
  • gedit——创建文件
gedit file                # only create one file once in .txt format
  • nano——创建文件
nano file                 # only create one file once in .txt format
  • ln——创建链接文件
ln file filelink          # hard link file
<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值