[英]Shell script to ls and execute command on ls result
我在ubuntu的文件夹中有一个文件夹列表。 即。 在/ mnt / source / customcode / files / brands /下
root@a919794ec280:/mnt/source/customcode/files/brands# ls -la
total 236
drwxrwxrwx 19 1002 root 4096 Jan 3 09:26 .
drwxrwxrwx 8 1002 1003 4096 Dec 27 22:45 ..
drwxrwxr-x 3 1002 1003 4096 Jan 3 09:22 aem
drwxrwxr-x 3 1002 1003 4096 Jan 3 09:22 apple
drwxrwxr-x 3 1002 1003 4096 Jan 3 09:22 cool
drwxr-xr-x 3 1002 root 4096 Jan 3 09:22 doll
drwxr-xr-x 3 1002 root 4096 Jan 3 09:22 ent
drwxr-xr-x 3 1002 root 4096 Jan 3 09:22 f1
drwxr-xr-x 3 1002 root 4096 Jan 3 09:22 google
drwxrwxrwx 3 1002 root 4096 Jan 3 09:22 h1
drwxrwxr-x 3 1002 1003 4096 Jan 3 09:22 iq
drwxr-xr-x 3 1002 root 4096 Jan 3 09:22 king
drwxrwxrwx 3 root root 4096 Jan 3 09:22 link
drwxrwxrwx 3 1002 root 155648 Jan 3 09:22 nobrand
drwxrwxr-x 3 1002 1003 12288 Jan 3 09:22 pepperfry
drwxrwxrwx 2 1002 root 4096 Jan 3 09:22 pepsi
drwxrwxr-x 2 1002 1003 4096 Jan 3 09:22 rock
drwxrwxrwx 2 1002 root 4096 Jan 3 09:22 star9
drwxrwxr-x 2 1002 1003 4096 Jan 3 09:22 vicks
----- 100+ -----
像上面一样,我有“ a1”,“ cola”,“ link”等文件夹(超过100个文件夹)
在这些文件夹的旁边,将有一个名为“ data_aug”的文件夹,而“ data_aug”文件夹中确实包含文件。
root@a919794ec280:/mnt/source/customcode/files/brands/apple# ls -la
total 1988
drwxrwxr-x 3 1002 1003 4096 Jan 3 09:22 .
drwxrwxrwx 19 1002 root 4096 Jan 3 09:26 ..
-rw-r--r-- 1 1002 1003 17465 Dec 29 23:28 0DPA0C3.jpg
-rw-r--r-- 1 1002 1003 3836 Dec 31 00:55 130418131111-apple-store-santa-monica.jpg
-rw-r--r-- 1 1002 1003 48616 Dec 31 00:52 15146774227434507677123475441338.jpg
-rw-r--r-- 1 1002 1003 9107 Dec 31 00:52 15146774615326659565665852728294.jpg
-rw-r--r-- 1 1002 1003 28005 Dec 29 23:28 3D-Apple-Logo-Wallpapers.jpg
-rw-r--r-- 1 1002 1003 75855 Dec 29 23:28 3D-Apple-Logo.jpg
-rw-r--r-- 1 1002 1003 27403 Dec 29 23:28 3d_apple_logo___wallpaper_by_techflashdesigns-d4fbc7p.jpg
-rw-r--r-- 1 1002 1003 38420 Dec 29 23:28 AX62GjL.jpg
-rw-r--r-- 1 1002 1003 6025 Dec 29 23:28 Apple-Logo-2016 (1).jpg
-rw-r--r-- 1 1002 1003 929419 Dec 29 23:28 Apple-Logo-Png-Download.png
-rw-r--r-- 1 1002 1003 35742 Dec 29 23:28 apple-logo-2016.jpg
-rw-r--r-- 1 1002 1003 15301 Dec 29 23:28 apple-logo-3d-model-max-obj-fbx-3dm-ige-igs-iges.jpg
-rw-r--r-- 1 1002 1003 42514 Dec 29 23:28 apple-logo-clipart-2.jpeg
-rw-r--r-- 1 1002 1003 152183 Dec 29 23:28 apple-logo-clouds.jpg
-rw-r--r-- 1 1002 1003 6117 Dec 31 00:55 apple1.jpg
-rw-r--r-- 1 1002 1003 349787 Dec 29 23:28 apple_ipad_logo.png
-rw-r--r-- 1 1002 1003 54167 Dec 29 23:28 b5c4d6c9-3.jpg
drwxr-xr-x 2 root root 4096 Jan 3 09:22 data_aug
-rw-r--r-- 1 1002 1003 32918 Dec 29 23:28 large.JPG
-rw-r--r-- 1 1002 1003 48972 Dec 29 23:28 medium.jpg
-rw-r--r-- 1 1002 1003 3609 Dec 29 23:28 th (1).jpeg
-rw-r--r-- 1 1002 1003 30392 Dec 29 23:28 th (2).jpeg
-rw-r--r-- 1 1002 1003 3222 Dec 29 23:28 th.jpeg
-rw-r--r-- 1 1002 1003 22544 Dec 29 23:28 u5TAcBk.jpg
root@a919794ec280:/mnt/source/customcode/files/brands/apple/data_aug# ls -la
total 4356
drwxr-xr-x 2 root root 12288 Jan 3 09:41 .
drwxrwxr-x 3 1002 1003 4096 Jan 3 09:22 ..
-rw-r--r-- 1 root root 10450 Jan 3 09:40 apple_0_1.jpeg
-rw-r--r-- 1 root root 5599 Jan 3 09:40 apple_0_1019.jpeg
-rw-r--r-- 1 root root 3225 Jan 3 09:40 apple_0_1075.jpeg
-rw-r--r-- 1 root root 10283 Jan 3 09:40 apple_0_1100.jpeg
-rw-r--r-- 1 root root 13923 Jan 3 09:41 apple_0_1119.jpeg
现在...
我需要将脚本放置在“ / mnt / source / customcode /”中
希望从“ / mnt / source / customcode /”运行脚本,因为我的脚本相关文件只能从“ / mnt / source / customcode /”执行才能实现。
从所有100个文件夹中递归删除文件夹“ data_aug”和“ data_aug”中的数据。
然后从“ / mnt / source / customcode /”位置执行
特殊脚本,它将引用这100个文件夹。 像例子
下面。
码...
python -m scripts.augmentation_keras --image_dir=files/brands/apple --target_dir=files/brands/apple/data_aug --save_prefix=apple
python -m scripts.augmentation_keras --image_dir=files/brands/a1 --target_dir=files/brands/a1/data_aug --save_prefix=a1
像以上所有100个文件夹一样。 文件夹100的数量将来会增加。
我该如何动态地做到这一点,而不是编写带有数百行的简单脚本(静态删除和执行)!
谢谢。
大概是这样的:
for d in /home/user/data/*
do
rm -rf $d/content/*
python -m scripts.augmentation_keras --image_dir=$d --
target_dir=$d/content --save_prefix=$(basename $d)
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.