I am trying to write a very very simple script in Linux.
Let me show you the code first:
#!/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/*.*.*
When I run this code with bash myscript
command, I get something like: /path/to/file/file.with.three.dots
But I don't want this. I want to show only the file name, not the path.
Then I tried:
ls -l *.*.*
But this time is shows me the files, only if I am inside the /path/to/file/.
How can I set the path, so when running the script from any place, it will output the name of the files in the /path/to/file/?
Thank you!
basename path/to/file.b.c
should give you file.b.c
However re-reading the question, I think a temporary cd
to the path and then an ls
may be better:
(cd /path/to/file; ls -l *.*.*)