Questions tagged [bash]

Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

bash is the Bourne Again SHell, the successor to the classic Unix Bourne shell (sh). It's the default shell on many Linux distributions, including RedHat, CentOS, Debian, and Ubuntu.

The premier online guide is the BashGuide.

3527 questions
147
votes
9 answers

Keeping a linux process running after I logout

I'm connecting to a Linux machine through SSH, and I'm trying to run a heavy bash script that makes filesystem operations. It's expected to keep running for hours, but I cannot leave the SSH session open because of internet connections issues I…
doc_id
  • 1,509
  • 2
  • 12
  • 17
141
votes
39 answers

What useful things can one add to one's .bashrc?

Is there anything that you can't live without and will make my life SO much easier? Here are some that I use ('diskspace' & 'folders' are particularly handy). # some more ls aliases alias ll='ls -alh' alias la='ls -A' alias l='ls -CFlh' alias…
Gareth
  • 8,573
  • 13
  • 44
  • 44
133
votes
5 answers

Clean way to write complex multi-line string to a variable

I need to write some complex xml to a variable inside a bash script. The xml needs to be readable inside the bash script as this is where the xml fragment will live, it's not being read from another file or source. So my question is this if I have a…
ChrisInCambo
  • 1,751
  • 3
  • 15
  • 13
128
votes
2 answers

Colors in bash after piping through less?

When I have dircolors defined life is full of... color. When I pipe ls through less to scroll around I lose the colors. Any suggestions?
MathewC
  • 6,957
  • 9
  • 39
  • 53
122
votes
8 answers

How to get pid of just started process

I want to start process (eg. myCommand) and get its pid (to allow to kill it later). I tried ps and filter by name, but I can not distinguish process by names myCommand ps ux | awk '// {print $2}' Because processes names are not…
rafalmag
  • 1,331
  • 2
  • 9
  • 9
114
votes
8 answers

How to run command as user who has /usr/sbin/nologin as Shell?

All I need to do is to run a specific script as a particular user who does have the nologin/false shell indicated in /etc/passwd. I would run the script as root and this should run as another user. Running: ~# su -c "/bin/touch /tmp/test"…
Tommaso
  • 1,161
  • 2
  • 8
  • 4
112
votes
85 answers

Linux command line best practices and tips?

I would like to open a discussion that would accumulate your Linux command line (CLI) best practices and tips. I've searched for such a discussion to share the below comment but haven't found one, hence this post. I hope we all could learn from…
Maxim Veksler
  • 2,725
  • 10
  • 28
  • 32
102
votes
8 answers

Can you have more than one ~/.ssh/config file?

We have a bastion server that we use to connect to multiple hosts, and our .ssh/config has grown to over a thousand lines (we have hundreds of hosts that we connect to). This is beginning to get a little unwieldy and I'd like to know if there is a…
wrangler
  • 3,080
  • 5
  • 24
  • 20
102
votes
8 answers

How to make bash scripts print out every command before it executes?

For example, I have a simple bash file #!/bin/bash cd ~/hello ls How can I make it display every command before executing it? Just the opposite effect of "@echo off" in windows batch scripting.
Epeius
  • 1,031
  • 2
  • 9
  • 6
100
votes
9 answers

mysqldump to a tar.gz

Usually after dumping a MySQL database with mysqldump command I immediately tar/gzip the resultant file. I'm looking for a way to do this in one command: So from this: mysqldump dbname -u root -p > dbname.sql tar czvf dbname.sql.tgz dbname.sql rm…
pygorex1
  • 1,181
  • 2
  • 9
  • 10
98
votes
7 answers

SSH from A through B to C, using private key on B

I'm looking for a simple way to SSH from my local machine, A, through a proxy, B, to a destination host, C. The private key that goes with the public key on C is on B, and I can't put that key on my local machine. Any tips? Also, I'd like to be…
wrangler
  • 3,080
  • 5
  • 24
  • 20
95
votes
8 answers

How can I edit the welcome message when ssh start?

I have a VPS for my website hosting. It is running a Ubuntu server. Every time I logged in my server by ssh, it displays a lengthy welcome message in my terminal. Linux node61.buyvm.net 2.6.18-pony6-3 #1 SMP Tue Mar 13 07:31:44 PDT 2012…
Yansuck
95
votes
9 answers

How can I fully log all bash scripts actions?

From my script output I want to capture ALL the logs data with error messages and redirect them all to log file. I have script like below: #!/bin/bash ( echo " `date` : part 1 - start " ssh -f admin@server.com 'bash…
BlueMark
  • 1,089
  • 1
  • 9
  • 8
89
votes
6 answers

Standard place for user defined bash_completion.d scripts?

I have user access (no root) into a Linux (Suse) machine where I developed some bash scripts and the corresponding bash autocompletion rules. Since the scripts belong only to my user and therefore I need the complete rules only "active" for me (a…
Carles Sala
  • 993
  • 1
  • 7
  • 6
86
votes
4 answers

How can I find the path to an executable in OSX

Is there a command I can use to easily find the path to an executable? I'm looking for identify on my local machine - something like pwd? pwd identify => /usr/local/bin/identify
Codebeef
  • 1,449
  • 4
  • 19
  • 20