227,599 questions
7706
votes
57
answers
12.1m
views
Find all files containing a specific text (string) on Linux [closed]
How do I find all files containing a specific string of text within their file contents?
The following doesn't work. It seems to display every single file in the system.
find / -type f -exec grep -H '...
2846
votes
34
answers
2.1m
views
How to change the output color of echo in Linux
I am trying to print a text in a red color in the terminal using echo command.
How can I do that?
2322
votes
51
answers
2.0m
views
How do I exclude a directory when using `find`? [closed]
How do I exclude a specific directory when searching for *.js files using find?
find . -name '*.js'
2249
votes
27
answers
2.5m
views
How do I recursively grep all directories and subdirectories?
How do I recursively grep all directories and subdirectories?
find . | xargs grep "texthere" *
2182
votes
20
answers
756k
views
How do I profile C++ code running on Linux? [closed]
How do I find areas of my code that run slowly in a C++ application running on Linux?
1920
votes
40
answers
1.4m
views
How do I prompt for Yes/No/Cancel input in a Linux shell script?
I want to pause input in a shell script, and prompt the user for choices.
The standard Yes, No, or Cancel type question.
How do I accomplish this in a typical bash prompt?
1677
votes
12
answers
1.2m
views
How to redirect output to a file and stdout
In bash, calling foo would display any output from that command on the stdout.
Calling foo > output would redirect any output from that command to the file specified (in this case 'output').
Is ...
1537
votes
3
answers
1.2m
views
How can I use grep to show just filenames on Linux? [closed]
How can I use grep to show just file-names (no in-line matches) on Linux?
I am usually using something like:
find . -iname "*php" -exec grep -H myString {} \;
How can I just get the file-...
1522
votes
3
answers
3.1m
views
How do I create a copy of a directory in Unix/Linux? [closed]
I want to recursively create a copy of a directory and all its contents (e.g. files and subdirectories).
1457
votes
28
answers
1.9m
views
Count number of lines in a non binary file (Like a CSV or a TXT) file in terminal [closed]
I have a text file, and I like to know the total number of line withou opening it. My document is like these, and I want to know how many lines actually...
09:16:39 AM all 2.00 0.00 4.00 ...
1273
votes
16
answers
548k
views
Defining a variable with or without export
What is export for?
What is the difference between:
export name=value
and
name=value
1212
votes
10
answers
1.1m
views
Remove a symlink to a directory [closed]
I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it.
I tried rm and get back rm: cannot remove 'foo'.
I tried rmdir and got back rmdir: ...
1190
votes
12
answers
802k
views
What does 'set -e' mean in a Bash script?
I'm studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file.
The script has the following code:
#!/bin/bash
set -e
# ...
1146
votes
31
answers
1.4m
views
Shell command to tar directory excluding certain files/folders [closed]
Is there a simple shell command/script that supports excluding certain files/folders from being archived?
I have a directory that need to be archived with a sub directory that has a number of very ...
1140
votes
34
answers
1.5m
views
Exploring Docker container's file system
I've noticed with docker that I need to understand what's happening inside a container or what files exist in there. One example is downloading images from the docker index - you don't have a clue ...
1112
votes
5
answers
138k
views
Why does the C preprocessor interpret the word "linux" as the constant "1"?
Why does the C preprocessor in GCC interpret the word linux (small letters) as the constant 1?
test.c:
#include <stdio.h>
int main(void)
{
int linux = 5;
return 0;
}
Result of $ ...
1102
votes
36
answers
1.9m
views
How to get full path of a file?
Is there an easy way I can print the full path of file.txt ?
file.txt = /nfs/an/disks/jj/home/dir/file.txt
The <command>
dir> <command> file.txt
should print
/nfs/an/disks/jj/home/...
1080
votes
13
answers
1.8m
views
How does "cat << EOF" work in bash?
I needed to write a script to enter multi-line input to a program (psql).
After a bit of googling, I found the following syntax works:
cat << EOF | psql ---params
BEGIN;
`pg_dump ----...
981
votes
19
answers
1.5m
views
open() in Python does not create a file if it doesn't exist
What is the best way to open a file as read/write if it exists, or if it does not, then create it and open it as read/write? From what I read, file = open('myfile.dat', 'rw') should do this, right?
It ...
955
votes
9
answers
1.5m
views
Redirect all output to file in Bash [duplicate]
I know that in Linux, to redirect output from the screen to a file, I can either use the > or tee. However, I'm not sure why part of the output is still output to the screen and not written to the ...
934
votes
7
answers
899k
views
How to get the current time in seconds since the epoch, in Bash on Linux?
I need something simple like date, but in seconds since 1970 instead of the current date, hours, minutes, and seconds.
date doesn't seem to offer that option. Is there an easy way?
924
votes
19
answers
1.8m
views
How to force cp to overwrite without confirmation
I'm trying to use the cp command and force an overwrite.
I have tried cp -rf /foo/* /bar, but I am still prompted to confirm each overwrite.
906
votes
15
answers
476k
views
ImageMagick security policy 'PDF' blocking conversion
The Imagemagick security policy seems to be not allowing me perform this conversion from pdf to png. Converting other extensions seem to be working, just not from pdf. I haven't changed any of the ...
896
votes
18
answers
2.0m
views
Sleep for milliseconds
I know the POSIX sleep(x) function makes the program sleep for x seconds. Is there a function to make the program sleep for x milliseconds in C++?
890
votes
13
answers
454k
views
How to 'grep' a continuous stream?
Is that possible to use grep on a continuous stream?
What I mean is sort of a tail -f <file> command, but with grep on the output in order to keep only the lines that interest me.
I've tried ...