Most Popular

1500 questions
576
votes
3 answers

What is a bind mount?

What is a “bind mount”? How do I make one? What is it good for? I've been told to use a bind mount for something, but I don't understand what it is or how to use it.
561
votes
4 answers

In a bash script, using the conditional "or" in an "if" statement

This question is a sequel of sorts to my earlier question. The users on this site kindly helped me determine how to write a bash for loop that iterates over string values. For example, suppose that a loop control variable fname iterates over the…
Andrew
  • 16,855
559
votes
4 answers

recursive mkdir

Is there a linux command that I'm overlooking that makes it possible to do something along the lines of: (pseudo) $ mkdir -R foo/bar/zoo/andsoforth Or is there no alternative but to make the directories one at a time?
Dr.Dredel
559
votes
8 answers

Difference between Login Shell and Non-Login Shell?

I understand the basic difference between an interactive shell and a non-interactive shell. But what exactly differentiates a login shell from a non-login shell? Can you give examples for uses of a non-login interactive shell?
Igorio
  • 7,519
  • 7
  • 20
  • 11
559
votes
14 answers

How to forward X over SSH to run graphics applications remotely?

I have a machine running Ubuntu which I SSH to from my Fedora 14 machine. I want to forward X from the Ubuntu machine back to Fedora so I can run graphical programs remotely. Both machines are on a LAN. I know that the -X option enables X11…
Mr. Shickadance
  • 7,104
  • 6
  • 27
  • 28
558
votes
7 answers

What is the difference between the Bash operators [[ vs [ vs ( vs ((?

I am a little bit confused on what do these operators do differently when used in bash (brackets, double brackets, parenthesis and double parenthesis). [[ , [ , ( , (( I have seen people use them on if statements like this: if [[ condition ]] if […
RetroCode
  • 5,729
  • 3
  • 10
  • 8
558
votes
10 answers

How to conditionally do something if a command succeeded or failed

How can I do something like this in bash? if "`command` returns any error"; then echo "Returned an error" else echo "Proceed..." fi
Shinmaru
557
votes
12 answers

How do I copy a folder keeping owners and permissions intact?

So I was going to back up my home folder by copying it to an external drive as follows: sudo cp -r /home/my_home /media/backup/my_home With the result that all folders on the external drives are now owned by root:root. How can I have cp keep the…
553
votes
7 answers

Can I zip an entire folder using gzip?

I'm trying to zip a folder in unix. Can that be done using the gzip command?
user1269502
  • 5,631
543
votes
8 answers

How can I pass a command line argument into a shell script?

I know that shell scripts just run commands as if they were executed in at the command prompt. I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or string into the script. How do I approach doing…
Paul
  • 9,423
540
votes
15 answers

How to turn off stdout buffering in a pipe?

I have a script which calls two commands: long_running_command | print_progress The long_running_command prints progress but I'm unhappy with it. I'm using print_progress to make it nicer (namely, I print the progress in a single line). The…
529
votes
6 answers

How to copy a file from a remote server to a local machine?

In my terminal shell, I ssh'ed into a remote server, and I cd to the directory I want. Now in this directory, there is a file called table that I want to copy to my local machine /home/me/Desktop. How can I do this? I tried scp table…
omega
  • 5,797
525
votes
9 answers

Execute vs Read bit. How do directory permissions in Linux work?

In my CMS, I noticed that directories need the executable bit (+x) set for the user to open them. Why is the execute permission required to read a directory, and how do directory permissions in Linux work?
Nick.h
  • 6,323
522
votes
14 answers

How do I loop through only directories in bash?

I have a folder with some directories and some files (some are hidden, beginning with dot). for d in *; do echo $d done will loop through all files and directories, but I want to loop only through directories. How do I do that?
rubo77
  • 28,966
509
votes
21 answers

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233