Bash 文件夹操作

  • mkdir, rm,find都是对tree结构的文件夹进行的操作,可以安装tree用tree命令直接打印出树的结构
  • 文件夹的操作分为只操作当前文件夹的集合数据和迭代操作的tree数据

Bash迭代当前文件夹

ls---list information about the FILES(the current directory by default)[du也统计文件大小,但是du使用的是tree的数据结构,ls则是数组的数据结构]

ls -author #罗列文件信息包含作者
ls -c -lt #根据访问时间倒序排列
ls  -c #list entries by columns
ls -d #list directory entries instead of contents and don't
 dereference symbolic links
ls -l  -h # print sizes in human readable format
ls -l ./ceshi/ceshi #罗列第三级文件夹ceshi

Bash迭代文件夹树

tree命令

Bash创建文件夹

mkdir---make directoryes

     -p---no error if existing,make parent directories as needed(带着-p参数,会自动判断只有当文件夹不存在的时候才创建,可以创建多层次目录)

mkdir newdir #第一次创建不存在的目录newdir成功
mkdir newdir #第二次创建已经存在的newdir失败
mkdir -p newdir#成功
mkdir -p newdir/firse/second/thired/#可以一次创建多级目录

    mkdir可以创建一个完整的项目目录结构

mkdir -p project/{lib/ext,bin,src/doc/{html,info,pdf},demo/stat}#执行完成后,当前目录下后出现一个当前结构【原文借鉴

Bash删除文件和文件夹

rm---rm removes each specified file.By default ,it does not remove directories.

  -i---prompt before ervry removal

  -r---remove directories and their contents recursively.

rm -i -r project#删除文件夹project和文件夹下的全部内容

Bash查找搜索文件夹

find---find searches the directory tree rooted at each given file name by evaluating the given expression from left to right,according to the rules of percedence,util the outcome is known,at which point find moves on to the next file name.(在目录树上搜索结果)

  -name---Base of file name matches shell pattern pattern.(根据文件名字匹配搜索)【详细用法参考

find  './软件' -name '*.txt' #查找当前目录下的软件文件夹下,所有以txt结尾的文件
find '.' -user harvey#查找属于用户harvey的文件
find '.' -mtime -1#一天以内修改的文件
find '.' -ctime -1#一天以内创建的文件
find '.' -ctime -1 -name '*.txt'#今天创建的文本文件
find . -size +1000000c #查找文件大于1M的文件

Bash统计文件夹下所有文件的大小

du---summarize disk usage of each FILE,recursively for directories(递归的统计磁盘的使用情况)

-h---print sizes in human readable format(e.g.,1k 234M 2G)

du -h '.' #统计当前文件夹下各文件使用磁盘的情况

Bash移动文件

 mv---Rename SOURCE to DEST or move SOURCE(s) to DIRECTOR.

mv test.txt x.txt #当前目录下的test.txt重命名为x.txt
mv x.txt ./ceshi/x.txt #移动x.txt到测试文件夹下

 Bash复制文件

cp kkkk.txt k1.txt # 在当前文件夹下复制文件
cp kkkk.txt ./ceshi/k2.txt #复制文件到新的文件夹

    

原文地址:https://www.cnblogs.com/zhanghaiyublog/p/3593569.html