commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
rm -rf .* matches ".." and thus one goes up a level and wipes out more than intended.
In bash, .??* safely accomplishes what one intends - remove those .files
The ? matches most characters except "/", thus .?? does not match ../ and so one is safe.
Remove all arquives except the list.
Can't have space between the commas.
Bash method to remove all files but "abc".
It would be 'rm *~abc' in Zsh.
-depth argument will cause find to do a "depth first" tree search, this will eliminate the "No such file or directory" error messages
expands through shell and not find
but may hits the limit of max argument size for rm
(thus: for f in **/*.htm;do rm $f;done
but then I prefer the find command ;)
This is for zsh with extended globbing.
An alternative which uses the advanced zsh globbing (pattern matching)
Really, you deserve whatever happens if you have a whitespace character in a file name, but this has a small safety net. The truly paranoid will use '-i'.
Please be careful while executing the following command as you don?t want
to delete the files by mistake. The best practice is to execute the same
command with ls ?l to make sure you know which files will get deleted when
you execute the command with rm.
This will search all directories and ignore the CVS ones. Then it will search all files in the resulting directories and act on them.
This is a slight variation of an existing submission, but uses regular expression to look for files instead. This makes it vastly more versatile, and one can easily verify the files to be kept by running ls | egrep "[REGULAR EXPRESSION]"
Remove all empty directories below the current directory. If directories become empty as the results of this, remove those too.
it will remove everything except the file names matching you can use also use wildcards
Remove everything except that file with shell tricks inside a subshell to avoid changes in the environment.
This is an useful command for when your OS is reporting less free RAM than it actually has. In case terminated processes did not free their variables correctly, the previously allocated RAM might make a bit sluggis over time.
This command then creates a huge file made out of zeroes and then removes it, thus freeing the amount of memory occupied by the file in the RAM.
In this example, the sequence will free up to 1GB(1M * 1K) of unused RAM. This will not free memory which is genuinely being used by active processes.
Remove everything in current directory except files starting with "ca".
avoid rm to be recursive until you complete the command: put the -rf at the end!
Deletes empty directories and prints an error if directory is not empty.