How do you grep and only return the matching line? i.e. The path/filename is omitted from the results. In this case I want to look in all .bar files in the current directory, searching for the term FOO Answer No need to find. If you are just looking for a pattern within a specific directory, this should suffi…
Tag: unix
How to copy directories into a directory using install in bash?
Assume the nested directories foo/bar and a empty directory dest. I would like to call something like install foo dest such that dest contains the directory foo/bar. I have tried the following: install foo dest => install: omitting directory “foo” install -d foo dest => nothing happens Answe…
What is the difference between the C programming language and C programming under linux?
What is the difference between the C programming language and C programming under Linux? Are the syntax same in both them? Or is the difference only when you execute the program? Answer The C language is governed by the ISO approved C standard and it does not take in to account the underlying platform on whic…
calculate total used disk space by files older than 180 days using find
I am trying to find the total disk space used by files older than 180 days in a particular directory. This is what I’m using: but the above is quiet evidently giving me disk space used by every file that is found. I want only the total added disk space used by the files. Can this be done using find
How do I replace single quotes with another character in sed?
I have a flat file where I have multiple occurrences of strings that contains single quote, e.g. hari’s and leader’s. I want to replace all occurrences of the single quote with space, i.e. all occurences of hari’s to hari s all occurences of leader’s to leader s I tried and but they ar…
Create a hard link from a file handle on Unix?
If I’ve got a handle to an open file, is it possible to create a hard link to that file after all references to it have been removed from the filesystem? For example, something like this: Specifically, I’d like to do this so that I can safely write to large data files, then move them into place at…
Clearing output of a terminal program in Linux C
I want to clear the output of a C program produced with printf statements. I want to clear only one line, for example: [source] [terminal] [I hope] I will “DDDDDDDDDDDDDD” line in write other string. I just want the above A, B, C sentences to left. Only clear D sentences to change the other senten…
How does cmd > /dev/null 2>&1 work?
I’m reading up on redirecting data to /dev/null and so I tried a simple test: If I try this: However, if I do this: That last solution is the desired solution, but what is happening with this 2>&1? My research so far suggest that 2 represents stderr and 1 represents stdout. So if I read it that w…
Use sed with ignore case while adding text before some pattern
In this case,how to ignore case while searching for pattern =first Answer You can use the following: Otherwise, you have the /I and n/i flags: From man sed: I i The I modifier to regular-expression matching is a GNU extension which makes sed match regexp in a case-insensitive manner. Test
Terminal edit command in a editor [closed]
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 am coming from the postgres world, and am not very new to UNIX. My question is, if there is a way…