120 Answered Questions for the topic Linux

Linux Unix Grep


How can I exclude directories from grep -R?

I want to traverse all subdirectories, except the "node_modules" directory.
Linux Unix String Bash


Replacing some characters in a string with another character?

I have a string like <!-- language: lang-none --> AxxBCyyyDEFzzLMN I want to replace all `x` and `y` and `z` with `_` so that the output is A_BC_DEF_LMN How to do that? I know a... more


What does the number in parentheses shown after Unix command names in manpages mean?

For example: man(1), find(3), updatedb(2)? What do the numbers in parentheses (Brit. "brackets") mean?


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?


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?


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... more
Linux Unix Bash


How do I write stderr to a file while using "tee" with a pipe?

I know how to use `tee` to write the output (`STDOUT`) of `aaa.sh` to `bbb.out`, while still displaying it in the terminal: ./aaa.sh | tee bbb.out How would I now also write `STDERR` to a file... more
Linux Bash Posix


How to kill all processes with a given partial name?

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

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,... more


How do I know the script file name in a Bash script?

How can I determine the name of the Bash script file inside the script itself? Like if my script is in file `runme.sh`, then how would I make it to display "You are running runme.sh" message... more
Linux Unix Bash Shell


Aborting a shell script if any command returns a non-zero value?

I have a Bash shell script that invokes a number of commands. I would like to have the shell script automatically exit with a return value of 1 if any of the commands return a non-zero value. Is... more
Linux Bash Grep Shell


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... more


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

Is there a program to control other computers from another computer?

Is there a good **remote desktop software tool** that I can use to control my Windows and Linux PCs from my Mac, and vice-versa? I don't care if it uses up lots of internet bandwidth. Desired... more


How to get the current date and time in the terminal and set a custom command in terminal for it?

I have to check the time in linux terminal.<br/> What is the command for getting date and time in Linux terminal ?<br/> Is there any way in which we can set custom function ?
Linux Unix Macos Mkdir


Is there a way to make mv create the directory to be moved to if it doesn't exist?

So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would... more


What is ":-!!" in C code?

I bumped into this strange macro code in [/usr/include/linux/kernel.h][1]: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the... more


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; ... more
Linux Bash Recursion


Recursively look for files with a specific extension?

I'm trying to find all files with a specific extension in a directory and its subdirectories with my bash (Latest Ubuntu LTS Release). This is what's written in a script file: #!/bin/bash ... more


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... more
Linux Symlink


How to symlink a file in Linux?

I want to make a symbolic link in Linux. I have written this bash command where the first path is the folder I want link into and the second path is the compiled source. ln -s... more
Linux Unix Path File


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 ... more
Linux Unix Cron Crontab


Restarting cron after changing crontab file?

Do I have to restart cron after changing the crontable file?
Linux Unix Grep Centos


How to grep a string in a directory and all its subdirectories' files in LINUX?

How to grep a string or a text in a directory and all its subdirectories'files in LINUX ??

Where can I set environment variables that crontab will use?

I have a crontab running every hour. The user running it has environment variabless in the `.bash_profile` that work when the user runs the job from the terminal, however, obviously these don't get... more

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.