Linked Questions

107
votes
4answers
62k views

What is the difference between “&&” and “;” when chaining commands [duplicate]

What is the difference between the following methods of chaining commands? cmd1; cmd2 cmd1 && cmd2
142
votes
3answers
61k views

What's the difference between semicolon and double ampersand && [duplicate]

What is the difference between echo "Hello " ; echo "world" and echo "Hello " && echo "world" Both seems to run the two commands after each other.
20
votes
5answers
11k views

Is there a difference between `;` and `&&` and `|`? [duplicate]

When you want to run multiple commands you can use ;, && and | Like this: killall Finder; killall SystemUIServer, cd ~/Desktop/ && rm Caches Or: man grep | man cat for example. But, ...
32
votes
2answers
19k views

Difference between executing multiple commands with && and ; [duplicate]

What's the difference between executing multiple commands with && and ;? Examples: echo "Hi\!" && echo "How are you?" and echo "Hi\!"; echo "How are you?"
11
votes
2answers
6k views

How to redirect the output of a command to an already existing file without deleting its contents? [duplicate]

I am making a backup of some files and am creating a checksum file, checksums.txt, to later check the integrity of my data. However pasting each checksum manually into the file is inconvenient since ...
13
votes
3answers
24k views

What does “>” do vs “>>”? [duplicate]

I am currently doing preparation for my GCSE computing controlled assessment on Linux. I type ls > list and ls >> list into the command line, but it does not do anything. I have googled it ...
18
votes
2answers
12k views

What does the < (left chevron / triangle bracket) do? [duplicate]

I understand that the > (right chevron) is for redirecting the STDOUT of a program to a file, as in echo 'polo' > marco.txt will create a text file called marco.txt with polo as the contents ...
14
votes
2answers
17k views

What is &>> in a shell script [duplicate]

In a script I have inherited the output of one of our programs is put in to a file with: program &>> result.txt I have been reading in my book "Learning the bash shell" at home over the ...
9
votes
2answers
16k views

How do i run a command only after previous command is unsuccessful in bash? [duplicate]

We use && operator to run a command after previous one finishes. update-system-configuration && restart-service but how do I run a command only if previous command is unsuccessful ? ...
5
votes
3answers
10k views

What does || mean in bash? [duplicate]

Apologies if this is a duplicate post. I did try searching to see if someone already asked/answered this but didn't find anything. What does || mean in bash? For example, in researching steps to ...
4
votes
2answers
6k views

What is the difference between > and >> (especially as it relates to use with the cat program)? [duplicate]

Suppose that I have a file called temp.txt. Using the cat program, I would like to add the contents of this file to the end of myfile.txt -- creating myfile.txt if it does not exist and appending to ...
0
votes
1answer
37k views

How do I use: cat << EOF [duplicate]

I am little confused and not sure, how to add the cat << EOF style to my script. Would really appreciate a little feedback and help. Here is my script !/bin/sh #This is a disk mailer script ...
7
votes
1answer
3k views

Difference between parentheses and braces in terminal? [duplicate]

( du /etc; du /var; ) > tmp.txt { du /etc; du /var; } > tmp.txt Is there a difference between the () and {}? The output of tmp.txt seems exactly the same, and I was wondering whether i'm ...
4
votes
1answer
8k views

< and << in UNIX /Linux [duplicate]

What are the operators <<and < used for in Linux? For example cat << abc.txt
3
votes
2answers
2k views

Convert file contents to lowercase and store result in same file [duplicate]

I use the following command to convert my input file contents to lowercase tr A-Z a-z < input > output This command works fine. But when I try to store the output in input file itself, it is ...
1
vote
1answer
7k views

What is the different between ls > list and ls >> list? [duplicate]

I was wondering what the difference is between ls > list and ls >> list is and what the purpose of these commands is?
2
votes
1answer
3k views

what is the difference between >&2 and &>2 [duplicate]

Just wondering if there is any difference between: echo "running the npm patch" >&2; and echo "running the npm patch" &>2; I have actually never really understand that syntax.
1
vote
1answer
3k views

What is the behaviour of & operator [duplicate]

I am trying to chain the commands in linux, I am using ubuntu 14.04 distribution. The aim to create a directory and go into that directory. Generally we do this mkdir foldername cd foldername ...
1
vote
2answers
2k views

How does (echo 'text' ; cat file.txt ) > new file.txt actually work? [duplicate]

So, here's a simple code: (echo "Some text to prepend"; cat gero.txt) > file.txt And I can't really grasp the mechanics of this code. So basically gero.txt is an already existing file, we create ...
0
votes
2answers
4k views

How to redirect unzip -v output to a log file in shell script [duplicate]

I have a script that loops through all zip files in a large directory and individually unzips them. I am using the -q option in order to keep the console clean and display other monitoring info. I ...
2
votes
3answers
1k views

what is the use of '<<' redirection? [duplicate]

I am looking for an example of << redirection because i don't understand it well. I know < is for sending the contents of specified file to be use as standard input like : cat < file.txt ...
0
votes
1answer
2k views

How to make a bash script run all the time [duplicate]

Just curious how I can make a bash script run not only when I call it but all the time in the background. I have a bash script that is supposed to look for files and place them in the right folders, ...
3
votes
2answers
289 views

Linux redirection: << operator [duplicate]

Can anyone explain when and how to use << operator for input redirection? I've googled enough but couldn't find.
1
vote
2answers
1k views

How to run shell script in background while start On CentOS? [duplicate]

I have a shell script contain loop like this: while true do if ... ; then ... else ... break fi done I want this script to run backend while OS start. I have try to add this script ...
0
votes
1answer
2k views

What does this ls command do? [duplicate]

what does this command do if it was executed in my current working directory that has files in it? ls 2> result I think whatever ls writes will be redirected to the result file? Is that correct and ...
0
votes
1answer
489 views

Piping to file doesn't work with intermediate pipe [duplicate]

This is causing problems: node "$SUMAN_PROJECT_ROOT/server.js" | bunyan -o short &> ${LOG_FILE} & this works: node "$SUMAN_PROJECT_ROOT/server.js" &> ${LOG_FILE} & the ...
2
votes
2answers
908 views

How to redirect command output and error to two different files? [duplicate]

I want to redirect output of a tar command to one file say, out.log and errors during execution should be redirected to another file for example, error.log. How can I achieve this?
3
votes
2answers
110 views

Order of commands executed and redirection [duplicate]

For a bash script I'm making, I need to delete all but the newest 2 files in a directory. I decided to use ls -tUr > somefile.txt and then just tail the newest 2, move them somewhere else, rm *, ...
-3
votes
3answers
715 views

“Make sure not to read and write the same file in the same pipeline” [duplicate]

shellcheck reports: echo -e "blah/blah\n$(cat "$tmpdir"/"$filename".jpdf)" > "$tmpdir"/"$filename".jpdf ^-- SC2094: Make sure not to read and write the same file in the ...
2
votes
1answer
889 views

Unable to redirect stdout/stderr to log file [duplicate]

I have a script tmp.sh #!/bin/bash echo hello sleep 3 echo 3 I want to log the script running time (as well as script stdout) to a log file. user$ time ./tmp.sh >& log.tmp real 0m3....
2
votes
2answers
398 views

xargs and < and > to the same files [duplicate]

I want to run git stripspace on all my source code files, on each build (or precommit or just manually), to remove extraneous whitespace, and later maybe to format the code in a standard way, So ...
1
vote
1answer
1k views

How to redirect stdin and stdout and stderr at the same time in bash? [duplicate]

I want to redirect stdin and stdout and stderr at the same time in bash, is this how it's done: someProgram < stdinFile.txt > stdoutFile.txt 2> stderrFile.txt
2
votes
1answer
973 views

How redirecting debug output to a file [duplicate]

I use -x for debug info while executing the shell script. How can I redirect debug info only to a file? Example script: #!/bin/bash echo OK echo NO i will get the below result when i run in debug ...
0
votes
1answer
843 views

Ampersand in Cronjob [duplicate]

I have found the following entry in a user crontab: */5 * * * * ~/bin/php /path/to/phpscript &> /path/to/logfile What is the meaning of the & (ampersand) here? Has it still the meaning ...
2
votes
2answers
295 views

Insert result of command into an executable (one command) [duplicate]

Is it possible to insert the result of a command (or even a chain of commands) into an executable in one command? Something like this: ./a.out < echo 0 Or is it necessary to do this: echo 0 > ...
1
vote
1answer
207 views

Does ampersand also function as line terminator? [duplicate]

I know that in bash, the & symbol delegates a command to the background, but is it also supposed to double as a special line terminator? To give an example of what I'm referring to, I found this ...
0
votes
1answer
600 views

opening multiple tabs in firefox using a one-liner bash script [duplicate]

I am on CentOS 6.6. I have a program that runs analysis and outputs its data in html files. The file structure is dir1/dir1.html dir2/dir2.html dir3/dir3.html I want to open all three html files ...
0
votes
1answer
265 views

What does this bash operation do? [duplicate]

I recently came across this command in bash: cat > filename << EOF I do not understand the << EOF part. Googling the << operator, I only came across regular shift arithmetic ...
0
votes
1answer
415 views

Unix, create file based on command [duplicate]

I have a command, but I want to get the results into a .txt file I can open. How do I alter my command to allow the results to be put into a text file. I plan to transfer this .txt file to my local ...
0
votes
1answer
241 views

the T-split command in linux as opposed to cat? [duplicate]

so for a question I have to store both messages of x and y to log, since y only exists and x does not I used cat x y &> log to be able to store both messages. However as the second part my ...
1
vote
3answers
84 views

What is `>&` in simple terms? [duplicate]

What does $ command 1>&2 do? As I understand it this runs the command but with the STDOUT redirected to the STDERR. But I'm not sure exactly how >& works. I have seen it as $ command 1&...
0
votes
1answer
149 views

One liner to replace file contents [duplicate]

When I run base64 filename >> encodedfile the new content is appended to existing content. Is there any way I can replace entire old content with new content. Using any similar one line ...
1
vote
2answers
85 views

why <<\END is used in ed [duplicate]

Using ed put character # to the beginning of lines 10 to 20 in file /etc/passwd. Solution is the following ed /etc/passwd <<\END 10,20s/^/#/ %p Q END my question is that what does << ...
0
votes
2answers
94 views

What are the steps of this command using ; || and && [duplicate]

Note: A B C are commands..... Please tell me what the step process would be of these commands, so I can better understand the language.. A || B ; C = If A fails then run B then C? A ; B || C = Run A ...
1
vote
1answer
91 views

Difference between 2>&1 <command> and <command> 2>&1 [duplicate]

I have the following two invocations of a function in bash, which I'm piping to another function which captures the error output: >&2 log_stdout | log_err log_stdout >&2 | log_err Is ...
2
votes
1answer
142 views

Appending a variable to different lines of a file in bash [duplicate]

So say I've got a file with the following text in it. And the source file I'm reading is like this: #0 abc 2016-08-06 01:12:57 AM 9.1% 779.9M of 1G 156.3M of 1G #1 abc 2016-08-06 02:33:47 ...
1
vote
1answer
56 views

Multiple methods of inputting files [duplicate]

What is the difference between the following commands: $ input.txt > grep foo $ grep foo < input.txt $ cat input.txt | grep foo $ grep foo input.txt And not just grep. Other commands too.
0
votes
1answer
51 views

What does | symbol near end of a command do? [duplicate]

I came across someone using the command zcat [filename].gz | less to open a file. What does | generally do when it's using in this manner? I've tried googling the question but haven't found the answer ...
-4
votes
2answers
67 views

$ sh < foo > bar this statement is the question [duplicate]

What this is the following command doing? I'm new, and still learning. $ sh < foo > bar How to interpret it step by step so that I can get clear understanding more question like this.
-3
votes
3answers
60 views

What is the use of 2>? [duplicate]

What is the use of: 2> in an SSH command?

15 30 50 per page