Sponsored Content
Full Discussion: Viewing changes in directory
Top Forums UNIX for Beginners Questions & Answers Answers to Frequently Asked Questions Tips and Tutorials Viewing changes in directory Post 302590000 by tukuyomi on Friday 13th of January 2012 11:16:50 AM
Old 01-13-2012
I just wrote this script in reply for this topic, but I think I'll use for my personal usage as well Smilie
Hope someone else will find it useful Smilie
Code:
#!/bin/sh

F1=$(mktemp); F2=$(mktemp); F3=$(mktemp)
CMD=${CMD:='ls -l'}
echo "Watching ${DIR:=${1:-$PWD}}"

${CMD} "$DIR" > "$F1"
while :; do
	trap break 2
	${CMD} "$DIR" > "$F2"
	grep -Fvf "$F1" "$F2" > "$F3"; x="$?"
	[ "$x" -eq 0 ] && { echo 'Created or modified files:'; cat "$F3";}

	grep -Fvf "$F2" "$F1" > "$F3"; y="$?"
	[ "$y" -eq 0 ] && { echo 'Deleted files:'; cat "$F3";}
	
	[ $((x+y)) -ne 2 ] && mv "$F2" "$F1"

	sleep 1
done

rm "$F1" "$F2" "$F3"

Code:
Usage: ./script [directory]
You can change the command used for checking directories with CMD variable.
Directory can also be changed with DIR variable:
[DIR=/home/unix.com] [CMD='ls -l'] ./script
If no directories are given, the current directory is watched.


Last edited by tukuyomi; 01-13-2012 at 12:24 PM.. Reason: Added usage
This User Gave Thanks to tukuyomi For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Viewing files in a directory?

How do I view files in a directory? (1 Reply)
Discussion started by: Ania
1 Replies

2. UNIX for Dummies Questions & Answers

viewing tables

I have completely blanked out on this and I have done it a million times. I need to modify some tables in unix. What is the command for opening/viewing the tables? Thanks so much. :o (2 Replies)
Discussion started by: itldp
2 Replies

3. UNIX for Dummies Questions & Answers

pdf viewing

How do I view pdf files on a Solaris 9 environment? Links and such would be grateful. "AAAAHHH!! They're everywhere!!!" - Halo Grunt (3 Replies)
Discussion started by: antalexi
3 Replies

4. UNIX for Dummies Questions & Answers

Viewing files

I have a file (called CORE) that is a dump created by a crashing process. This file, I believe, is in "binary" form, so when I try to use cat, more, or vi on it, it has a bunch of garbage. Is there anything I can use to "read" or view this file just like I might a non-binary file? I am running... (2 Replies)
Discussion started by: dsimpg1
2 Replies

5. UNIX for Dummies Questions & Answers

Viewing Directory Content as You Navigate Directories in UNIX

Hi, Can someone help me figure out how to view directory content while I navigate directories (without having to go to the actual directory and "ls-ing" it)? Is there some keyboard shortcut for this? For instance, it would be useful if I could see the content of a directory when I'm copying... (2 Replies)
Discussion started by: shelata
2 Replies

6. UNIX for Dummies Questions & Answers

Bourne shell viewing files in directory

Hi, I have a program that get a directory name from the user, then the program should go through one by one of the file, asking the user whether to move it to another folder. I tried to list the time of the file one by one. But it seems like it doesn't work. The code is as follow: check() {... (10 Replies)
Discussion started by: mInGzaiii
10 Replies

7. Shell Programming and Scripting

viewing lines

Hey, I know the head and tail function is to view like the top or bottom lines for each file. But lets say I want to view the top/bottom 100 or top/bottom 1000 for a file. whats the command that I use to do this? thanks (2 Replies)
Discussion started by: kylle345
2 Replies

8. UNIX for Advanced & Expert Users

HP-UX: Problem viewing directory with BDF...

Hi all, When I use BDF command on this particular server, it outputs mostly normal stuff. However, there is one directory it can't read at all. Also, it doesn't seem to exist. When I BDF my file system with a small panic script (it happens even if you use just the bdf command): As you... (17 Replies)
Discussion started by: zixzix01
17 Replies

9. Shell Programming and Scripting

Help with viewing the Log files

I have a file name as logfiles_tar.tgz. How can I view the contents of the log files present in logfiles_tar.tgz ? Any help would be really appreciated. Thanks (3 Replies)
Discussion started by: bobby1015
3 Replies

10. UNIX for Dummies Questions & Answers

Viewing file size in current directory

What is the command line for viewing the sizes(lines and bytes)of all the files in your present working directory? Is it >ls -la (2 Replies)
Discussion started by: Payton2704
2 Replies
MKTEMP(1)							   User Commands							 MKTEMP(1)

NAME
mktemp - create a temporary file or directory SYNOPSIS
mktemp [OPTION]... [TEMPLATE] DESCRIPTION
Create a temporary file or directory, safely, and print its name. TEMPLATE must contain at least 3 consecutive 'X's in last component. If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and --tmpdir is implied. Files are created u+rw, and directories u+rwx, minus umask restrictions. -d, --directory create a directory, not a file -u, --dry-run do not create anything; merely print a name (unsafe) -q, --quiet suppress diagnostics about file/dir-creation failure --suffix=SUFF append SUFF to TEMPLATE; SUFF must not contain a slash. This option is implied if TEMPLATE does not end in X -p DIR, --tmpdir[=DIR] interpret TEMPLATE relative to DIR; if DIR is not specified, use $TMPDIR if set, else /tmp. With this option, TEMPLATE must not be an absolute name; unlike with -t, TEMPLATE may contain slashes, but mktemp creates only the final component -t interpret TEMPLATE as a single file name component, relative to a directory: $TMPDIR, if set; else the directory specified via -p; else /tmp [deprecated] --help display this help and exit --version output version information and exit AUTHOR
Written by Jim Meyering and Eric Blake. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report mktemp translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
mkstemp(3), mkdtemp(3), mktemp(3) Full documentation at: <http://www.gnu.org/software/coreutils/mktemp> or available locally via: info '(coreutils) mktemp invocation' GNU coreutils 8.28 January 2018 MKTEMP(1)
All times are GMT -4. The time now is 07:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy