Use this tag for questions about file management and operations on files.
31
votes
11answers
6k 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 ...
30
votes
3answers
9k views
How to remove duplicate lines inside a text file?
A huge (up to 2 GiB) text file of mine contains about 100 exact duplicates of every line in it (useless in my case, as the file is a CSV-like data table).
What I need is to remove all the repetitions ...
27
votes
5answers
15k 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, ...
24
votes
2answers
4k 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 ...
22
votes
6answers
8k views
How can I edit multiple files in VIM?
I know I can open multiple files with vim by doing something like vim 2011-12*.log, but how can I switch between files and close the files one at a time? Also, how can I tell the file name of the ...
21
votes
4answers
2k 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:
...
19
votes
2answers
829 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 ...
17
votes
3answers
3k views
Reading lines from a file with bash: for vs. while
I'm trying to read a text file and do something with each line, using a bash script.
So, I have a list that looks like this:
server1
server2
server3
server4
I thought I could loop over this using ...
17
votes
4answers
695 views
Howto find duplicate files on disk
Is it possible to find duplicate files on my disk which are bit to bit identical but have different file-names?
17
votes
3answers
48k 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 ...
17
votes
4answers
4k 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)?
16
votes
3answers
2k views
Clone ownership and permissions from another file?
Is there a command or flag to clone the user/group ownership and permissions on a file from another file? To make the perms and ownership exactly "like" that of another file?
16
votes
2answers
736 views
How do I make a file NOT modifiable?
While logged in, I can do the following:
mkdir foo
touch foo/bar
chmod 400 foo/bar
chmod 500 foo
Then I can open vim (not as root), edit bar, force a write with w!, and the file is modified!
How ...
16
votes
1answer
502 views
How to implement a horizontal cat?
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 ...
15
votes
3answers
450 views
How can you trim files using the command line?
What is the console equivalent of the following Python code:
target = file("disk", "w") # create a file
target.seek(2*1024*1024*1024) # skip to 2 GB
target.write("\0")
target.close()
Maybe some ...
14
votes
4answers
3k 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 ...
13
votes
3answers
601 views
locate vs find: usage, pros and cons of each other
In Linux and Unix systems there are two common search commands: locate and find.
What are the pros and cons of each? When one have benefits over the other?
13
votes
2answers
7k 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.
13
votes
3answers
10k 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?
13
votes
2answers
2k 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 ...
13
votes
1answer
217 views
How to move a directory, file by file? (instead of “copy then remove”)
My computer has one 500GB drive.
I want to move 400GB of data from /unencrypted to /encrypted.
Both directories are on the same partition, but /encrypted is handled by ecryptfs, so mv /uncrypted/* ...
13
votes
1answer
5k 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% ...
12
votes
5answers
2k 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.
12
votes
2answers
502 views
What happens when you read a file while it is overwritten?
Suppose I read (cat) a file while another process is rewriting its contents. Is the output predictable? What would happen?
12
votes
2answers
808 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?
12
votes
4answers
2k views
How can I do a “copy if changed” operation?
I would like to copy a set of files from directory A to directory B, with the caveat that if a file in directory A is identical to a file in directory B, that file should not be copied (and thus its ...
12
votes
3answers
2k 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?
12
votes
1answer
2k views
ls taking long time in small directory
Running Ubuntu, I open a terminal and do
sudo bash
cd /
ls | head -n 1000
And predictably about 20 directories are returned.
However, if I do an ls, and don't pipe it into anything, the ls just ...
11
votes
6answers
1k views
Which extension to use for text files? (Unix/Linux)
I noticed that I can read text files without an extension .txt just fine. How come? Should I save these files with or without the .txt extension?
Also, what about .ini files? I usually use them like ...
11
votes
2answers
3k views
How tell gzip to keep original file?
I would like to compress a text file using gzip command line tool while keeping the original file. By default running the following command
gzip file.txt
results in modifying this file and renaming ...
11
votes
2answers
538 views
“ls -lh” reports total size less than sum of individual sizes
Under what circumstances would ls -lh show a total that is less than the sum of the individual files? For example:
$ ls -lh /var/lib/nova/instances/_base
total 100G
-rw-rw-r-- 1 nova nova ...
11
votes
5answers
6k 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 ...
11
votes
2answers
290 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 ...
11
votes
2answers
7k views
timestamp, modification time, and created time of a file
I just know that ls -t, -f give different sorting of files and subdirectories under a directory.
Now I wonder what are the differences between timestamp, modification time, and created time of a ...
11
votes
6answers
6k views
How do I can get the size of a file in a bash script?
How do I can get the size of a file in a bash script?
How do I assign this to a bash variable so I can use it later?
11
votes
3answers
1k 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 ...
11
votes
4answers
282 views
Is there a top-like command that shows the network bandwidths and file accesses of running processes
For example, we'd like to see:
PROCESS IF TX RX FILE(regular) R/W
prog1 eth0 200kB/s 12kB/s -- --
wlan0 12kB/s 100kB/s -- ...
10
votes
5answers
741 views
How to list all files in the size order
I would like to list all files in the order of big to small in size and the files could be present anywhere in a certain folder.
10
votes
3answers
1k views
What happens when you delete a hard link?
If you do rm myFile where myFile is a hard link, what happens?
10
votes
1answer
3k views
What does dead.letter files do
I find dead.letter files from time to time in my $HOME directory. What they are for?
10
votes
1answer
4k views
How to skip “permission denied” errors when running find in Linux? [duplicate]
Possible Duplicate:
How do I remove “permission denied” printout statements from the find program?
When I run this command in Linux (SuSE):
find / -name ant
I get many error ...
9
votes
2answers
1k views
How can I find out how many lines a text file contains without viewing it?
How can I find how many lines a text file contains without opening the file in an editor or a viewer application? Is there a handy Unix console command to see the number?
9
votes
4answers
4k views
What's the best way to join files again after splitting them?
If I have a large file and need to split it into 100 megabyte chunks I will do
split -b 100m myImage.iso
That usually give me something like
xaa
xab
xac
xad
And to get them back together I have ...
9
votes
3answers
1k views
Are two files hardlinked?
How can I tell if two files are hard-linked from the command line? e.g. something link this:
$ ls
fileA fileB fileC
$ is-hardlinked fileA fileB
yes
$ is-hardlinked fileA fileC
no
9
votes
2answers
763 views
How can I delete all files in a folder that haven't been accessed in a certain amount of time?
I'd like to run a nightly cron job that deletes all the files in a folder that haven't been accessed in a week or more. What is the most efficient way to do this in bash?
9
votes
5answers
385 views
What Windows-related files are valueless to *nix users?
I have accumulated, from my time using Windows a good quantity of held-over filesystem copies and archives of system and data drives. I am trying to distill them down to the usable parts while ...
9
votes
4answers
967 views
Creating an arbitrarily large “fake” file
I would like to create a special file similar to /dev/null or /dev/random, where the file doesn't actually exist but you can read from it all the same, except that I could actually set a cap on the ...
9
votes
6answers
309 views
How to copy every 4th file in a folder
I have a lot of files in a folder, named like 00802_Bla_Aquarium_XXXXX.jpg. Now I need to copy every 4th file to a subfolder, saying in selected/.
00802_Bla_Aquarium_00020.jpg <= this one
...
9
votes
2answers
1k views
recursive statistics on file types in directory?
I did a website scrape for a conversion project. I'd like to do some statistics on the types of files in there -- for instance, 400 .html files, 100 .gif, etc. What's an easy way to do this? It has to ...
9
votes
2answers
20k views
How to get over “device or resource busy”?
I tried to rm -rf a folder, and got "device or resource busy".
In Windows, I would have used LockHunter to resolve this. What's the linux equivalent? (Please give as answer a simple "unlock this" ...