On 2024-07-26 07:14, Alain D D Williams wrote:
Neither do you say what you are trying to achieve. Looking for files
owned by
apache in a directory ?
yes.
On Fri, Jul 26, 2024 at 07:04:37AM +0800, coreyh@free.fr wrote:
Hello gurus,
I have the following commands:
$ ls /tmp/|grep apache2
systemd-private-653536fdd8d04538ab68da7469570d0c-apache2.service-UiHjaL
$ sudo ls -ltr
/tmp/systemd-private-653536fdd8d04538ab68da7469570d0c-apache2.service-UiHjaL >> total 4
When I tried to run them in one line as follows,
$ ls /tmp/|grep apache2|sudo ls -ltr
It doesn't work as I expected.
You do not tell us what you expect; however it seems that you not
understand
what you are trying to do. The 'ls' command does not read from stdin,
so
putting it at the end of a pipeline will mean that data in the pipe is ignored.
Neither do you say what you are trying to achieve. Looking for files
owned by
apache in a directory ?
Maybe the following will do what you want:
$ sudo ls -ltr /tmp/systemd-private-653536fdd8d04538ab68da7469570d0c-apache2.service-UiHjaL | grep apache2
this could work indeed. but it requires me to input a long path. so I am asking for a easier way.
I won't go any fancier than this until I know it's actually needed.
On Fri, Jul 26, 2024 at 07:59:42 +0800, coreyh@free.fr wrote:
I won't go any fancier than this until I know it's actually needed.
My actual requirement is that I want to 'ls -ltr' into a subdir in
/tmp.
that subdir is apache's tmp dir. but the name of the subdir is too
long
(hard to copy&paste), so I am looking for a easier way.
Then how do you KNOW which subdirectory to use?
Is it the only one with "-apache" in its name? If so:
ls -ltr /tmp/*-apache*
Otherwise, please describe how you (as a human with a mind) know which directory it is. Then we can try to duplicate that reasoning feat
with commands.
I won't go any fancier than this until I know it's actually needed.
My actual requirement is that I want to 'ls -ltr' into a subdir in /tmp.
that subdir is apache's tmp dir. but the name of the subdir is too long
(hard to copy&paste), so I am looking for a easier way.
I found this works though it's ugly.
$ sudo ls -ltr "/tmp/$(ls /tmp |grep apache)"
total 4
On 26/07/2024 06:59, coreyh@free.fr wrote:
My actual requirement is that I want to 'ls -ltr' into a subdir in
/tmp. that subdir is apache's tmp dir. but the name of the subdir is
too long (hard to copy&paste), so I am looking for a easier way.
Use glob if it is acceptable
sudo ls -ltr /tmp/*-apache2.service-*
If you need a private tmp directory of a specific systemd service then
try to find proper tools to query it
service="bluetooth.service"
pid="$(systemctl show --property MainPID --value "$service")"
tmp="$(findmnt --task "$pid" --target /tmp --noheading --output FSROOT --raw)"
ls -ltr "$tmp"
I found this works though it's ugly.
$ sudo ls -ltr "/tmp/$(ls /tmp |grep apache)"
total 4
Thanks for all help.
On 2024-07-26 09:42, Max Nikulin wrote:
Use glob if it is acceptable
sudo ls -ltr /tmp/*-apache2.service-*
https://mywiki.wooledge.org/BashPitfalls#for_f_in_.24.28ls_.2A.mp3.29
for f in $(ls *.mp3)
No 1 in Bash Pitfalls
So, in summary, the glob solution:
* Is shorter.
* Is easier to read and understand.
* Is more efficient.
* Doesn't break if someone creates /tmp/apache420.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 153:12:17 |
Calls: | 10,383 |
Files: | 14,054 |
Messages: | 6,417,828 |