I’m writing a cross-platform application, and I need the total available disk space. For posix systems (Linux and Macos) I’m using statvfs. I created this C++ method: Unfortunately I’m getting quite strange values I can’t understand. For instance: f_blocks = 73242188 f_bsize = 1048576 f_bfree = 50393643 … Are those values in bits, bytes or anything else? I read here
Tag: unix
Delete the first five characters on any line of a text file in Linux with sed
I need a one-liner to remove the first five characters on any line of a text file. How can I do that with sed? Answer means replace (“s”, substitute) beginning-of-line then 5 characters (“.”) with nothing. There are more compact or flexible ways to write this using sed or cut.
Regarding the Single and the Double Dot within Directories
Whenever we use the command: and We see 2 kinds of dots: Appear in the directories. Now in APUE by Stephens Rago, it says these are filenames and some books say these are directories. What are these Dots about anyway? Please provide an answer w.r.t. Windows as well as Unix if possible. Answer It’s the same for both platforms (and
How can I recall the argument of the previous bash command?
Is there a way in Bash to recall the argument of the previous command? I usually do vi file.c followed by gcc file.c. Is there a way in Bash to recall the argument of the previous command? Answer You can use $_ or !$ to recall the last argument of the previous command. Also Alt + . can be used
BASH: how to perform arithmetic on numbers in a pipe
I am getting a stream of numbers in a pipe, and would like to perform some operations before passing them on to the next section, but I’m a little lost about how I would go about it without breaking the pipe. for example Would you have any ideas on how to make something like this work? The actual operation I
How can I convert a file pointer ( FILE* fp ) to a file descriptor (int fd)?
I have a FILE *, returned by a call to fopen(). I need to get a file descriptor from it, to make calls like fsync(fd) on it. What’s the function to get a file descriptor from a file pointer? Answer The proper function is int fileno(FILE *stream). It can be found in <stdio.h>, and is a POSIX standard but not
Parsing line with delimiter in Python
I have lines of data which I want to parse. The data looks like this: What I want to do is to have a subroutine that parse them and return 2 values (score and expect) for each line. However this function of mine doesn’t seem to work: Please advice what’s the right way to do it? Answer It looks like
how to find whether a script run as a nohup finished or not?
I tried running a script using nohup like, When I tried I couldn’t find it there except for the grep which is being run with that string as a parameter. Am I doing it right?. Does this mean that the process has indeed finished execution? Thanks. Answer At the beginning of your shell script, write the PID to a file
The conventional location for storing my Java libraries and applications in UNIX based systems
I usually store the Java applications and JAR files that I download from the Web in the ~/Java folder on my computer (an OS X machine). I have been doing this since the days when I was a Windows user. However I think in UNIX based systems user local apps are conventionally stored in another directory. I have a feeling
Get directory path by fd
I’ve run into the need to be able refer to a directory by path given its file descriptor in Linux. The path doesn’t have to be canonical, it just has to be functional so that I can pass it to other functions. So, taking the same parameters as passed to a function like fstatat(), I need to be able to