# Tag Info

## Hot answers tagged files

234

I've had success with Sysinternals Process Explorer. With this, you can search to find what process(es) have a file open, and you can use it to close the handle(s) if you want. Of course, it is safer to close the whole process. Exercise caution and judgement. To find a specific file, use the menu option "Find->Find Handle or DLL..." Type in part of the ...

109

Yes, you can change the attributes of the file to read-only. The command is: chattr +i filename And to disable it: chattr -i filename From man chattr: A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process ...

74

You can create a symbolic link with the command line utility mklink. MKLINK [[/D] | [/H] | [/J]] Link Target /D Creates a directory symbolic link. Default is a file symbolic link. /H Creates a hard link instead of a symbolic link. /J Creates a Directory Junction. Link specifies the new ...

72

unlocker is also useful for this (works on both 32 and 64 bit)

72

Burn it to a CD. Put the CD in a CD-ROM drive and access it from there.

60

Try the openfiles command.

38

Just be very careful with closing handles; it's even more dangerous than you'd think, because of handle recycling - if you close the file handle, and the program opens something else, that original file handle you closed may be reused for that "something else." And now guess what happens if the program continues, thinking it is working on the file (whose ...

33

No. "rm -rf" does a recursive depth-first traversal of your filesystem, calling unlink() on every file. The two operations that cause the process to go slowly are opendir()/readdir() and unlink(). opendir() and readdir() are dependent on the number of files in the directory. unlink() is dependent on the size of the file being deleted. The only way to make ...

32

Millions is a big number - I'll get back to that later. Regardless of your approach, the underlying mechanism needs to be copying directly from one bucket to another - in this way (since your buckets are in the same region) you do not incur any charge for bandwidth. Any other approach is simply inefficient (e.g. downloading and reuploading the files). ...

28

On Windows XP you can use fsutil (built into the OS) to create a hardlink fsutil hardlink create c:\foo.txt c:\bar.txt Keep in mind fsutil will only work if both are on same drive

24

rsync -aplx --link-dest=dir1/ dir1/ merged/ rsync -aplx --link-dest=dir2/ dir2/ merged/ This would create hardlinks rather than moving them, you can verify that they were moved correctly, then, remove dir1/ and dir2/

24

Create a file system image. Mount the image. Copy the file to the mounted image. Unmount the image and remount it as read-only. Now you can't delete it. Example: # dd if=/dev/zero of=readonly.img bs=1024 count=1024 # mkfs.ext2 readonly.img # mkdir readonlyfolder # mount readonly.img readonlyfolder/ # echo "can't delete this" > ...

23

I've used Handle with success to find such processes in the past.

21

Don't tar. Use rsync -av to preserve permissions while transfering the files. Though like tar, this does not preserve selinux context. Not that I would consider that important though.

18

As an alternative, move the directory aside, recreate it with the same name, permissions and ownership and restart any apps/services that care about that directory. You can then "nice rm" the original directory in the background without having to worry about an extended outage.

17

There's two parts to this question: when to add a new FILEGROUP, and when to add a new FILE in a filegroup. First let's talk theory: Mark's right about the primary reason being performance. The secondary reason is disaster recovery. With SQL Server 2005 and newer, you can do filegroup restores. When disaster strikes, you can restore just your primary ...

17

The -L flag to rsync will sync the contents of files or directories linked to, rather than the symbolic link.

17

Probably a trailing new-line character. For example, a file created in a text editor containing only an 'a' may actually contain 2 bytes: $cat /tmp/test_text | hexdump -C 00000000 61 0a |a.| 00000002 However, using echo -n (no new line) gives us a size of 1 byte:$ echo -n 'a' > /tmp/test_text $ls -l ... 16 Using --link-dest to create space-efficient snapshot based backups, whereby you appear to have multiple complete copies of the backedup data (one for each backup run) but files that don't change between runs are hard-linked instead of creating new copies saving space. (actually, I still use the rysnc-followed-by-cp -al method which achieves the same thing, ... 16 On the containing folder you'll want to change the group to be dev and then use mark it set-gid. chgrp dev <containing-folder> chmod g+ws <containing-folder> The set gid bit makes files created in that folder to inherit the group of the folder as well as marking the setgid bit on any new folders. You'll want to be careful when moving files ... 16 It's strange nobody noted that cp has option "-l": -l, --link hard link files instead of copying You can do something like % mkdir merge % cp -rl dir1/* dir2/* merge % rm -r dir* % tree merge merge ├── a │ ├── file1.txt │ ├── file2.txt │ ├── file5.txt │ └── file6.txt ├── b │ ├── file3.txt │ ├── file7.txt │ └── file8.txt └── c ... 15 locate filename Much faster than find, if you're running the locate service, and it only finds files that existed at the time updatedb last ran (usualy the night befor under the control of a cron job). You can run updatedb by hand, but that is even slower than the find cletus suggests, and requires root. I sometimes update the database by hand after ... 15 The tool your looking for is rdiff. It works like combining rsync and diff. It creates a patch file which you can compare, or distribute. 15 Try to use rsync version 3 if you have to sync many files! V3 builds its file list incrementally and is much faster and uses less memory than version 2. Depending on your platform this can make quite a difference. On OSX version 2.6.3 would take more than one hour or crash trying to build an index of 5 million files while the version 3.0.2 I compiled ... 15 sed '5555,7777!d' <filename> This will print lines 5555-7777 of the file inclusively. Dennis Posted the following which I agree should be faster: sed '5555,7777p; 7778q' filename The following evidence that it should be faster:$ n=1 $while [[ n -le 100000 ]]; do echo$n >> sedtest2; n=$((n + 1)); done$ strace -e trace=read -o sed1 sed ...

15

An extra byte is for the line end at the end of the file, it's quite common for Linux text editors to add this line end after the last line.

14

For Windows 7 and Windows 8 you can use the built-in Resource Monitor for this. Open Resource Monitor, which can be found By searching in the start menu, or As a button on the Performance tab in your Task Manager Use the search field in the Associated Handles section on the CPU tab Pointed at by blue arrow in screen shot below In case it's not ...

14

You can use systemtap to show all PIDs that are trying to use unlink() on the inode of .bashrc and .bash_profile files. Install systemtap and the debug symbols for your kernel. Create a file with name unlink.stap with the following content: probe syscall.unlink { printf ("%s(%d) unlink (%s) userID(%d)\n", execname(), pid(), argstr, uid()) } Then ...

13

I do love lsof, but I think it's overkill for a simple question like this. The /proc filesystem contains everything you want to know. Perhaps an example would be best: # ps ax|grep tail 7196 pts/4 S+ 0:00 tail -f /var/log/messages 8773 pts/0 R+ 0:00 grep tail # ls -l /proc/7196/cwd lrwxrwxrwx 1 insyte insyte 0 2009-07-29 19:05 ...

13

The command df(1) takes one or more arguments and will return the mountpoint and device on which that file or directory exists, as well as usage information. You can then use the path or device to look up the filesystem type in the output of mount -v or similar. Unfortunately, the output format of both df and mount are system-dependent; there is no ...

Only top voted, non community-wiki answers of a minimum length are eligible