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

learn more… | top users | synonyms (1)

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 ...
7
votes
3answers
1k views

How to run a command when a directory's contents are updated?

There is a directory A whose contents are changed frequently by other people. I have made a personal directory B where I keep all the files that have ever been in A. Currently I just occasionally ...
38
votes
4answers
7k views

What's the point in adding a new line to the end of a file?

Some compilers (especially C or C++ ones) give you warnings about: No new line at end of file I thought this would be a C-programmers-only problem, but github displays a message in the commit view: ...
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 ...
22
votes
5answers
13k views

Determine which process is creating a file

Given file path, how can I determine which process creates it (and/or reads/writes to it)?
31
votes
2answers
13k views

Why can rm remove read-only files?

If I create a file and then change its permissions to 444 (read-only), how come rm can remove it? If I do this: echo test > test.txt chmod 444 test.txt rm test.txt ...rm will ask if I want to ...
6
votes
2answers
3k views

How can I rename a lot of files using a regex?

I want to rename a lot of files on Mac OS X (10.7.2).. I don't have the perl package for the rename command. My files have names like "T452-102456-0.png" and I want to delete the "-0" part. I know I ...
39
votes
5answers
28k 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, ...
4
votes
2answers
784 views

undelete files from local fileserver

I have a NAS (mybook world white light) in my living room where all my music and stuff is stored. I've mounted the music folder of the nas in the local music folder of my home directory on my desktop ...
3
votes
1answer
2k views

Rename All Files with a Certain Name

I'm trying to find certain files with the name "stringx" and replace the name (but not the extension) with "stringy". So basically for stringx.txt and stingx.cs, I'd want stringy.txt and stringy.cs. ...
27
votes
2answers
22k views

How do I do a ls and then sort the results by date created?

In what order are the dated ordered by? Certainly not alphanumeric order. ls -lt sorts by modification time. But I need creation time.
14
votes
3answers
5k views

How to list files that were changed in a certain range of time?

How can I list recursively all files that were changed between 22.12.2011 and 24.12.2011?
19
votes
5answers
15k views

How to find creation date of file?

I want to find out the creation date of particular file, not modification date or access date. I have tried with ls -ltrh and stat filename.
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 ...
8
votes
6answers
7k views

Shell script for moving oldest files?

How do I write a script for moving just the 20 oldest files from one folder to another? Is there a way to grab the oldest files in a folder?
25
votes
2answers
24k 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 ...
21
votes
1answer
19k views

How can I increase the number of inodes in an ext4 filesystem?

I had a problem (new to me) last week. I have a ext4 (Fedora 15) filesystem. The application that runs on the server suddenly stopped. I couldn't find the problem at first look. df showed 50% ...
15
votes
5answers
3k 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
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.
49
votes
15answers
13k 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 ...
14
votes
5answers
22k views

Script to monitor folder for new files?

How do I detect new files in a folder with a bash script? I would like to process the files as soon as they are created in the folder. Is this possible to do so or do I have to schedule a script with ...
7
votes
4answers
799 views

Can a file that was originally sparse and expanded be made re-sparse

I know that copying or transferring what was originally a sparse file without using a utility that understands sparse files will cause the 'holes' to be filled out. Is there a method or utility to ...
6
votes
4answers
4k views

Renaming a bunch of files with date modified timestamp at the end of the filename?

So, say, I have a directory with a bunch of files like g.txt, where g.txt was last modified on, say, June 20, 2012. How would I batch-rename all of the files (like g.txt) with the last modified date ...
8
votes
2answers
339 views

Cleaner way to delete files on Linux which include a datestamp as part of file name

I have a new requirement to purge MySQL dump files that are older than 30 days. The files use a naming convention of "all-mysql-YYYYMMDD-HHMM.dump". The files are located on SAN mounted file system, ...
6
votes
1answer
5k views

Cannot delete a file - permission denied - why?

[db2inst1][testing ~/sqllib/db2dump] rm db2diag.log rm: cannot remove `db2diag.log': Permission denied [db2inst1][testing ~/sqllib/db2dump] id uid=1002(db2inst1) gid=107(db2iadm1) ...
6
votes
7answers
2k views

Bash, remove oldest files

I`m trying to delete old files from directory and leave only 3 newest files. cd /home/user1/test while [ `ls -lAR | grep ^- | wc -l` < 3 ] ; do rm `ls -t1 /home/user/test | tail -1` ...
3
votes
3answers
659 views

get age of given file

How can I get the age of a given file in, at least, days? I'm well aware of ls -lh and similar commands. I want something that will work sort of like this: getfage <FILE> # prints out '12d' ...
4
votes
2answers
1k views

Access history of a file

I was wondering if there are any tools to keep track of the access history of a file. I know of stat, but as far as I understand, it only returns information about the last time the file was accessed. ...
21
votes
12answers
27k views

Efficiently delete large directory containing thousands of files

We have an issue with a folder becoming unwieldy with hundreds of thousands of tiny files. There are so many files that performing rm -rf returns an error and instead what we need to do is something ...
20
votes
1answer
874 views

How to implement a horizontal cat? [duplicate]

Standard cat concatenates files line by line (row by row, if you will). I find myself needing a horizontal cat command more and more often recently; i.e. a command that takes a list of files and ...
19
votes
4answers
7k views

How to properly and easy configure `xdg-open` without any enviroment?

I'm using OpenBox window manager without any desktop enviroment. xdg-open behaves strangely. It opens everything with firefox. $ xdg-settings --list Known properties: default-web-browser ...
10
votes
7answers
9k views

How to move 100 files from a folder containing thousands?

I have a directory with thousands of files. How can I move 100 of the files (any files will do) to another location.
13
votes
2answers
411 views

How can I be sure that a directory or file is actually deleted?

I know that most files, when deleted, aren't actually removed from the disk, and can be recovered later. How can I ensure that a directory I had deleted will actually be removed from the disk? Are ...
9
votes
5answers
2k 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 ?
7
votes
6answers
6k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
33
votes
3answers
105k views

Get file created/creation time? [duplicate]

Possible Duplicate: How do I do a ls and then sort the results by date created? Is there a command in Linux which displays when the file was created ? I see that ls -l gives the last ...
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 ...
5
votes
1answer
2k views

How to circumvent “Too many open files” in debian

If I want to see all relevant log files of my apache2 server at once, I use tail -f /var/kunden/logs/*log /var/kunden/logs/*log /var/log/apache2/*log |grep -v robots|grep -v favicon But since those ...
3
votes
2answers
752 views

Concatenate specific files into one single file

In a folder containing X files, I need to concatenate Y files (where X > Y) together into a single text file. I have the filenames (of Y files) that I need to concatenate. Can anyone please help me ...
11
votes
1answer
1k views

Who creates /etc/{group,gshadow,passwd,shadow}-?

In any linux system I have access to (a couple of Archlinuxes, an Ubuntu, a Debian Sid and a Gentoo) there are the following 4 files in /etc/, all ending with a dash: /etc/group- /etc/gshadow- ...
8
votes
4answers
3k views

How are directories implemented in Unix filesystems?

My question is how directories are implemented? I can believe a data structure like a variable e.g. table, array or similar. Since UNIX is Open Source I can look in the source what the program does ...
7
votes
1answer
3k views

Why can't I have a folder and a file with the same name?

I've never had this problem before, but for some reason, I can't rename my folder to packages/. This is the structure: root - packages_old/ - packages When I try to rename the folder with ...
5
votes
4answers
350 views

Delete all files in a directory whose name do not match a line in a file list

I have a directory with 1000+ files. In a text file, I have about 50 filenames, one per line. I'd like to delete all the files in the directory whose filenames don't correspond with an entry on the ...
3
votes
1answer
292 views

How does the Linux file structure work?

I see the different folders bin, dev, mnt, proc, srv, sys, etc. What are the properties of all these different folders? What are there purposes? Are there files in some of them that I should not ...
8
votes
3answers
2k views

How to remove only the content of directories?

I'm in a folder: /var/myfolder. Inside there are some other folders like: /var/myfolder/A/ /var/myfolder/B/ `/var/myfolder/C/ etc. Inside each there are some files with random names. How do I ...
6
votes
3answers
150 views

Find the top 50 directories containing the most files/directories in their first level?

How can I use find to generate a list of directories which contain the most numbers of files. I'd like the list to be from highest to lowest. I'd only like the listing to go 1 level deep, and I'd ...
6
votes
5answers
1k views

Find images by size: find / file / awk

I've been trying to find png image files a certain height (over 500px). I know that file will return image dimensions. Example: $ file TestImg1a.png TestImg1a.png: PNG image data, 764 x 200, ...
6
votes
1answer
5k views

Group within group file permissions

I tried finding this on here, but couldn't so sorry if it's a duplicate. Say I have 2 groups and a user: group1, group2, user1 with the following structure: group1 is a member of group 2, user1 is a ...
4
votes
3answers
74 views

Local Account Creation Date

For compliance purposes there is the need to fetch information regarding local (user and non-user) accounts creation date on UNIX machines. Is there any way (even if it's not the most reliable or ...
4
votes
1answer
141 views

When was file created [duplicate]

How can i see when a file was created. I have looked at man page ls -lc is for last modification of file status ls -lu for access time ls -l not exactly indicated which time, last changed? I ...