Diff to Output Only the File Names

diff to output only the file names

From the diff man page:

-q   Report only whether the files differ, not the details of the differences.

-r   When comparing directories, recursively compare any subdirectories found.

Example command:

diff -qr dir1 dir2

Example output (depends on locale):

$ ls dir1 dir2
dir1:
same-file different only-1

dir2:
same-file different only-2
$ diff -qr dir1 dir2
Files dir1/different and dir2/different differ
Only in dir1: only-1
Only in dir2: only-2

linux diff to only output filename and nothing else

Use the exit status of diff:

if ! diff -q file1 file2 >/dev/null; then echo file1; fi

diff compare directories by filename only

In PowerShell, if you want to know which file names are unique to /dir1, use a Compare-Object call, followed by reducing those file names to their base name (file name without extension), weeding out duplicates, and sorting via Sort-Object

Compare-Object -PassThru -Property Name (Get-ChildItem -File /dir1) (Get-ChildItem -File /dir2) |
Where-Object SideIndicator -eq '<=' |
ForEach-Object BaseName |
Sort-Object -Unique

Note: The assumption is that both Get-ChildItem calls return at least one file-info object, otherwise the Compare-Object call will fail - guard against that with if statements, if necessary.

In linux, how to compare two directories by filename only and get list of results that did not match

if I understand you correctly you nedd following script:

#/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
folder1="/home/vagrant/1 b"
folder2="/home/vagrant/2 a"
ext1="tiff"
ext2="png"

for fullfile in ${folder1}/*.$ext1
do
#echo "$fullfile fullfile"
filename=$(basename "$fullfile")
#echo "$filename file"
extension="${filename##*.}"
#echo "$extension ext"
cleanfilename="${filename%.*}"
#echo "$cleanfilename base"
if ! [ -a "${folder2}/$cleanfilename.$ext2" ]
then
echo $fullfile
fi
done
IFS=$SAVEIFS

it It shows files present in first folder but absent in second. like this:

admin$ mkdir 1
admin$ mkdir 2
admin$ touch 1/1.tiff
admin$ touch 1/2.tiff
admin$ touch 1/3.tiff
admin$ touch 2/1.png
admin$ touch 2/2.png
admin$ vim diff.sh
admin$ chmod +x diff.sh
admin$ ./diff.sh
/Users/admin/1/3.tiff

kubectl diff output to show only file names?

You can use, something as below, here KUBECTL_EXTERNAL_DIFF is an env variable, to use a custom diff program with custom flags. So, basically, here we are telling kubectl to use diff -qr for displaying the difference. By default, kubectl use diff -u -N.

KUBECTL_EXTERNAL_DIFF='diff -qr' kubectl diff -f .

Using output of `git diff --name-only` for file names with non-ASCII characters

How can I obtain a listing of the staged files that's useful for further processing?

Use a zero separated stream.

git diff -z --cached --name-only |
while IFS= read -r -d '' f; do
cat "$f"
done

See https://mywiki.wooledge.org/BashFAQ/020

Anyway, with just cat, then: git diff -z --cached --name-only | xargs -0 cat.

Can I make 'git diff' only display the line numbers AND changed file names?

Note: if you're just looking for the names of changed files (without the line numbers for lines that were changed), see another answer here.


There's no built-in option for this (and I don't think it's all that useful either), but it is possible to do this in Git, with the help of an "external diff" script.

Here's a pretty crappy one; it will be up to you to fix up the output the way you would like it.

#! /bin/sh
#
# run this with:
# GIT_EXTERNAL_DIFF=<name of script> git diff ...
#
case $# in
1) "unmerged file $@, can't show you line numbers"; exit 1;;
7) ;;
*) echo "I don't know what to do, help!"; exit 1;;
esac

path=$1
old_file=$2
old_hex=$3
old_mode=$4
new_file=$5
new_hex=$6
new_mode=$7

printf '%s: ' $path
diff $old_file $new_file | grep -v '^[<>-]'

For details on "external diff", see the description of GIT_EXTERNAL_DIFF on the Git manual page (around line 700, pretty close to the end).

diff with file names prefixing each line

I could not find a more concise solution, so I wrote my own script to do it, using several calls to diff to add a different prefix each time.

#!/bin/bash

# the first argument is the original file that others are compared with
orig=$1
len1=${#1}
shift

# we compute the length of the filenames to ensure they are aligned
for arg in "$@"
do
len2=${#arg}
maxlen=$((len1 > len2 ? len1 : len2))
prefix1=$(printf "%-${maxlen}s" "$orig")
prefix2=$(printf "%-${maxlen}s" "$arg")
diff --old-line-format="$prefix1:-%L" \
--new-line-format="$prefix2:+%L" \
--unchanged-line-format="" $orig $arg
echo "---" # not necessary, but helps visual separation
done


Related Topics



Leave a reply



Submit