120 Answered Questions for the topic Linux

Linux Unix Grep

05/14/19

How can I exclude directories from grep -R?

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

05/13/19

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

05/11/19

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?

05/09/19

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?

05/06/19

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?

05/06/19

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

05/05/19

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

05/04/19

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

05/04/19

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

05/04/19

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

05/02/19

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

05/01/19

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

04/28/19

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

04/27/19

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

04/26/19

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

04/26/19

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

04/25/19

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

04/25/19

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

04/22/19

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

04/20/19

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

04/20/19

Restarting cron after changing crontab file?

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

04/20/19

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.

OR

Find an Online Tutor Now

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