我不确定这是否会在当天获得过去的日期,或者是否只需要 30 或 31 天。
例如
如果当前日期是March 28th,则必须是 1 个月前February 28th,但是当它是 时会发生什么March 30th?
设想
我想每天备份一些文件,脚本将在当前日期内保存这些文件,$(date +%Y%m%d)格式20150603_bckp.tar.gz为我的条件:
past_month = $(date -d "-1 month" +%Y%m%d)
day = $(date +%d)
if [ "$day" != 01 ] && [ "$day" != 15 ]
then
rm /path/of/files/${past_month}_bckp.tar.gz
echo "Depuration done"
else
echo "Keep file"
fi
Run Code Online (Sandbox Code Playgroud)
但是我想知道,当日期是 30 日、31 日甚至过去的二月示例时会发生什么?它会保留那些文件吗?或删除第一天的文件?
当它是 31 日时,净化将执行,所以如果过去一个月只有 30 天,这将删除第 1 天的文件?
我希望我有所暗示。
我发现自己<command> --help | grep <feature>每天都在做非常非常频繁的事情。我想知道是否有可能使类似的东西^^扩展到"--help | grep"然后我这样做:
ls ^^ size
Run Code Online (Sandbox Code Playgroud)
这将执行以下操作:
ls --help | grep size
Run Code Online (Sandbox Code Playgroud) 我经常更改每天生成的某些文件的位置。问题是我只想通过添加新的必需字符来更改他们的名字。
我想要的是这样的:
$ mv file.csv /home/user/{something}_backup1
Run Code Online (Sandbox Code Playgroud)
所以我可以看到:
$ ls /home/user
file.csv_backup1
Run Code Online (Sandbox Code Playgroud)
我现在做的很简单:
$ mv file.csv /home/user/file.csv_backup1
Run Code Online (Sandbox Code Playgroud)
你可以说“不要偷懒,那样做”,问题是真正的文件名大约有 25 个字符,重新输入它们真的很烦人。
给出的过去只是一个例子,它可以是不同的目录或不同的新文本。
顺便说一句,我正在使用 bash shell
我明白这意味着强制做某事。
这样做时$ vim -R file我进入read-only模式,但这仅作为预防模式起作用
-R Readonly mode. The 'readonly' option will be set for all the
files being edited. You can still edit the buffer, but will
be prevented from accidentally overwriting a file. If you
forgot that you are in View mode and did make some changes,
you can overwrite a file by adding an exclamation mark to
the Ex command, as in ":w!". The 'readonly' option can be
reset with ":set …Run Code Online (Sandbox Code Playgroud) 我正在阅读活动日志并尝试接到一些特殊电话
$ tail -f example.log | egrep 'pattern1|pattern2|pattern3|pattern4|pattern5'
Run Code Online (Sandbox Code Playgroud)
但是有几个图案几乎没有打印出来(由于开发流程),而另一个则非常连续地打印。
我怎样才能让egrep每个图案只打印一个请求,这样我就可以很容易地看到它们运行良好。
文件#1:
I have foofoo
You have foobar
she/he has foo
Run Code Online (Sandbox Code Playgroud)
文件#2:
bar
foobar
barfoo
Run Code Online (Sandbox Code Playgroud)
最终的:
I have foofoobar
You have foobarfoobar
she/he has foobarfoo
Run Code Online (Sandbox Code Playgroud) 当我错误地输入“ñ”(希望输入任何命令)然后将其删除并输入正确的字母时,输出返回带有特殊字符的命令?,显然 shell 无法识别该命令,我必须重新输入小心不要再次输入“ñ”字符。
例如
Wrong typing @tachomi:~$ ñs
Correct typing @tachomi:~$ ls
Output ?ls: command not found
Run Code Online (Sandbox Code Playgroud)
我认为这种字符ñ , '等与外壳不兼容,这是“内存”保留它无法识别的东西的原因,但我想确定为什么会发生这种情况。
我正在使用 bash shell
我认为这会很简单,但不知道如何去做。
设想
我有一个.csv带有id_user, text,id_group列的单个文件,其中每一列都由tabs如下分隔:
"123456789" "Here's the field of the text, also contains comma" "10"
"987456321" "Here's the field of the text, also contains comma" "10"
"123654789" "Here's the field of the text, also contains comma" "11"
"987456123" "Here's the field of the text, also contains comma" "11"
Run Code Online (Sandbox Code Playgroud)
如何找到文本?
试图
awk
我正在寻找一种指定print $n分隔符的方法,如果可以的话,一个选项将是
$ awk -d '\t' '{print $2}' file.csv | sed -e 's/"//gp'
Run Code Online (Sandbox Code Playgroud)
选项-d的分隔符print和 …
我有以下字符串
y10_zcis y10_nom y10_infl y20_zcis y20_infl y30_zcis
Run Code Online (Sandbox Code Playgroud)
我想将其转换为
"y10_zcis", "y10_nom", "y10_infl", "y20_zcis", "y20_infl", "y30_zcis"
Run Code Online (Sandbox Code Playgroud)
我用极其丑陋的方式完成了类似的事情:
$ cat in.txt | sed 's/ /\'$'\n/g' | sed 's/\(.*\)/"\1",/g' | tr -d '\n'
"y10_zcis","y10_nom","y10_infl","y20_zcis","y20_infl","y30_zcis",
Run Code Online (Sandbox Code Playgroud)
但这感觉完全失败了,它没有处理最后一个不需要的,(但也许最好在之后删除)
假设我有一行文本如下:
I have a nice car
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以在不将行保存到任何文件的情况下分别在不同位置获取行的不同单词(例如,我想获得“有”和“不错”的部分)。我的意思是,我想应用这样一种方法,它会直接在给定行的所需位置给我单词。有什么办法吗?
最近,我要求我的托管服务提供商重新加载操作系统,Ubuntu 12.04 64 bit minimal假设最小安装了所需的最少软件包,但我意识到 mysql 已安装,因为我不需要它,我想卸载与其相关的所有软件包。
我所做的是:
$ sudo apt-get --purge remove mysql-client
$ sudo apt-get --purge remove mysql-server
Run Code Online (Sandbox Code Playgroud)
但是我仍然在寻找 mysql 二进制文件和文件
$ whereis mysql
mysql: /usr/bin/mysql /etc/mysql /usr/bin/X11/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
Run Code Online (Sandbox Code Playgroud)
我在想像
$ dpkg -s mysql*
Run Code Online (Sandbox Code Playgroud)
但这没有帮助。
有什么建议吗?
我想将该变量声明为 shell 脚本的命令行参数,就像
./script.sh
file=/tmp/domains.txt
domain=abcd.com**
Run Code Online (Sandbox Code Playgroud)
帮助做同样的事情。