Curious about differences between /bin, /usr/bin, and /usr/local/bin? What should be in the /sbin dir? Try this command to find out. Tested against Red Hat & OS X
Assumed dir A, B, C are subdirs of the current dir Exact syntax of the command is: rsync -v -r --size-only --compare-dest=/path_to_A/A/ /path_to_B/B/ /path_to_C/C/ (do not omit end-slashes, since that would copy only the names and not the contents of subdirs of dir B to dir C) You can replace --size-only with --checksum for more thorough file differences validation Useful switch: -n, --dry-run perform a trial run with no changes made
To create directory, use:
tempdir=$(/bin/mktemp -d)
Output of this command is the difference of recursive file lists in two directories (very quick!).
To view differences in content of files too, use the command submitted by mariusbutuc (very slow!):
diff -rq path_to_dir1 path_to_dir2
Show Sample Output
Display the size (human reading) of all the directories in your home path (~). Show Sample Output
as per eightmillion's comment. Simply economical :)
Very quick! Based only on the content sizes and the character counts of filenames. If both numbers are equal then two (or more) directories seem to be most likely identical.
if in doubt apply:
diff -rq path_to_dir1 path_to_dir2
AWK function taken from here:
http://stackoverflow.com/questions/2912224/find-duplicates-lines-based-on-some-delimited-fileds-on-line
Show Sample Output
It can be used to pinpoint the path(s) where the largest number of files resides when running out of free i-nodes Show Sample Output
If you want certain files out of a directory hierarchy, this will copy just the listed files, but will create the directory hierarchy in the new location ($DIR/)
This will list all symlinks that are directories under the current directory. This will help you distinguish them from regular files.
Compare the ls -Rl output of two directories in meld (you can also use diff -y instead of meld).
This will check if there are any empty directories, or newly emptied directories, in a list of directories. It will then delete all of those directories. It works with gnu find and OSX/BSD find.
I realise that this is just a reiteration of another entry (regardless of whether I came up with all this all by myself), but I would like present my additional alias' in context as a method of managing your directories. Rather convenient.
recursively delete empty directories and directories which only contain empty directories using zsh globbing syntax. ** is for recursive globbing. *(/^F) matches all entries that are directories which are not full.
If you only want to delete empty directories and not those directories which contained only empty directories and will be empty afterwards, just leave out the options to rmdir:
rmdir **/*(/^F)
Finds all files recursively from your working directory, matching 'aMethodName', except if 'target' is in that file's path. Handy for finding text without matching all your files in target or subversion directories.
It starts in the current working directory.
It removes the empty directory and its ancestors (unless the ancestor contains other elements than the empty directory itself).
It will print a failure message for every directory that isn't empty.
This command handles correctly directory names containing single or double quotes, spaces or newlines.
If you do not want only to remove all the ancestors, just use:
find . -empty -type d -print0 | xargs -0 rmdir
Great for backup / restore scripts. May want to remove the %M/%S to group backups by hour. If using a script, set a variable earlier with the date command, then reference that variable. Otherwise, time will keep on rolling ;-) declare -rx script_start_time="$(date '+./%Y/%m/%d/%H/%M/%S')" mkdir -p "$script_start_time" Show Sample Output
As output, checksums and filenames will be printed.
This version handles directory names with spaces properly
Compare the content of the files in the current directory with files of the same name in the duplicate directory.
Pop Quiz: You have a duplicate of a directory with files of the same name that might differ. What do you do?
You could use diff to compare the directories, but that's boring and it isn't as clever as find -print0 with xargs.
Note: You must omit stderr redirect 2>/dev/null to see the list of missing files from DUPDIR, if any.
Hint: Redirect stderr to a new file to produce a more readable list of files that are missing from DUPDIR.
Warning: This doesn't tell you if DUPDIR contains files not found in the current directory so don't delete DUPDIR.
Show Sample Output
The Windows Subsystem for Linux (WSL) is a compatibility layer for running binary Linux executables natively in Windows. A folder such as "C:\Program Files (x86)\Common Files" is represented as "/mnt/c/Program Files (x86)/Common Files". This function allows you to change the current directory to a Windows folder. Show Sample Output
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: