Use this tag for questions about file management and operations on files.

learn more… | top users | synonyms (1)

4
votes
2answers
799 views

rm -rf failing if deleting in parallel

rm -rf will fail if something tries to delete the same file tree (I think because rm enumerates the files first, then deletes). A simple test: # Terminal 1 for i in `seq 1 1000`; do mkdir -p ...
14
votes
2answers
3k views

How do open files behave on linux systems?

I just renamed a log file to "foo.log.old", and assumed that the application will start writing a new logfile at "foo.log". I was surprised to discover that it tracked the logfile to its new name, and ...
0
votes
1answer
1k views

How to copy files nested in directories that match a pattern?

I'm looking to copy files from subdirectories that match this pattern vendor/plugin/*/tasks/*.rake into a folder lib/tasks I think that this could be done several ways, but wanted to see if a ...
4
votes
2answers
517 views

Find incoming symlinks

In Linux, what is the best way to find all symbolic links that point to a given file (regardless of whether the symlink is relative or absolute)? I realize this will require scanning the whole ...
7
votes
4answers
6k views

Number of files containing a given string

How can I count the number of files (in a directory) containing a given string as input in bash/sh?
11
votes
4answers
8k views

Use of O_DIRECT on Linux

If this question is too programmer oriented, let me know. I wonder if there are people familiar with the O_DIRECT flag for the open() system call on Linux 2.6? Linus disparages its use, however high ...
13
votes
4answers
3k views

Is it possible to find out what program or script created a given file?

Three files have suddenly appeared in my home directory, called "client_state.xml", "lockfile", and "time_stats_log". The last two are empty. I'm wondering how they got there. It's not the first time ...
9
votes
3answers
2k views

Can I make `cut` change a file in place?

The man page doesn't give me much hope, but I'm hoping it's an undocumented (and/or GNU-specific) feature.
27
votes
3answers
2k views

Can a bash script be hooked to a file?

I want a script to sleep unless a certain file is modifed/deleted (or a file created in a certain directory, or ...). Can this be achieved in some elegant way? The simplest thing that comes to my mind ...
15
votes
2answers
2k views

How can I count the number of different characters in a file?

I would need a program, that outputs the number of the different characters in a file. Example: > stats testfile ' ': 207 'e': 186 'n': 102 Exists any tool, that do this?
3
votes
1answer
401 views

How to recover a missing file

I am running ubuntu and last week the system didn't let me alter files as if I had no write permissions. Then on reboot the system did a check of the system which took some time. Then everything went ...
43
votes
5answers
32k views

What is a Superblock, Inode, Dentry and a File?

From the article Anatomy of Linux File Systems by Tim Jones, I read that Linux views all the file systems from the perspective of a common set of objects and these objects are superblock, inode, ...
8
votes
3answers
462 views

Why do tar and gzip files usually have a file extension?

File extensions are not necessary on unices, still every tarred, gzipped or bzipped file I encounter has a file extension like .tar, .tar.gz or .tgz. Is there any special reason for that or is that ...
20
votes
3answers
33k views

How to merge all (text) files in a directory into one?

I've got 14 files all being parts of one text. I'd like to merge them into one. How to do that?
18
votes
1answer
12k views

What does dead.letter files do

I find dead.letter files from time to time in my $HOME directory. What they are for?
2
votes
1answer
193 views

Prevent libflashplayer.so from deleting a file?

I'm trying the preview release of Flash Player "Square" for Linux and noticed that video files are now being deleted from the /tmp/ folder. Yet the files are still in use (I can see them with lsof): ...
51
votes
15answers
15k views

Is there an easy way to replace duplicate files with hardlinks?

I'm looking for an easy way (a command or series of commands, probably involving find) to find duplicate files in two directories, and replace the files in one directory with hardlinks of the files in ...
2
votes
3answers
202 views

archive files and directories before transfer

I was wondering what is the advantage of making all the files and directories into an archive file for transfer, such as by cpio, instead of transferring them directly, such as by cp, scp?
27
votes
2answers
32k views

timestamp, modification time, and created time of a file

I just know that ls -t and ls -f give different sorting of files and subdirectories under a directory. What are the differences between timestamp, modification time, and created time of a file? How ...
9
votes
5answers
3k views

How to create a file even root user can't delete it

How to create a file even root user can't delete it ?
3
votes
1answer
4k views

Error when using stat, errno=2

The case is as this, I create many files, and after the file generation, I use stat to get the all files info under the directory. The purpose is to purge all the files which are old than the ...
4
votes
2answers
2k views

Remove a corrupted file in a Linux system

How to remove a file that is corrupted? In Linux (Fedora based), when I type: ls -l I get drwxr-xr-x. 2 dmiller3 dmiller3 4096 Jul 26 13:57 SomeFile ?????????? ? ? ? 4096 ...
15
votes
3answers
17k views

How to find binary executables within a directory

How do I list all binary executable files recursively within a directory? I use find command like this: find /mydir/mysubdir -executable -type f All executable files are listed (excluding ...
8
votes
6answers
240 views

Grab certain contents of a file

So I know tools exist for this problem because I've heard about them, but I don't know what they are. I want to do something like filter out all data but the usernames in /etc/passwd. For example, I ...
14
votes
3answers
2k views

I accidentally chmod -R +x on a directory. How do I restore the correct permissions?

Well, to be specific, it was chmod -R 755. Now every file is executable, which I don't want. I am thinking that I should look at the first two bytes of each file for the #!, but will this cover ...
2
votes
1answer
1k views

How to zip individual files from different directories in one line?

I want to zip numerous files from different directories(paths) in one line. How can I do that?
15
votes
5answers
4k views

How can I edit a large file in place?

I have a few files sized > 1 GB each. I need to remove last few bytes from the files. How can I do it? I prefer to edit file in place to save disk space. I am on HP-UX.
9
votes
5answers
5k views

Keep log file size fixed without logrotate

Is there any way to keep file size of log file fixed without rotating it by a new empty file and deleting (or archiving) the old file. For example, if I set log file maximum size to 1MB, after the ...