开发者

I want to prompt a user for the first 5 characters of a file then have it search for the files

开发者 https://www.devze.com 2023-04-07 00:15 出处:网络
I\'m trying to write a script that will prompt the user for the first 5 charters of a file name then have it search the directories for any开发者_开发百科 files that start with that. Then I want it to

I'm trying to write a script that will prompt the user for the first 5 charters of a file name then have it search the directories for any开发者_开发百科 files that start with that. Then I want it to check to see if a folder is created with the file names and if not create one then move the files there. But if there is a directory for it already then to just move the files too the folder.


Break it down step by step:

"prompt the user for the first 5 characters of a file name" -- you can use the shell read command to get the data. Try a simple shell script:

#!/bin/bash
read foo
echo "foo = $foo"

"if a folder is created with the file names" -- you can use find to see if a file exists. for example:

find . -name abcde\*

"But if there is a directory for it already then to just move the files too the folder." -- the command mkdir takes a -p option so that, if the directory already exists, it won't do anything.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号