Moving Hidden files to normal files


 
Thread Tools Search this Thread
Operating Systems AIX Moving Hidden files to normal files
# 1  
Old 12-22-2012
Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory.

Say i have the following files in directory /x

Code:
.test~1234~567
.report~5678~123
.find~9876~576

i would like to move them to directory /y as

Code:
test~1234~567
report~5678~123
find~9876~576

Can you please let me know the best way to do this ? Appreciate your help.

Warm Regards.

Last edited by Scott; 12-22-2012 at 09:37 AM.. Reason: Code tags
# 2  
Old 12-22-2012
Try:
Code:
#!/bin/ksh
for i in .[^.]*
do      
     echo mv "$i" "${i#.}"
done

I use the Korn shell. You can use any POSIX conforming shell by changing /bin/ksh in #!/bin/ksh to the pathname of the conforming shell you want to use. (And, remove the echo, when you have convinced yourself that the script correctly selects the files you want to move.)

Last edited by fpmurphy; 12-22-2012 at 11:07 AM..
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 12-22-2012
Tried it but not working

Thanks Don.

I tried it to a sample hidden file, but the for loop doesnt identify the hidden file at all. I get the following when i run it:

Code:
$ ~/mvhidden
mv .. .


Following are the files in the directory
Code:
$ls -la
 
.test~HJKL~1234~435
.test~ABCD~5678~123
..
.

I want the above two hidden files to be converted to unhidden so that i can move them to another directory as unhidden.

I have your script like the following:


Code:
for i in .[^.]*
do
  echo mv "$i" "${i#.}"
done


Please help.

Last edited by Scott; 12-22-2012 at 09:40 AM.. Reason: Please use code tags
# 4  
Old 12-22-2012
Quote:
$ ~/mvhidden
mv .. .
You cannot do that. "." and ".." are special. A single "." denotes the current directory and ".." denotes it's parent directory.
# 5  
Old 12-22-2012
Assuming all your file names are more than 2 char length:
Code:
#!/bin/ksh

printf "%s\n" .* | while read h_file                    # Reading all hidden file names
do
        r_file=$( echo "$h_file" | sed 's#^\.##g' )     # Removing the leading period sign
        if [ ${#r_file} -gt 2 ]                         # Checking if length is greater than 2
        then
                echo "mv $h_file $r_file"
        fi
done

Note: Remove the highlighted echo if the output is as expected.
This User Gave Thanks to Yoda For This Post:
# 6  
Old 12-22-2012
Works like a charm

Spot on, bipinajith. Worked like charm.

Thanks a bunch for your help.Smilie
# 7  
Old 12-22-2012
Quote:
Originally Posted by umesh.narain
Thanks Don.

I tried it to a sample hidden file, but the for loop doesnt identify the hidden file at all. I get the following when i run it:

Code:
$ ~/mvhidden
mv .. .


Following are the files in the directory
Code:
$ls -la
 
.test~HJKL~1234~435
.test~ABCD~5678~123
..
.

I want the above two hidden files to be converted to unhidden so that i can move them to another directory as unhidden.

I have your script like the following:


Code:
for i in .[^.]*
do
  echo mv "$i" "${i#.}"
done


Please help.
I note that you left out the #!/bin/ksh line that I had in the script I gave you.

In my test directory, where the output from the command:
Code:
ls -1ad .*

is:
Code:
.
..
.find~9876~576
.report~5678~123
.test~1234~567

the output from my script running on OS X is:
Code:
mv .find~9876~576 find~9876~576
mv .report~5678~123 report~5678~123
mv .test~1234~567 test~1234~567

I'm glad that bipinajith's script worked for you, but I'd still like to know why ksh or bash on AIX didn't work for you. What shell did you use? What happens if you run the command:
Code:
ksh NameOfFileContainingMyScript

instead of:
Code:
~/mvhidden

Note that ~/mvhidden runs a command found in your home directory; did you by any chance have different versions of mvhidden in different directories?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync - how to copy hidden folder or hidden files when using full path

Hello. I use this command : rsync -av --include=".*" --dry-run "$A_FULL_PATH_S" "$A_FULL_PATH_D"The data comes from the output of a find command. And no full source directories are in use, only some files. Source example... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. UNIX for Dummies Questions & Answers

Hidden files

How to list out only the hidden files from a directory ? Thanks (4 Replies)
Discussion started by: pandeesh
4 Replies

4. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

5. UNIX for Dummies Questions & Answers

Moving Multiple files to destination files

I am running a code like this foreach list ($tmp) mv *_${list}.txt ${chart}_${list}.txt #mv: when moving multiple files, last argument must be a directory mv *_${list}.doc ${chart}_${list}.doc #mv: when moving multiple files, last argument must be a... (3 Replies)
Discussion started by: animesharma
3 Replies

6. Shell Programming and Scripting

moving the files in a.txt files to a different directory

HI All, I am coding a shell script which will pick all the .csv files in a particular directoryand write it in to a .txt file, this .txt file i will use as a source in datastage for processing. now after the processing is done I have to move and archive all the files in the .txt file to a... (5 Replies)
Discussion started by: subhasri_2020
5 Replies

7. UNIX for Dummies Questions & Answers

hidden files

I usually use ls -al | awk '{sum = sum + $5} END {print sum}' to sum the size of all files in a directory. However this command includes the hidden files. Is there a command to just add up all the files/sub-directories excluding the hidden files (begins with . and ..) I wanted to check the... (10 Replies)
Discussion started by: lhareigh890
10 Replies

8. Shell Programming and Scripting

Finding Hidden files and protecting the folder containing hidden files from deletion

Hi. I have a script which is deleting files with a particular extension and older than 45 days.The code is: find <path> -name "<filename_pattern>" -mtime +45 -exec rm {} \; But the problem is that some important files are also getting deleted.To prevent this I have decide to make a dummy... (4 Replies)
Discussion started by: pochaw
4 Replies

9. Shell Programming and Scripting

unzip particular gzip files among the normal data files

Hello experts, I run Solaris 9. I have a below script which is used for gunzip the thousand files from a directory. ---- #!/usr/bin/sh cd /home/thousands/gzipfiles/ for i in `ls -1` do gunzip -c $i > /path/to/file/$i done ---- In my SAME directory there thousand of GZIP file and also... (4 Replies)
Discussion started by: thepurple
4 Replies
Login or Register to Ask a Question