How to expose an image folder and access them via a route? - laravel

I have a list of flags located at :
/home/bheng/app/public/assets/be/img/flags/
...
-rw-r--r-- 1 robot robot 4655 Apr 29 16:34 tf_64.png
-rw-r--r-- 1 robot robot 3024 Apr 29 16:34 td_64.png
-rw-r--r-- 1 robot robot 5379 Apr 29 16:34 tc_64.png
-rw-r--r-- 1 robot robot 5316 Apr 29 16:34 sz_64.png
-rw-r--r-- 1 robot robot 3486 Apr 29 16:34 sy_64.png
-rw-r--r-- 1 robot robot 4902 Apr 29 16:34 sx_64.png
-rw-r--r-- 1 robot robot 3508 Apr 29 16:34 sv_64.png
-rw-r--r-- 1 robot robot 3986 Apr 29 16:34 st_64.png
-rw-r--r-- 1 robot robot 4290 Apr 29 16:34 ss_64.png
-rw-r--r-- 1 robot robot 3765 Apr 29 16:34 sr_64.png
-rw-r--r-- 1 robot robot 3856 Apr 29 16:34 so_64.png
-rw-r--r-- 1 robot robot 3580 Apr 29 16:34 sn_64.png
-rw-r--r-- 1 robot robot 4959 Apr 29 16:34 sm_64.png
-rw-r--r-- 1 robot robot 3077 Apr 29 16:34 sl_64.png
-rw-r--r-- 1 robot robot 4483 Apr 29 16:34 sk_64.png
-rw-r--r-- 1 robot robot 3517 Apr 29 16:34 sj_64.png
-rw-r--r-- 1 robot robot 3483 Apr 29 16:34 si_64.png
drwxr-xr-x 2 robot robot 12288 Apr 29 16:34 .
┌──[robot#world]──[/home/bheng/app/public/assets/be/img/flags]
└──
I want to load that image when I visit
https://www.bunlongheng.com/flags/*
Ex.
https://www.bunlongheng.com/flags/sn_64.png
I've tried add this line to my nginx
location ^~ /flags/ {
root /home/bheng/app/public/assets/be/img/flags/;
}
I still get 404 on my URL : https://www.bunlongheng.com/flags/sn_64.png
What did missed?
Also
I've tried alias
location /flags/ {
alias /home/bheng/app/public/assets/be/img/flags/;
#root /home/bheng/app/public/assets/be/img/flags/;
}

You need rewrite instead of alias :
location ~ /assets/be/img/flags/(?<filename>.+)$ {
rewrite ^ /flags/$filename last;
}
or another way maybe you should use root:
location ~ /flags/ {
root /assets/be/img/flags/;
}
but both ways need to use php artisan storage:link, because it's must be a public nginx path.

Related

Linux command du returns different size when the same content is, either an image mount to the file system, or under a directory of it

I have a qcow2 image which I have converted to raw format, and then mount to my file system:
# qemu-img convert -O raw initial-image.qcow2 raw-image.img
# kpartx -av raw-image.img
add map loop0p1 (253:1): 0 41940992 linear /dev/loop0 2048
# mount /dev/mapper/loop0p1 ~/myImage
# ls ~/myImage
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
The size of ~/myImage mountpoint is checked with du command as follows:
# du -hx --max-depth=1 ~/myImage/
0 /root/myImage/dev
0 /root/myImage/proc
0 /root/myImage/run
0 /root/myImage/sys
36M /root/myImage/etc
40K /root/myImage/root
53M /root/myImage/var
12K /root/myImage/tmp
834M /root/myImage/usr
89M /root/myImage/boot
0 /root/myImage/home
0 /root/myImage/media
0 /root/myImage/mnt
0 /root/myImage/opt
0 /root/myImage/srv
1012M /root/myImage/
At this point I copied the contents of ~/myImage and pasted them inside ~/myImage-copy directory. Then I checked the size of the newly created directory. I expected the exact same size for each directory between ~/myImage and ~/myImage-copy, but it's not:
# cp -R myImage/ ~/myImage-copy
# du -hx --max-depth=1 ~/myImage-copy/
0 /root/myImage-copy/dev
0 /root/myImage-copy/proc
0 /root/myImage-copy/run
0 /root/myImage-copy/sys
36M /root/myImage-copy/etc
40K /root/myImage-copy/root
63M /root/myImage-copy/var
12K /root/myImage-copy/tmp
862M /root/myImage-copy/usr
89M /root/myImage-copy/boot
0 /root/myImage-copy/home
0 /root/myImage-copy/media
0 /root/myImage-copy/mnt
0 /root/myImage-copy/opt
0 /root/myImage-copy/srv
1.1G /root/myImage-copy/
From the paths above with different size, I chose /usr and I followed a branch of it until I conclude to an innermost directory which has different size, in order to inspect its files. Below is shown the size difference of an innermost directory:
# du -hx --max-depth=1 ~/myImage/usr/lib64/python2.7/json/
112K /root/myImage/usr/lib64/python2.7/json/
# du -hx --max-depth=1 ~/myImage-copy/usr/lib64/python2.7/json/
164K /root/myImage-copy/usr/lib64/python2.7/json/
However, by inspecting their file content, I can't see any difference related to their size. I don't know if the second column plays a role:
# ls -lah ~/myImage/usr/lib64/python2.7/json/
total 200K
drwxr-xr-x. 2 root root 280 Feb 3 11:17 .
drwxr-xr-x. 26 root root 20K Feb 3 11:17 ..
-rw-r--r--. 1 root root 14K Aug 13 2020 decoder.py
-rw-r--r--. 2 root root 12K Aug 13 2020 decoder.pyc
-rw-r--r--. 2 root root 12K Aug 13 2020 decoder.pyo
-rw-r--r--. 1 root root 17K Aug 13 2020 encoder.py
-rw-r--r--. 2 root root 14K Aug 13 2020 encoder.pyc
-rw-r--r--. 2 root root 14K Aug 13 2020 encoder.pyo
-rw-r--r--. 1 root root 15K Aug 13 2020 __init__.py
-rw-r--r--. 2 root root 14K Aug 13 2020 __init__.pyc
-rw-r--r--. 2 root root 14K Aug 13 2020 __init__.pyo
-rw-r--r--. 1 root root 2.3K Aug 13 2020 scanner.py
-rw-r--r--. 2 root root 2.2K Aug 13 2020 scanner.pyc
-rw-r--r--. 2 root root 2.2K Aug 13 2020 scanner.pyo
-rw-r--r--. 1 root root 997 Aug 13 2020 tool.py
-rw-r--r--. 2 root root 1.3K Aug 13 2020 tool.pyc
-rw-r--r--. 2 root root 1.3K Aug 13 2020 tool.pyo
# ls -lah ~/myImage-copy/usr/lib64/python2.7/json/
total 200K
drwxr-xr-x 2 root root 280 Mar 4 17:55 .
drwxr-xr-x 26 root root 20K Mar 4 17:55 ..
-rw-r--r-- 1 root root 14K Mar 4 17:55 decoder.py
-rw-r--r-- 1 root root 12K Mar 4 17:55 decoder.pyc
-rw-r--r-- 1 root root 12K Mar 4 17:55 decoder.pyo
-rw-r--r-- 1 root root 17K Mar 4 17:55 encoder.py
-rw-r--r-- 1 root root 14K Mar 4 17:55 encoder.pyc
-rw-r--r-- 1 root root 14K Mar 4 17:55 encoder.pyo
-rw-r--r-- 1 root root 15K Mar 4 17:55 __init__.py
-rw-r--r-- 1 root root 14K Mar 4 17:55 __init__.pyc
-rw-r--r-- 1 root root 14K Mar 4 17:55 __init__.pyo
-rw-r--r-- 1 root root 2.3K Mar 4 17:55 scanner.py
-rw-r--r-- 1 root root 2.2K Mar 4 17:55 scanner.pyc
-rw-r--r-- 1 root root 2.2K Mar 4 17:55 scanner.pyo
-rw-r--r-- 1 root root 997 Mar 4 17:55 tool.py
-rw-r--r-- 1 root root 1.3K Mar 4 17:55 tool.pyc
-rw-r--r-- 1 root root 1.3K Mar 4 17:55 tool.pyo
In addition, I checked the md5 hash of the files above as a view of their content. It seems there is no content differences between the same files:
# md5sum ~/myImage/usr/lib64/python2.7/json/*
598c681c82c582ca3f17950b4d5413c1 /root/myImage/usr/lib64/python2.7/json/decoder.py
939055a9fdfbbe6ab4d4babeb3ae63f5 /root/myImage/usr/lib64/python2.7/json/decoder.pyc
939055a9fdfbbe6ab4d4babeb3ae63f5 /root/myImage/usr/lib64/python2.7/json/decoder.pyo
007a9954ca6641b29564a0f0cb55096b /root/myImage/usr/lib64/python2.7/json/encoder.py
366d44efbfce1e5b4a3397b15f202765 /root/myImage/usr/lib64/python2.7/json/encoder.pyc
366d44efbfce1e5b4a3397b15f202765 /root/myImage/usr/lib64/python2.7/json/encoder.pyo
dd5db0c7fb7c531be4e14feebbdb52e8 /root/myImage/usr/lib64/python2.7/json/__init__.py
791c8dca2a86ce50ead04e918a17b508 /root/myImage/usr/lib64/python2.7/json/__init__.pyc
791c8dca2a86ce50ead04e918a17b508 /root/myImage/usr/lib64/python2.7/json/__init__.pyo
8d6660f10863f99ffdd9a95eeddd7b64 /root/myImage/usr/lib64/python2.7/json/scanner.py
59865f486b742aea959693c04cfce057 /root/myImage/usr/lib64/python2.7/json/scanner.pyc
59865f486b742aea959693c04cfce057 /root/myImage/usr/lib64/python2.7/json/scanner.pyo
ad879e2ba247d3d4a5cc71fe22db91d0 /root/myImage/usr/lib64/python2.7/json/tool.py
af6b5531a8bc6977bca14e8d34ba8f68 /root/myImage/usr/lib64/python2.7/json/tool.pyc
af6b5531a8bc6977bca14e8d34ba8f68 /root/myImage/usr/lib64/python2.7/json/tool.pyo
# md5sum ~/myImage-copy/usr/lib64/python2.7/json/*
598c681c82c582ca3f17950b4d5413c1 /root/myImage-copy/usr/lib64/python2.7/json/decoder.py
939055a9fdfbbe6ab4d4babeb3ae63f5 /root/myImage-copy/usr/lib64/python2.7/json/decoder.pyc
939055a9fdfbbe6ab4d4babeb3ae63f5 /root/myImage-copy/usr/lib64/python2.7/json/decoder.pyo
007a9954ca6641b29564a0f0cb55096b /root/myImage-copy/usr/lib64/python2.7/json/encoder.py
366d44efbfce1e5b4a3397b15f202765 /root/myImage-copy/usr/lib64/python2.7/json/encoder.pyc
366d44efbfce1e5b4a3397b15f202765 /root/myImage-copy/usr/lib64/python2.7/json/encoder.pyo
dd5db0c7fb7c531be4e14feebbdb52e8 /root/myImage-copy/usr/lib64/python2.7/json/__init__.py
791c8dca2a86ce50ead04e918a17b508 /root/myImage-copy/usr/lib64/python2.7/json/__init__.pyc
791c8dca2a86ce50ead04e918a17b508 /root/myImage-copy/usr/lib64/python2.7/json/__init__.pyo
8d6660f10863f99ffdd9a95eeddd7b64 /root/myImage-copy/usr/lib64/python2.7/json/scanner.py
59865f486b742aea959693c04cfce057 /root/myImage-copy/usr/lib64/python2.7/json/scanner.pyc
59865f486b742aea959693c04cfce057 /root/myImage-copy/usr/lib64/python2.7/json/scanner.pyo
ad879e2ba247d3d4a5cc71fe22db91d0 /root/myImage-copy/usr/lib64/python2.7/json/tool.py
af6b5531a8bc6977bca14e8d34ba8f68 /root/myImage-copy/usr/lib64/python2.7/json/tool.pyc
af6b5531a8bc6977bca14e8d34ba8f68 /root/myImage-copy/usr/lib64/python2.7/json/tool.pyo
So, what is the reason behind the size difference of the same content in du output?
My operating system is CentOS Linux release 7.9.2009.

Selected png images to gif using ffmpeg or imagemagick

I want to convert png to gif and i want to mention which are the frames i want to combine
eg: frame1.png and frame2.png.
I've tried using ffmpeg -i frames/%03d.png -vf fps=20 logo.gif but it is considering all the images in that directory, but i want only two images in that directory to be included in the gif i want to create. Thank you in advance.
Just use the ones you want:
magick -delay 80 nice1.png nice37.png animated.gif
By way of explanation and further example, I can make a red and a blue frame and morph between the two in 14 steps like this - making a total of 16 frames:
magick -size 20x100 xc:red xc:blue -morph 14 frame-%02d.png
If I append those frames side-by-side, you can see them all:
magick frame* +append side-by-side.png
And I can list them in the shell:
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-00.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-01.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-02.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-03.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-04.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-05.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-06.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-07.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-08.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-09.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-10.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-11.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-12.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-13.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-14.png
-rw-r--r-- 1 mark staff 278 28 Apr 13:45 frame-15.png
If I now want to select some to make an animated GIF, I can use the shell's "brace expansion" to select certain ones:
ls frame-0{2,3,9}.png
frame-02.png frame-03.png frame-09.png
Or the shell's "range expansion" to select a contiguous range:
ls frame-1[2-4].png
frame-12.png frame-13.png frame-14.png
Or the shell's "wildcard expansion":
ls frame-1?.png
frame-10.png frame-11.png frame-12.png frame-13.png frame-14.png frame-15.png
And that works with magick just the same as ls, so I can select a few frames for an animated GIF like this:
magick -delay 80 frame-0{2,4}.png frame-1*.png animated.gif

How to debug unexpected OpenBMC hwmon AST2600 behavior?

I am debugging a pwmtachtool<->hwmon interaction problem, observed when OpenBMC image is running
on an AST2600 EVB, which is connected to a SensorsBoard and a Fan (Host is not connected).
The running OpenBMC image was built using bitbake, and it includes recipes-phosphor/configuration/entity-manager/SensorBoard.json,
customized for this SensorBoard. Verified that I2C sensors on the SensorsBoard are accessible via i2ctools,
and behave as expected. However, running "pwmtachtool <dev_id> --get-fan-speed <fan_num>" consistently
reports "Fan speed is 0", even though phy Fan is properly connected.
For example:
/usr/local/bin/pwmtachtool 0 --get-fan-speed 0 --verbose
GET_TACH_SPEED:rpm value 0
Fan 0 speed is 0
cat /sys/class/hwmon/hwmon0/fan0_input
0
Looking closely at the pwmtachtool codepath, I am seeing that it calls pwmtach_action(), which reads
"/sys/class/hwmon/hwmon<dev_id>/fan", which is always 0. Tried all <dev_id>/ combinations,
exposed by sysfs: same result. So far, unable to figure out why this is so.
I would really appreciate all recommendations for how to debug this problem.
Additional details:
ll /sys/class/hwmon/
lrwxrwxrwx 1 root root 0 Feb 16 08:52 hwmon0 -> ../../devices/platform/ahb/ahb:apb/1e610000.pwm-tacho-controller/hwmon/hwmon0
lrwxrwxrwx 1 root root 0 Feb 16 08:52 hwmon1 -> ../../devices/platform/iio-hwmon/hwmon/hwmon1
lrwxrwxrwx 1 root root 0 Feb 26 22:20 hwmon2 -> ../../devices/platform/ahb/ahb:apb/ahb:apb:bus#1e78a000/1e78a480.i2c-bus/i2c-8/8-004d/hwmon/hwmon2
ll /sys/class/hwmon/hwmon0/*
lrwxrwxrwx 1 root root 0 Feb 26 22:20 /sys/class/hwmon/hwmon0/device -> ../../../1e610000.pwm-tacho-controller
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan0_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan10_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan11_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan12_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan13_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan14_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan15_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan1_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan2_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan3_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan4_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan5_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan6_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan7_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan8_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/fan9_input
-r--r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/name
lrwxrwxrwx 1 root root 0 Feb 26 22:20 /sys/class/hwmon/hwmon0/of_node -> ../../../../../../../firmware/devicetree/base/ahb/apb/pwm-tacho-controller#1e610000
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm0
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm1
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm10
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm11
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm12
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm13
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm14
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm15
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm2
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm3
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm4
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm5
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm6
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm7
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm8
-rw-r--r-- 1 root root 4096 Feb 26 22:20 /sys/class/hwmon/hwmon0/pwm9
lrwxrwxrwx 1 root root 0 Feb 16 08:52 /sys/class/hwmon/hwmon0/subsystem -> ../../../../../../../class/hwmon
-rw-r--r-- 1 root root 4096 Feb 16 08:52 /sys/class/hwmon/hwmon0/uevent
In my case, the problem was because of J80 jumper connected PWM and TACH lines. So, when I removed it pwmtachtool started to work as expected.

Make nl to enumerate from a specified line

I intent to enumerate the files and dirs
[root#iz2ze9wve43n2nyuvmsfx5z /]# ls -lh |nl
1 total 60K
2 lrwxrwxrwx 1 root root 7 Jun 15 22:08 bin -> usr/bin
3 dr-xr-xr-x. 5 root root 4.0K Jun 15 22:10 boot
4 drwxr-xr-x 19 root root 2.9K Sep 17 11:35 dev
5 drwxr-xr-x. 85 root root 4.0K Sep 18 22:44 etc
6 drwxr-xr-x. 2 root root 4.0K Sep 17 08:25 home
7 lrwxrwxrwx 1 root root 7 Jun 15 22:08 lib -> usr/lib
8 lrwxrwxrwx 1 root root 9 Jun 15 22:08 lib64 -> usr/lib64
9 drwx------. 2 root root 16K Oct 15 2017 lost+found
10 drwxr-xr-x. 2 root root 4.0K Apr 11 2018 media
11 drwxr-xr-x. 2 root root 4.0K Apr 11 2018 mnt
12 drwxr-xr-x. 2 root root 4.0K Apr 11 2018 opt
13 dr-xr-xr-x 86 root root 0 Sep 17 11:35 proc
14 drwxrwxrwx. 21 root root 4.0K Oct 22 08:11 root
15 drwxr-xr-x 24 root root 660 Oct 24 19:10 run
16 lrwxrwxrwx 1 root root 8 Jun 15 22:08 sbin -> usr/sbin
17 drwxr-xr-x. 2 root root 4.0K Apr 11 2018 srv
18 dr-xr-xr-x 13 root root 0 Oct 21 19:50 sys
19 drwxrwxrwt. 11 root root 4.0K Oct 24 05:19 tmp
20 drwxr-xr-x. 13 root root 4.0K Jun 15 22:08 usr
21 drwxr-xr-x. 19 root root 4.0K Jun 15 22:08 var
It starts with 1 which I desire is 0.
How could make nl to enumerate from a specified line.
You just need to use the -v option, and specify to start from 0; your instruction becoming:
ls -lh |nl -v 0
Lets have a look at nl --help:
$ nl --help
Usage: nl [OPTION]... [FILE]...
Write each FILE to standard output, with line numbers added.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
...
-v, --starting-line-number=NUMBER first line number for each section
Therefore:
$ nl -v0 <<EOF
> a
> b
> EOF
0 a
1 b
Note that it does not really matter whether you want to enumerate directories or anything else, which is why you probably should strip this part from your question to make it more specific.

Extract lines with duplicate last field

Based on a list generated with the command
find '/patch' -name A* -exec ls -la {} \;
Get only a list with file names that appears more than once (duplicated), but I want display the full line not only the file name.
File name consider only the name of file not the full path.
Example
Based on this file:
-rw-r--r-- 1 root root 34K Jan 9 2014 /usr/share/dia/sheets/AADL.sheet
-rw-r--r-- 1 root root 952 Fev 14 07:07 /usr/share/postgresql/9.3/man/man7/ABORT.7.gz
-rw-r--r-- 1 root root 955 Jul 30 2014 /usr/share/postgresql/9.1/man/man7/ABORT.7.gz
-rw-r--r-- 1 root root 92K Abr 28 2014 /usr/share/gettext/ABOUT-NLS
-rw-r--r-- 1 root root 545 Dez 14 2013 /usr/share/dia/sheets/Automata.sheet
-rw-r--r-- 1 root root 6,7K Dez 21 2012 /usr/share/perl5/Mail/Address.pm
-rw-r--r-- 1 root root 709 Mar 3 09:03 /home/test/Address.pm
-rw-r--r-- 1 root root 709 Mar 3 11:13 /home/test/Automata.sheet
-rw-r--r-- 1 root root 520 Mar 3 11:15 /home/test/t2/Address.pm
I want get this result:
-rw-r--r-- 1 root root 952 Fev 14 07:07 /usr/share/postgresql/9.3/man/man7/ABORT.7.gz
-rw-r--r-- 1 root root 955 Jul 30 2014 /usr/share/postgresql/9.1/man/man7/ABORT.7.gz
-rw-r--r-- 1 root root 6,7K Dez 21 2012 /usr/share/perl5/Mail/Address.pm
-rw-r--r-- 1 root root 709 Mar 3 09:03 /home/test/Address.pm
-rw-r--r-- 1 root root 520 Mar 3 11:15 /home/test/t2/Address.pm
-rw-r--r-- 1 root root 545 Dez 14 2013 /usr/share/dia/sheets/Automata.sheet
-rw-r--r-- 1 root root 709 Mar 3 11:13 /home/test/Automata.sheet
Using this commands
awk -F. '{ n = split($0, a, "/"); print a[n] }' file |sort | uniq -d > filedups
I got
ABORT.7.gz
Address.pm
Automata.sheet
and after
grep -f filedups file
I get expected result.
My question:
Is there a direct way to do this in just one line using awk and/or other commands?
awk to the rescue!
starting with your initial file
$ awk '{n=split($NF,a,"/"); k=a[n]; c[k]++;
v[k]=k in v?v[k] ORS $0:$0}
END {for(k in c) if(c[k]>1) print v[k]}' file
-rw-r--r-- 1 root root 6,7K Dez 21 2012 /usr/share/perl5/Mail/Address.pm
-rw-r--r-- 1 root root 709 Mar 3 09:03 /home/test/Address.pm
-rw-r--r-- 1 root root 520 Mar 3 11:15 /home/test/t2/Address.pm
-rw-r--r-- 1 root root 545 Dez 14 2013 /usr/share/dia/sheets/Automata.sheet
-rw-r--r-- 1 root root 709 Mar 3 11:13 /home/test/Automata.sheet
-rw-r--r-- 1 root root 952 Fev 14 07:07 /usr/share/postgresql/9.3/man/man7/ABORT.7.gz
-rw-r--r-- 1 root root 955 Jul 30 2014 /usr/share/postgresql/9.1/man/man7/ABORT.7.gz

Resources