Sponsored Content
Top Forums Shell Programming and Scripting Dealing with files with spaces in the name Post 302360711 by jakethegreycat on Friday 9th of October 2009 08:44:37 PM
Old 10-09-2009
I'm sorry... I don't know what code tags are.



Tried adding -- before the rm commands but it still has the same problems as before
Code:
#!
#
#This script will search out duplicate files and remove duplicates
#
#directory=NULL
#echo "Wht directory would you like to remove duplicates from?"
#read directory
cd ~/Desktop/test_remove
for i in *
do
    for j in *
    do
        if [ "$i" != "$j" ]
        then            
            cmp -s -- "$i" "$j" 
            c=$?
            if [ $c == 0 ]
            then
                if [ "$j" > "$i" ]
                then
                    rm  -- "$j"
                else
                    rm -- "$i"
                fi 
            fi    
        fi
    done
done
exit 1


Last edited by Franklin52; 10-10-2009 at 08:00 AM.. Reason: Please use code tags!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl: When dealing with files that do not exist

I have a process run weekly where I must convert data formats for about thirty files. I read a text file that provides all of the filenames and switch settings. My perl code is: for ($j = 1; $j <= $k; $j++) { open(FIN2,$fin2) || die "open: $!"; do other stuff } Every once in... (2 Replies)
Discussion started by: joeyg
2 Replies

2. Shell Programming and Scripting

Files with spaces....

Ok, I have this script that will look for files with the .pl4 extension and rename them with the modification date... But it breaks when the file has a space in it... (files are on windows machine) ive been trying to fix it but no luck.... Any help is greatly appriciated.. #! /bin/sh for file... (1 Reply)
Discussion started by: Jay5487
1 Replies

3. Shell Programming and Scripting

Dealing with spaces in file names in a shell script

Hi, What's the best way to find all files under a directory - including ones with space - in order to apply a command to each of them. For instance I want get a list of files under a directory and generate a checksum for each file. Here's the csh script: #!/bin/csh set files = `find $1... (5 Replies)
Discussion started by: same1290
5 Replies

4. Shell Programming and Scripting

Dealing with log files

Hi , My requirement is that i need to search for a number of strings in a log file and print them with line numbers.The search should be date wise. The sample log file is : Jan 17 02:45:34 srim6165 MQSIv500: (UKBRKR1P_B.LZ_ BENCHMARKS)BIP2648E: Message backed out to a queue; node... (6 Replies)
Discussion started by: charudpss
6 Replies

5. UNIX for Dummies Questions & Answers

How to read files with spaces

Hi I am a newbie to unix. I have a current script that reads a directory for excel files and renames the files. There is a problem now because some of the files have spaces. If I put quotes on the file, it will work but I dont know how to read all the files with quotes. Variables $1 =... (6 Replies)
Discussion started by: Lillyt
6 Replies

6. Shell Programming and Scripting

Iterating over subdirectories and dealing with files within them

Hello, I am working on a coding project for a class and to test the program I have created, I have come up with 100 different test cases. The program takes four text files as input, so each of the test cases is contained in a folder with four files. I have a folder called 'tests', within which... (1 Reply)
Discussion started by: dpryor
1 Replies

7. UNIX for Dummies Questions & Answers

Dealing with Empty files, AWK and Loops

I write this bit of code to calculate the mean and variance for all the files in one directory and print the mean and variance in a separate folder but with the same file name. FILES="data/*" for X in $FILES do name=$(basename $X) awk '{x=$0; s+=$0; n++} END{mean=s/n; for (i in x){ss... (20 Replies)
Discussion started by: A-V
20 Replies

8. Shell Programming and Scripting

Dealing with multiple files

Korn Shell I have hundreds of small files like below created every day. A midnight cron job moves them to the location /u04/temp/logs But sometimes I have to manually move these files based a certain dates or time. I have two basic requirements 1.Using mv command I want to move all .dat... (2 Replies)
Discussion started by: kraljic
2 Replies

9. Shell Programming and Scripting

Dealing with white spaces in bash scripts

I'm trying to search for all files in directory with particular GID then change the GID to match the UID of each file: #!/bin/sh for i in $(find /dump -gid 200 | sed 's/\ /\\\ /g' | sed 's/\&/\\\&/g'); do chgrp $(ls -ln ${i} | awk '{print $3}') ${i} done I'm using sed to deal with... (7 Replies)
Discussion started by: venmx
7 Replies

10. Shell Programming and Scripting

Dealing with filename spaces in Perl

The following command to replace text in place in multiple files in a directory is tripping up on filename spaces (Windows environment). I really don't know Perl. find '\\server\directory' | xargs perl -pi -e 's/textA/textB/g'Mike (2 Replies)
Discussion started by: Michael Stora
2 Replies
hardlink(1)						      General Commands Manual						       hardlink(1)

NAME
hardlink - Consolidate duplicate files via hardlinks SYNOPSIS
hardlink [-c] [-n] [-v] [-vv] [-h] directory1 [ directory2 ... ] DESCRIPTION
This manual page documents hardlink, a program which consolidates duplicate files in one or more directories using hardlinks. hardlink traverses one or more directories searching for duplicate files. When it finds duplicate files, it uses one of them as the mas- ter. It then removes all other duplicates and places a hardlink for each one pointing to the master file. This allows for conservation of disk space where multiple directories on a single filesystem contain many duplicate files. Since hard links can only span a single filesystem, hardlink is only useful when all directories specified are on the same filesystem. OPTIONS
-c Compare only the contents of the files being considered for consolidation. Disregards permission, ownership and other differ- ences. -f Force hardlinking across file systems. -n Do not perform the consolidation; only print what would be changed. -v Print summary after hardlinking. -vv Print every hardlinked file and bytes saved. Also print summary after hardlinking. -h Show help. AUTHOR
hardlink was written by Jakub Jelinek <jakub@redhat.com>. Man page written by Brian Long. Man page updated by Jindrich Novy <jnovy@redhat.com> BUGS
hardlink assumes that its target directory trees do not change from under it. If a directory tree does change, this may result in hardlink accessing files and/or directories outside of the intended directory tree. Thus, you must avoid running hardlink on potentially changing directory trees, and especially on directory trees under control of another user. hardlink(1)
All times are GMT -4. The time now is 07:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy