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
52
votes
6 answers

Bash Loop - How to stop the loop when I press Control-C inside a command?

I am rsyncing a few directories. I have a bash terminal open and am executing something like this: for DIR in * ; do rsync -a $DIR example.com:somewhere/ ; done However if I want to stop the whole things, I press Control-C. That stops the rsync,…
Amandasaurus
  • 31,471
  • 65
  • 192
  • 253
51
votes
5 answers

Piping wget output to /dev/null in cron

I am running the following command every 5 minutes in my crontab to keep Phusion Passenger alive. */5 * * * * wget mysite.com > /dev/null 2>&1 When I run this it performs a wget on the site url routes STDOUT/STDERR to /dev/null. When I run this…
nulltek
  • 1,251
  • 3
  • 14
  • 22
51
votes
3 answers

Find out which partition a directory is located on in Linux?

Is there a way to find out which partition a directory is located in? I know I can use df to list partitions and mount points but I need to be able to find out which partition any directory is located in with a simple command.
Camsoft
  • 961
  • 4
  • 12
  • 21
50
votes
7 answers

How to get all fingerprints for .ssh/authorized_keys(2) file

Is there a simple way to get a list of all fingerprints entered in the .ssh/authorized_keys || .ssh/authorized_keys2 file? ssh-keygen -l -f .ssh/authorized_keys will only return fingerprint of first line / entry / publickey hack with awk: awk…
childno͡.de
  • 642
  • 1
  • 5
  • 14
48
votes
8 answers

Remove path from find command output

I have a bash script for deploying code from a beta environment to a production environment but currently I have to add the list of files to a txt file manaully and sometime I miss some. Basically my deployment script cat/loops copying the files…
Mikey1980
  • 751
  • 1
  • 8
  • 12
46
votes
8 answers

create 'virtual file' from bash command output?

I wonder if there is a way to create a 'virtual file' from a bash output. Example: Let's say I want to email the output of mysqldump as an attachment to an external email address. I can use Mutt to do so. The mutt option I need to use is -a
ppbitb
  • 562
  • 1
  • 4
  • 7
45
votes
4 answers

Run command in bash without save in history

How to run command in bash without saving it in history?
hiemye
  • 779
  • 1
  • 7
  • 9
45
votes
8 answers

How do I ask screen to behave like a standard bash shell?

Just learned about the screen command on linux - it is genius. I love it. However, the actual terminal/prompt in screen looks and behaves differently than my standard bash prompt. That is, the colors aren't the same, tab completion doesn't seem…
thornomad
  • 551
  • 1
  • 4
  • 5
44
votes
4 answers

How to output a list of changed files from rsync?

I am using rsync in a bash script to keep files in sync between a few servers and a NAS. One issue I have run into is trying to generate a list of the files that have changed from the during the rsync. The idea is that when I run rsync, I can output…
Jason M.
  • 565
  • 1
  • 5
  • 7
43
votes
2 answers

Bash: Run an executable giving a good exit status

I want to run an executable in Linux, and regardless of the exit status that it returns, I want to return a good exit status. (i.e. no error.) (This is because I'm using sh -ex and I want the script to keep running even if one (specific) command…
Ram Rachum
  • 5,231
  • 7
  • 34
  • 46
42
votes
9 answers

How to get pgrep to display full process info

Is there any way to get pgrep to give me all the info about each process that ps does? I know I can pipe ps through grep but that's a lot of typing and it also gives me the grep process itself which I don't want.
JoelFan
  • 2,285
  • 5
  • 26
  • 30
42
votes
7 answers

Bash Scripting: Require script to be run as root (or with sudo)

I'm trying to write a bash script (in Ubuntu) that will backup a directory using tar. How can I do a check in the script so that it can only be run as root (or with sudo)? For instance, if a user runs the script, it should say that this script must…
Cory Plastek
  • 979
  • 2
  • 8
  • 14
42
votes
4 answers

How do I see du in GB instead of MB in linux?

This works: du -cshm . But this fails: du -cshg . How can I see it in unit of GB?
apache
  • 3,227
  • 7
  • 27
  • 25
42
votes
9 answers

Using ctrl-arrow keys with PuTTY and screen

I searched and couldn't find a solution for this anywhere. I'm using PuTTY from Windows to connect to various servers where I run bash and screen. It seems bash works fine with ctrl-arrow keys to jump word-to-word on the command line but within…
kbosak
  • 532
  • 1
  • 6
  • 10
41
votes
6 answers

Avoid to keep command in history

I use bash and I would like to avoid some commands being kept in the history. Is it possible to do that for the next command only? Is it possible to do that for the entire session?
Luc M
  • 3,110
  • 4
  • 26
  • 27