Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
To switch two filenames in place I can:
mv first firstTmp
mv second first
mv firstTmp second
Is this possible with simple one-liner, and preferably without using temporal filename?
You just think, how will it be possible without using a temporary file. If you change the name of the file to second file you are going to lose the second file forever. You can do it without a temp file but still the process is more time consuming. You have to rename and move the file to a different (say \tmp) directory and second file to the name of first file and copy the file from \tmp to your current directory.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am trying to learn basic commands in the terminal. I have a couple of quick questions. I know that to make a file and place it in a specific folder, one needs to create the directory and then use touch to create an empty file and place it there by mv:
mkdir folder/sub
touch file.txt
mv file.txt folder/sub
Could we somehow chain these things together and use touch to create a file and place it in a specific directory in just one line?
and then if I am in a sub-directory, in order to get back from there (say: folder/sub) to my home, either of these three commands would work (cd, cd -, cd ..) I am not sure I get the differences among the three. I get that cd .. takes you back one step up but the other two seem to work exactly the same.
and let's say I have already a text file in my home directory named file.txt. If I write this in shell it overrides that existing file:
cp folder/sub/file.txt ~/
How would I go about this if I wanted to keep both files?
You can pass a relative or absolute path in any folder to and command, including touch (although the folder must exist):
touch folder/sub.file.txt
cd - switches to the folder you were last in (like a "Back" button)
. means the current directory
.. means the parent directory
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have 1 file where data gets added every 10 min, I want to get updated data which can be stored in new file(inc1.txt) through script.
My path for file as /home/asda/Desktop/inc.txt
How this can be achive?
Use tac to cat the file backwards, and quit when you get to your marker:
tac /home/asda/Desktop/inc.txt | sed /Marker/q | tac
then add a new Marker at the end to remember where you last finished
echo "Marker" >> /home/asda/Desktop/inc.txt
This has the disadvantage that it alters your file, but you can grep out the markers when you use the file like this:
grep -v Marker /home/asda/Desktop/inc.txt
Of course, you should make the marker something that doesn't naturally occur in your file.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I learned that open files can not be removed/renamed in Windows but can be removed/renamed in Linux (by default). I think I understand the reasons of the Windows behaviour.
Now I wonder why Linux allows remame/remove of open files ? What was the design rationale behind this decision ? What are the use cases when one need it ?
the difference is that linux works on file handles rather than file names. as long as the file handle is valid you can read and write to it.
renaming a file in linux does not alter the file handle.
one very interesting use case is to delete temp files after opening them.
this makes it impossible for every other process to access this file, while the process that owns the file handle can still read and write.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
How to find the number of times particular file has been modified in given time range i.e in last 2 days in Unix client?
As seen in UNIX & Linux Stackexchange
Linux offers three timestamps for files: time of last access of
contents (atime), time of last modification of contents (mtime),
and time of last modification of the inode (metadata, ctime). So,
no, you cannot. The directory's mtime corresponds to the last file
creation or deletion that happened, though.
So you cannot know neither the creation time, neither the history of the modifications.
The linux kernel uses inode for files in filesystems these inodes do not log changes in the filesystem, you can however ask for the last change through mtime example find testfile -mtime 2 this will tell you if the file has changed in the last 48 hours.
You are looking the log changes to the file, you could use inotify for that. Or the inotifywait tool. Which let's you efficiently wait for changes in a file.
I suggest inotifywait.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a file from TREC(Text REtrieval Conference) whose extension is .0z .1z etc etc. I tried every method I can do, but still failed. Could someone do me a favour please?
There are some evidence that might helpful.
In terminal, I used "file" command then it shows "fr940104.1z: compress'd data 16 bits".
I also check the properties of the file under GUI, which shows UNIX-compressed file(application/x-compress).
and are stored in chunks of about 1 megabyte each
indicates that you need to recombine the chunks before decompressing. Hopefully the filenames can help you with that ("chunk001.z", "chunk002.z", ?). Assuming that you can figure out the order, use cat to combine them into one file. Then use Unix uncompress. Or pipe directly from cat to uncompress.
.z normally means simple Unix compression. Does
uncompress filename.z
not work?