m.s*_*tos 2 linux bash ls path
我试图在Linux中编写一个非常简单的脚本.
我先告诉你代码:
#!/bin/bash
# The shell program uses glob constructs and ls
# to list all entries in testfiles, that have 2
# or more dots "." in their name.
ls -l /path/to/file/*.*.*
Run Code Online (Sandbox Code Playgroud)
当我使用bash myscript
命令运行此代码时,我得到类似:/ path/to/file/file.with.three.dots
但我不想要这个.我只想显示文件名,而不是路径.
然后我尝试了:
ls -l *.*.*
Run Code Online (Sandbox Code Playgroud)
但是这次只显示我在/ path/to/file /中的文件.
如何设置路径,所以当从任何地方运行脚本时,它会将/ path /中的文件名输出到/ file /?
谢谢!
basename path/to/file.b.c
应该给你file.bc
无论如何重新阅读这个问题,我认为这是一个暂时cd
的路径然后ls
可能会更好:
(cd /path/to/file; ls -l *.*.*)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10548 次 |
最近记录: |