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
7491 votes
57 answers
11.0m 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.1k
3002 votes
19 answers
4.5m 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.5k
2758 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
2382 votes
7 answers
1.6m 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.2k
2212 votes
18 answers
2.2m 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
  • 40.8k
2188 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.2k
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
2177 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
  • 21.9k
2155 votes
67 answers
2.3m views

How can I update Node.js and NPM to their latest versions?

I just installed Node.js and NPM (Node Package Manager). I installed NPM for access to additional Node.js modules. After I installed Node.js and NPM, I noticed that neither were the latest versions ...
Dail's user avatar
  • 21.8k
2149 votes
20 answers
715k 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
2103 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
1877 votes
39 answers
1.3m 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
1602 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.4k
1543 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.2k
1477 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
  • 53.9k
1460 votes
35 answers
2.8m 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
  • 20.9k
1459 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
1400 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.8k
1350 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
1301 votes
31 answers
813k 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
  • 136k
1234 votes
15 answers
502k 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
  • 267k
1199 votes
29 answers
1.2m 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
  • 16.8k
1195 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
1130 votes
15 answers
747k views

How can I exclude directories from grep -R?

I want to traverse all subdirectories, except the node_modules directory.
TIMEX's user avatar
  • 266k
1128 votes
11 answers
698k 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
1123 votes
15 answers
341k 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.3k
1112 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,845
1109 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.6k
1101 votes
25 answers
931k 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
1091 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
  • 40.7k
1090 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
  • 265k
1085 votes
14 answers
1.2m 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.2k
1047 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.2k
1025 votes
13 answers
1.6m 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
  • 164k
1008 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.4k
994 votes
10 answers
675k 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
951 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.4k
916 votes
9 answers
1.3m 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.5k
905 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.7k
901 votes
7 answers
830k 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
884 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
878 votes
31 answers
902k 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.1k
878 votes
13 answers
437k 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
864 votes
11 answers
2.0m 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.1k
863 votes
2 answers
374k 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
  • 130k
860 votes
19 answers
1.8m 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
855 votes
14 answers
721k 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.4k
851 votes
25 answers
704k 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
  • 115k
843 votes
68 answers
2.6m 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.3k

1
2 3 4 5
4553