Skip to main content

Questions tagged [linux]

NOTICE: All Linux questions must be related to programming; those that aren't will be closed. Use this tag only if your question relates to programming using Linux APIs or Linux-specific behavior, not just because you happen to run your code on Linux. If you need Linux support, you can try https://unix.stackexchange.com or the specific Linux distribution's Stack Exchange site like https://askubuntu.com or https://elementaryos.stackexchange.com/

Filter by
Sorted by
Tagged with
7535 votes
56 answers
11.2m views

Find all files containing a specific text (string) on Linux?

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 '...
Nathan's user avatar
  • 76.8k
3029 votes
19 answers
4.6m views

How can I recursively find all files in current and subfolders based on wildcard matching?

How can I recursively find all files in current and subfolders based on wildcard matching?
john's user avatar
  • 34.8k
2780 votes
33 answers
2.0m views

How to change the output color of echo in Linux

I am trying to print a text in the terminal using echo command. I want to print the text in a red color. How can I do that?
satheesh.droid's user avatar
2424 votes
7 answers
1.7m views

How do I delete an exported environment variable?

Before installing gnuplot, I set the environment variable GNUPLOT_DRIVER_DIR = /home/gnuplot/build/src. During the installation, something went wrong. I want to remove the GNUPLOT_DRIVER_DIR ...
A. K.'s user avatar
  • 36.8k
2233 votes
18 answers
2.3m views

How can I symlink a file in Linux? [closed]

I want to create a symbolic link in Linux. I have written this Bash command where the first path is the folder I want to link, and the second path is the compiled source. ln -s '+basebuild+'/IpDome-...
chrisg's user avatar
  • 41.2k
2216 votes
49 answers
1.8m views

How do I exclude a directory when using `find`?

How do I exclude a specific directory when searching for *.js files using find? find . -name '*.js'
helion3's user avatar
  • 36.6k
2191 votes
27 answers
2.3m views

How do I recursively grep all directories and subdirectories?

How do I recursively grep all directories and subdirectories? find . | xargs grep "texthere" *
wpiri's user avatar
  • 22.1k
2177 votes
19 answers
5.2m views

How do I change permissions for a folder and its subfolders/files? [closed]

How do I change the permissions of a folder and all its subfolders and files? This only applies to the /opt/lampp/htdocs folder, not its contents: chmod 775 /opt/lampp/htdocs How do I set chmod 755 ...
Adam Halasz's user avatar
  • 58.1k
2153 votes
20 answers
723k views

How do I profile C++ code running on Linux?

How do I find areas of my code that run slowly in a C++ application running on Linux?
Gabriel Isenberg's user avatar
2125 votes
16 answers
2.8m views

Looping through the content of a file in Bash

How do I iterate through each line of a text file with Bash? With this script: echo "Start!" for p in (peptides.txt) do echo "${p}" done I get this output on the screen: Start! ./runPep.sh: ...
Peter Mortensen's user avatar
1887 votes
39 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?
Myrddin Emrys's user avatar
1809 votes
5 answers
203k views

What is ':-!!' in C?

I bumped into this strange macro code in /usr/include/linux/kernel.h: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression ...
chmurli's user avatar
  • 15.1k
1614 votes
12 answers
1.1m 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 ...
SCdF's user avatar
  • 58.6k
1568 votes
23 answers
1.2m views

Merge / convert multiple PDF files into one PDF [closed]

How could I merge / convert multiple PDF files into one large PDF file? I tried the following, but the content of the target file was not as expected: convert file1.pdf file2.pdf merged.pdf I need ...
alcohol's user avatar
  • 23.5k
1494 votes
3 answers
1.1m 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-...
cwd's user avatar
  • 54.2k
1481 votes
35 answers
2.9m views

How to kill a process running on particular port in Linux?

I tried to close the tomcat using ./shutdown.sh from tomcat /bin directory. But found that the server was not closed properly. And thus I was unable to restartMy tomcat is running on port 8080. I ...
veer7's user avatar
  • 21.1k
1464 votes
3 answers
2.9m 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).
user2080656's user avatar
  • 14.7k
1411 votes
28 answers
1.8m views

How to count lines in a document? [closed]

I have lines like these, and I want to know how many lines I actually have... 09:16:39 AM all 2.00 0.00 4.00 0.00 0.00 0.00 0.00 0.00 94.00 09:16:40 AM all 5.00 0.00 ...
Alucard's user avatar
  • 16.9k
1362 votes
28 answers
3.7m views

How can I close some specific port on Linux? [closed]

How can I remove the port that some application/process has used it but didn't close the port? For example: when I run ssh on my ubuntu and tunnel the ssh connection on some port <PORT> on my ...
KavinduWije's user avatar
  • 41.9k
1360 votes
24 answers
1.1m views

Which version of PostgreSQL am I running?

I'm in a corporate environment (running Debian Linux) and didn't install it myself. I access the databases using Navicat or phpPgAdmin (if that helps). I also don't have shell access to the server ...
Highly Irregular's user avatar
1305 votes
31 answers
824k views

Pipe to/from the clipboard in a Bash script

Is it possible to pipe to/from the clipboard in Bash? Whether it is piping to/from a device handle or using an auxiliary application, I can't find anything. For example, if /dev/clip was a device ...
moinudin's user avatar
  • 137k
1239 votes
15 answers
510k views

Defining a variable with or without export

What is export for? What is the difference between: export name=value and name=value
flybywire's user avatar
  • 269k
1206 votes
29 answers
1.3m views

Using ls to list directories and their total sizes [closed]

Is it possible to use ls in Unix to list the total size of a sub-directory and all its contents as opposed to the usual 4K that (I assume) is just the directory file itself? total 12K drwxrwxr-x 6 **...
kmorris511's user avatar
1196 votes
10 answers
1.0m 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: ...
Matthew Scouten's user avatar
1139 votes
14 answers
764k views

How can I exclude directories from grep -R?

I want to traverse all subdirectories, except the node_modules directory.
TIMEX's user avatar
  • 268k
1139 votes
12 answers
717k 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 # ...
AndreaNobili's user avatar
  • 42.3k
1131 votes
15 answers
346k views

How do I use sudo to redirect output to a location I don't have permission to write to? [closed]

I've been given sudo access on one of our development RedHat linux boxes, and I seem to find myself quite often needing to redirect output to a location I don't normally have write access to. The ...
Jonathan's user avatar
  • 26.4k
1120 votes
31 answers
1.3m 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 ...
deepwell's user avatar
  • 20.7k
1109 votes
5 answers
135k 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 $...
ahmedaly50's user avatar
  • 7,825
1108 votes
26 answers
945k views

Recursively counting files in a Linux directory

How can I recursively count files in a Linux directory? I found this: find DIR_NAME -type f ¦ wc -l But when I run this it returns the following error. find: paths must precede expression: ¦
Robert Buckley's user avatar
1101 votes
33 answers
1.3m 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 ...
user2668128's user avatar
  • 41.3k
1094 votes
24 answers
2.1m views

How to permanently set $PATH on Linux/Unix [closed]

On Linux, how can I add a directory to the $PATH so it remains persistent across different sessions? Background I'm trying to add a directory to my path so it will always be in my Linux path. I've ...
Ali's user avatar
  • 266k
1093 votes
14 answers
1.3m views

Where can I find php.ini?

Today I needed to install the IBM DB2 library. I went through all the steps up to make install, and I found ibm_db2.so in $PHP_HOME/lib/extensions/somecomplicatedname/ibm_db2.so. The great catch is ...
necromancer's user avatar
  • 24.4k
1056 votes
36 answers
1.7m 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/...
Jean's user avatar
  • 22.3k
1035 votes
13 answers
1.7m 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 ----...
hasen's user avatar
  • 165k
1021 votes
2 answers
1.7m views

How can I get the current date and time in the terminal and set a custom command in the terminal for it? [closed]

I have to check the time in a Linux terminal. What is the command for getting date and time in a Linux terminal? Is there a way in which we can set a custom function?
harshal's user avatar
  • 10.6k
1002 votes
10 answers
691k views

Given two directory trees, how can I find out which files differ by content? [closed]

If I want find the differences between two directory trees, I usually just execute: diff -r dir1/ dir2/ This outputs exactly what the differences are between corresponding files. I'm interested in ...
Mansoor Siddiqui's user avatar
956 votes
19 answers
1.4m 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 ...
trh178's user avatar
  • 11.5k
924 votes
9 answers
1.4m 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 ...
Rayne's user avatar
  • 14.6k
911 votes
32 answers
1.5m views

How can I measure the actual memory usage of an application or process?

How do you measure the memory usage of an application or process in Linux? From the blog article of Understanding memory usage on Linux, ps is not an accurate tool to use for this intent. Why ps is &...
ksuralta's user avatar
  • 16.8k
905 votes
7 answers
846k views

Get current time in seconds since the Epoch on Linux, Bash

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?
n-alexander's user avatar
  • 15.1k
895 votes
19 answers
1.6m 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.
Thiyagarajan Varadharaj's user avatar
883 votes
31 answers
923k views

Argument list too long error for rm, cp, mv commands

I have several hundred PDFs under a directory in UNIX. The names of the PDFs are really long (approx. 60 chars). When I try to delete all PDFs together using the following command: rm -f *.pdf I ...
Vicky's user avatar
  • 17.2k
881 votes
13 answers
441k 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 ...
Matthieu Napoli's user avatar
871 votes
2 answers
381k views

How do SO_REUSEADDR and SO_REUSEPORT differ?

The man pages and programmer documentations for the socket options SO_REUSEADDR and SO_REUSEPORT are different for different operating systems and often highly confusing. Some operating systems don't ...
Mecki's user avatar
  • 131k
868 votes
70 answers
2.7m views

Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?

I have applied every solution available on internet but still I cannot run Docker. I want to use Scrapy Splash on my server. Here is history of commands I ran. docker run -p 8050:8050 scrapinghub/...
Umair Ayub's user avatar
  • 20.6k
866 votes
19 answers
1.9m 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++?
Prasanth Madhavan's user avatar
866 votes
25 answers
733k views

How can I copy the output of a command directly into my clipboard?

How can I pipe the output of a command into my clipboard and paste it back when using a terminal? For instance: cat file | clipboard
Legend's user avatar
  • 116k
863 votes
14 answers
736k views

How to kill all processes with a given partial name? [closed]

I want to kill all processes that I get by: ps aux | grep my_pattern How to do it? This does not work: pkill my_pattern
Łukasz Lew's user avatar
  • 49.7k
863 votes
11 answers
2.1m views

Kill detached screen session [closed]

I learned from somewhere a detached screen can be killed by screen -X -S [session # you want to kill] kill where [session # you want to kill] can be gotten from screen -ls But this doesn't work. ...
Tim's user avatar
  • 97.8k

1
2 3 4 5
4558