linux命令学习一 :touch和mkdir 创建文件和文件夹

一、查看命令详情

touch --help

mkdir --help  

二、常用命令

1、创建文件:  touch  filename

2、创建文件夹:mkdir  directoryname 
     可创建父文件夹或创建多个或创建多级文件夹 mkdir -p  parentdir/directoryname
     创建目录同时复权 mkdir -m 权限   directoryname

三、命令详细说明

touch命令:

touch: 命令参数:

-a   或--time=atime或--time=access或--time=use  只更改存取时间。

-c   或--no-create  不建立任何文档。

-d  使用指定的日期时间,而非现在的时间。

-f  此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。

-m   或--time=mtime或--time=modify  只更改变动时间。

-r  把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。

-t  使用指定的日期时间,而非现在的时间。



touch:命令功能:

touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间。 


touch:实例

实例一:创建不存在的文件

命令:

touch log2012.log log2013.log

输出:

[root@localhost test]# touch log2012.log log2013.log

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log

如果log2014.log不存在,则不创建文件

[root@localhost test]# touch -c log2014.log

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log

实例二:更新log.log的时间和log2012.log时间戳相同

命令:

touch -r log.log log2012.log

输出:

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 16:01 log2012.log

-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

[root@localhost test]# touch -r log.log log2012.log 

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

实例三:设定文件的时间戳

命令:

touch -t 201211142234.50 log.log

输出:

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root    0 10-28 14:48 log.log

[root@localhost test]# touch -t 201211142234.50 log.log

[root@localhost test]# ll

-rw-r--r-- 1 root root    0 10-28 14:48 log2012.log

-rw-r--r-- 1 root root    0 10-28 16:01 log2013.log

-rw-r--r-- 1 root root    0 2012-11-14 log.log


mkdir命令:

1.mkdir:命令功能:

通过 mkdir 命令可以实现在指定位置创建以 DirName(指定的文件名)命名的文件夹或目录。要创建文件夹或目录的用户必须对所创建的文件夹的父文件夹具有写权限。并且,所创建的文件夹(目录)不能与其父目录(即父文件夹)中的文件名重名,即同一个目录下不能有同名的(区分大小写) 

2.mkdir:命令参数:

  -m, --mode=模式,设定权限<模式> (类似 chmod),而不是 rwxrwxrwx 减 umask

  -p, --parents  可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录; 

  -v, --verbose  每次创建新目录都显示信息

      --help   显示此帮助信息并退出

      --version  输出版本信息并退出

3、mkdir实例

  实例1递归创建多个目录 

命令:

mkdir -p test2/test22


实例2递归创建多个目录 

命令:

mkdir -p test2/test22


实例3创建权限为777的目录 

命令:

mkdir -m 777 test3


实例4、命令:

mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}

输出:

[root@localhost test]# mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}

mkdir: 已创建目录 scf

mkdir: 已创建目录 scf/lib

mkdir: 已创建目录 scf/bin

mkdir: 已创建目录 scf/doc

mkdir: 已创建目录 scf/doc/info

mkdir: 已创建目录 scf/doc/product

mkdir: 已创建目录 scf/logs

mkdir: 已创建目录 scf/logs/info

mkdir: 已创建目录 scf/logs/product

mkdir: 已创建目录 scf/service

mkdir: 已创建目录 scf/service/deploy

mkdir: 已创建目录 scf/service/deploy/info

mkdir: 已创建目录 scf/service/deploy/product

[root@localhost test]# tree scf/

scf/

|-- bin

|-- doc

|   |-- info

|   `-- product

|-- lib

|-- logs

|   |-- info

|   `-- product

`-- service

    `-- deploy

      |-- info

        `-- product

12 directories, 0 files

[root@localhost test]#




  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
// // FilePath.h // /** \file FilePath.h */ #pragma once #include "vtString.h" #include <fstream> #include <io.h> /** * A portable class for reading directory contents. * * Example of use: \code for (dir_iter it("C:/temp"); it != dir_iter(); ++it) { if (it.is_hidden()) continue; if (it.is_directory()) printf("Directory: '%s'\n", it.filename().c_str()); else printf("File: '%s'\n", it.filename().c_str()); } \endcode */ class dir_iter { public: dir_iter(); dir_iter(const char*dirname); dir_iter(const wchar_t*dirname); ~dir_iter(); /// Returns true if the current object is a directory. bool is_directory(); /// Returns true if the current object is hidden. bool is_hidden(); /// Get the filename fo the current object. std::string filename(); std::wstring wfilename(); // Iterate the object to the next file/directory. void operator++(); // Test for inequality useful to test when iteration is finished. bool operator!=(const dir_iter &it;); long m_handle; private: struct _wfinddata_t m_data; }; //MBCS string 或者 Wide string vtString vtFindFileOnPaths(const vtStringArray &paths;, const char *filename); vtString2 vtFindFileOnPaths(const vtStringArray2 &paths;, const wchar_t *filename); bool vtCreateDir(const char *dirname); bool vtCreateDir(const wchar_t *dirname); void vtDestroyDir(const char *dirname); void vtDestroyDir(const wchar_t *dirname); int vtDeleteFile(const char *filename); int vtDeleteFile(const wchar_t *filename); const char *vtStartOfFileName(const char *szFullPath); const wchar_t *vtStartOfFileName(const wchar_t *szFullPath); vtString vtExtractPath(const char *szFullPath, bool bTrailingSlash); vtString2 vtExtractPath(const wchar_t *szFullPath, bool bTrailingSlash); bool vtPathIsAbsolute(const char *szPath); bool vtPathIsAbsolute(const wchar_t *szPath); vtString vtPathLevelUp(const char *src); vtString2 vtPathLevelUp(const wchar_t *src); vtString get_line_from_stream(std::ifstream &input;); vtString2 get_line_from_stream(std::wifstream &input;); //bFull为ture包括所有扩展名;否则最后一个扩展名 void vtRemoveFileExtensions(vtString& fname,bool bFull = false); void vtRemoveFileExtensions(vtString2& fname,bool bFull = false); //bFull为ture包括所有扩展名;否则最后一个扩展名 vtString vtGetExtensions(const vtString &fname;, bool bFull = false); vtString2 vtGetExtensions(const vtString2 &fname;, bool bFull = false); bool vtChangeFileExtension(vtString& input, const char *extension); bool vtChangeFileExtension(vtString2& input, const wchar_t *extension); bool vtFileExists(const char *fname); bool vtFileExists(const wchar_t *fname); #pragma comment(lib, "shell32.lib") bool vtCopyFile( const char* from,const char * to, bool bFailIfExists=true); bool vtCopyFile( const wchar_t* from,const wchar_t * to, bool bFailIfExists=true); bool vtCopyTree(const char* from,const char * to); bool vtCopyTree(const wchar_t* from,const wchar_t * to); bool vtFolderExists(const char *fname); bool vtFolderExists(const wchar_t *fname); bool vtFilePathExists(const char *fname); bool vtFilePathExists(const wchar_t *fname); int vtGetFileSize(const char *fname); int vtGetFileSize(const wchar_t *fname); void vtSetEnvironmentVar(const char* var, const char*value); void vtSetEnvironmentVar(const wchar_t* var, const wchar_t*value); #include "windows.h" bool vtGetModuleFullPath(const char* modulename,vtString& fullpath); bool vtGetModuleFullPath(const wchar_t* modulename,vtString2& fullpath); ///////////////////////////////////////////// // Open a file using a UTF-8 or wide character filename. FILE *vtFileOpen(const char *fname_mbcs, const char *mode); FILE *vtFileOpen(const wchar_t *fname_wide, const wchar_t *mode); vtString vtChooseFolder(HWND hWnd =NULL); vtString2 vtChooseFolder2(HWND hWnd=NULL);

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值