Tag Info

New answers tagged

0

In Linux based systems it is nearly impossible to restore files once deleted. What you should do in this case is to retrieve the broken directory from your saved backups. You are making periodic backups right? Otherwise, depending on which directory you removed you might have to either identify and reinstall a bunch of packages or do a total system ...


6

rmdir will delete empty folders (while leaving other folders alone), so you can use something like: rmdir */ Or, if you're using bash 4+ and you want recursiveness (other shells have other names for the same thing): shopt -s globstar rmdir **/ This will give you a lot of error messages, however (one for every non-empty folder).


2

There's a little utility called rmtrash which does this. It doesn't seem to respond to params like -r or -f (it appears to essentially just be moving the file/directory to the ~/.Trash directory), but it won't override files with the same name (it appends "Copy" to like-named files/directories). To install with brew brew install rmtrash alias ...


0

OK, I would do this assuming that the logs are being created daily: #!/bin/sh day=$(date +%u)#To get a day of the week day_num=$(date +%d) #To get the current day month=$(date +%m) #To get the current month year=$(date +%Y) #Get current year date=$(date +%Y%m%d) #Get current date if [ $day -eq 7 ] #Saving only Sunday log then sunday_day=$(date +%Y%m%d) ...


1

You want logrotate http://linuxcommand.org/man_pages/logrotate8.html. It is probably already on your system. You just need to configure it. However it is mainly for the purpose of purging old log files and I don't know if you can configure it to keep one file. What you can do create several directories log, log.weekly, log.monthly, and log.yearly log ...


4

rm is a utility use to remove directory entries in *nix system. POSIX defined rm as: NAME rm - remove directory entries and -f option: -f Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored. So ...


0

So here you have this all in one:- mv com/com/ SOME-TEMPORARY-NAME ; rm -rf com ; mv SOME-TEMPORARY-NAME com The ; simply lets you run all the commands in one go. And then I have used rm -rf so that even if you have any other files inside com/ all will be removed without user-interaction.


0

The only way to accomplish this is to move the "various files" up a level and then remove the second "com" directory. Example $ mv com/com/(various files) com/. $ rmdir com/com


2

Rename the outer directory out of the way, move the inner one to the name you want, and then delete the (now empty) outer directory: $ mv com to-delete $ mv to-delete/com com $ rmdir to-delete You could also mv com/com/* com and remove the inner directory, if you don't have too many files and none of them are dotfiles, but the above is more general and ...


13

Anytime you have these types of questions it's best to conceive of a little test to see what's actually happening. For this you can use strace. unlink $ touch file1 $ strace -s 2000 -o unlink.log unlink file1 rm $ touch file1 $ strace -s 2000 -o rm.log rm file1 When you take a look at the 2 resulting log files you can "see" what each call is actually ...


4

With a single file, rm and unlink do the same task, remove the file. As POSIX defined, rm and unlink both call to unlink() system call. In GNU rm, it calls to unlinkat() system call, which is equivalent to the unlink() or rmdir() function except in the case where path specifies a relative path. Note On some systems, unlink can also remove directory. At ...



Top 50 recent answers are included