学些了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
<