- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试制作一个 linux 脚本来更新一些列表,其中带有时间戳。
我正在努力的部分是:
for dir in $(ls)
do
echo $dir
done
我得到:
noreply-unsch-simco 2014-03-17-14:20:41.txt
noreply-unsch-simcoe 2014-03-17-14:20:41.txt
noreply-unsch-sudbury-nbay 2014-03-17-14:20:41.txt
noreply-unsch-test 2014-03-17-14:20:41.txt
noreply-unsch-thunderbay 2014-03-17-14:20:41.txt
noreply-unsch-toronto 2014-03-17-14:20:41.txt
noreply-unsch-york 2014-03-17-14:20:41.txt
我想要做的是删除旧文件(如果它们存在),因为每次我的脚本运行时,它都会创建一个带有新时间戳的新文件。
所以基本上我想知道如何仅使用名称的开头部分(时间戳之前的所有内容)搜索文件。
我是新手。请帮助我
编辑:好的,所以我查看了评论,但出现错误。这是我的完整代码。
#!/bin/bash
cd /var/lib/mailman/lists/
variable=$(date +"%Y-%m-%d-%H:%M:%S")
for dir in $(ls)
do
echo $dir
rm /root/Desktop/Dan/Lists/$dir-*
echo echo | cat | list_members $dir/ > /root/Desktop/Dan/Lists/$dir" "$variable.txt
done
我遇到了找不到目录错误。
编辑我只需要去掉'-'
rm /root/Desktop/Dan/Lists/$dir*
谢谢!
最佳答案
如果你想删除所有以特定扩展名开头的文件,你可以这样做:
rm noreply-unsch-*
这将删除所有匹配该模式的文件。如果你想做的不仅仅是删除 ;您可以将循环更改为:
for filename in noreply-unsch-*.txt; do
#something
rm $filename
done
关于linux - 如何在没有文件全名的情况下检查文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22462445/
我正在尝试用此人的全名填充 Yii2 中的下拉列表,名字和姓氏在我的数据库中的不同列中。 在我的个人表中 编号 名字 姓氏 dep_id (fk) ... 在我的 Person.php 模型中有 pu
我目前正在像这样连接名字和姓氏(使用 PostgreSQL): concat(customers.firstname, ' ', customers.lastname) 我在这里遇到的问题是我的客户只
从 (new Date()).toString() 返回的字符串看起来像这样: "Tue Nov 22 2016 14:14:51 GMT-0800 (Pacific Standard Time)"
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
已经将近 3 天了,我仍然无法修复该错误。简单的情况,我想搜索人名(姓名和姓氏)。 示例: 首先我写给 John(结果:John Newman、John Stable、John Carens) 然后我
我在我的项目中使用 Laravel 5.3,我试图获取多个列并在 View 的下拉选择元素中显示数据。我正在做这样的查询: $users = User::select( DB:
我目前正在使用此脚本从给定路径中提取名称、文件夹、文件夹名称: Get-ChildItem "C:\user\desktop" | Select Name, ` @{ n = 'Folde
我通过在 ApplicationUser 中添加几个字段扩展了 ASP NET 身份架构。派生自 IdentityUser 的类.我添加的字段之一是 FullName . 现在,当我写 User.Id
我正在开发一个 Android 应用程序,其中任何使用我们的应用程序登录到 Facebook 的 Android 用户,我需要从 Facebook 中提取他的照片、他的性别和他的全名。我正在为此使用
我是一名优秀的程序员,十分优秀!