简体   繁体   中英

Linux Bash Script unhiding files in the directory

Am trying to make a script to unhide files in the directory with parameter --unhide but it is not working. May you help me? Here is my part of the code.

for i in `ls -1`
do
    if [ -f $i ] || [ -d $i ]
    then
        if [ `echo $i | cut -c1` == "." ]
        then
            mv $i ${i#.}
        fi
    fi
done

Thanks!

And how about unhide then i write --unhide file1 file2?

elif [ $1 = --unhide ] && [ ! $2 = --all ]
then
for i in $@
do
if [ -f $i ] || [ -d $i ]
then
if [ `echo $i | cut -c1` == "." ]
then
mv $i ${i#.}
fi
fi
done    

Its easy then we have not hidden files, then parameter name is the same name with the file name. But how to check hidden files? I tried to write --unhide .file1 .file2 but script only unhides .file1 and .file2 not.

So basically what you are asking for is a script that rename files within a directory, where the files start with a '.'?

Something like the following should work

GLOBIGNORE=".:.."
for file in .*; do
   mv -n "$file" "${file#.}"
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM