Skip to content
Advertisement

Tag: file

Close file in C

Under Linux I use this code to redirect stdout and stderr on a file, as shown in the code the file is opened using fopen(f) and is it closed using close(fd). My question is whether the close(fd) statement closes all file descriptors, or is it necessary to use fclose(f) as well ? Answer The rule is to close the outermost

Quickly create an uncompressible large file on a Linux system

On a Linux system, I need to create a large file (about 10GB), uncompressible file. This file is supposed to reside in a Docker image, needed to test performance in transferring and storing large docker images on a local registry. Therefore, I need the image to be “intrinsically” large (that is: uncompressible), in order to bypass optimization mechanisms. fallocate (described

My file doesn’t return the magic file message

I have to create a magic file that can detect a result of 42 on the 42nd byte. I’ve created the following line to then compile but when I run file -m <file_name> with this content I get the message Answer Your magic should be like this: Here’s my test:

Copy a file from one directory to another in C++

I am writing a C++ program to copy one file from one directory to another. I don’t want to use C++ 17 features. I have already implemented this in the following code. I am on Linux and I want to use the OS cp command to do this. I have written this code. The error is: cp: source: No such

How do I get the filename of an open std::fs::File in Rust?

I have an open std::fs::File, and I want to get it’s filename, e.g. as a PathBuf. How do I do that? The simple solution would be to just save the path used in the call to File::open. Unfortunately, this does not work for me. I am trying to write a program that reads log files, and the program that writes

Linux Command Line – list all directories containing .js files, and copy the directories and their contents to a new folder

Here is the code I already have that finds and lists all directories containing .js files (excluding the node_modules directory). As you can see, listing those directories is no problem. However, rather than list the directories, I would like to copy them (and their contents) to a new folder, preferably all in one line without running any kind of script.

Advertisement