shell 创建临时目录和临时文件mktemp
来源:互联网 发布:c语言黑客编程pdf 编辑:程序博客网 时间:2024/05/29 02:39
#!/bin/bash
mktemp_local()
{
tempfile=`mktemp temp.XXXXXX` #文件名格式 file.XXXXXX 6个大写X
exec 3>$tempfile
echo -e "\nThis script writes to local temp file $tempfile\n"
echo "This is first line." >&3
echo "This is second line." >&3
echo "This is third line." >&3
echo "Done creating tempfile.The contents are:"
cat $tempfile
rm -f $tempfile 2>/dev/null
}
mktemp_sys()
{
tempfile=`mktemp -t temp.XXXXXX` #在系统临时目录下创建临时文件
exec 3>$tempfile
echo -e "\nThis script writes to sys temp file $tempfile\n"
echo "This is first line." >&3
echo "This is second line." >&3
echo "This is third line." >&3
echo "Done creating tempfile.The contents are:"
cat $tempfile
rm -f $tempfile 2>/dev/null
}
mktemp_dir()
{
tempdir=`mktemp -d ./tmpd.XXXXXX` #创建临时目录
cd $tempdir
tempf_a=`mktemp tempf.XXXXXX` #创建本地临时文件
tempf_b=`mktemp tempf.XXXXXX`
exec 7>$tempf_a
exec 8>$tempf_b
echo "This is a test file for temp file:$tempf_a" >&7
echo "This is a test file for temp file:$tempf_b" >&8
echo -e "\nTempdir contents:\n"
echo "$tempf_a contents:"
cat $tempf_a
echo "$tempf_b contents:"
cat $tempf_b
cd - #返回原来的路径
echo -e "\nThe tempd is here:"
ls -d $tempdir
echo -e "\nrm the tempd is here:"
rm $tempdir -rf 2>/dev/null
}
mktemp_local
mktemp_sys
mktemp_local()
{
tempfile=`mktemp temp.XXXXXX` #文件名格式 file.XXXXXX 6个大写X
exec 3>$tempfile
echo -e "\nThis script writes to local temp file $tempfile\n"
echo "This is first line." >&3
echo "This is second line." >&3
echo "This is third line." >&3
echo "Done creating tempfile.The contents are:"
cat $tempfile
rm -f $tempfile 2>/dev/null
}
mktemp_sys()
{
tempfile=`mktemp -t temp.XXXXXX` #在系统临时目录下创建临时文件
exec 3>$tempfile
echo -e "\nThis script writes to sys temp file $tempfile\n"
echo "This is first line." >&3
echo "This is second line." >&3
echo "This is third line." >&3
echo "Done creating tempfile.The contents are:"
cat $tempfile
rm -f $tempfile 2>/dev/null
}
mktemp_dir()
{
tempdir=`mktemp -d ./tmpd.XXXXXX` #创建临时目录
cd $tempdir
tempf_a=`mktemp tempf.XXXXXX` #创建本地临时文件
tempf_b=`mktemp tempf.XXXXXX`
exec 7>$tempf_a
exec 8>$tempf_b
echo "This is a test file for temp file:$tempf_a" >&7
echo "This is a test file for temp file:$tempf_b" >&8
echo -e "\nTempdir contents:\n"
echo "$tempf_a contents:"
cat $tempf_a
echo "$tempf_b contents:"
cat $tempf_b
cd - #返回原来的路径
echo -e "\nThe tempd is here:"
ls -d $tempdir
echo -e "\nrm the tempd is here:"
rm $tempdir -rf 2>/dev/null
}
mktemp_local
mktemp_sys
mktemp_dir
#要点
mktemp 命令及选项
没有选项时建立本地临时文件
-t 在系统的临时目录/tmp 下建立临时文件
-d 建立临时目录
- shell 创建临时目录和临时文件mktemp
- Linux:使用mktemp创建临时文件/目录
- 创建临时文件 临时目录
- java 创建临时临时文件
- java 创建临时临时文件
- 创建临时文件——tmpnam,tmpfile,mktemp,mkstemp
- mktemp :建立暂存/临时文件
- shell创建临时文件
- 第4章 处理用户输入与显示数据------------(创建本地临时文件、在/temp中创建临时文件、创建临时目录、tee命令)
- 获取Windows 临时文件目录 和临时文件
- 创建和使用临时文件
- java 创建文件-创建目录-创建临时文件
- mktemp
- mktemp
- 8.6 tempfile--临时文件和目录处理
- 创建临时文件
- 创建临时文件
- 创建临时文件
- OpenCV学习笔记(十八)——图像的各种变换(cvtColor*+)imgproc
- android之自定义ViewGroup和自动换行的布局的实现
- 嵌入式Tomcat的使用(即使用java代码控制tomcat服务)
- VS2011写驱动
- 多线程的那点儿事(之数据同步)
- shell 创建临时目录和临时文件mktemp
- 多线程那点事儿(之数据互斥)
- 函数返回值—返回局部变量
- service的隐式启动和显示启动
- 文件上传
- IP地址、域名、DNS、网址之间的区别
- 鼠标进入与离开的消息
- listview 长按效果
- Oracle 数据库备份自动执行脚本_For_Windows