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

learn more… | top users | synonyms (1)

10
votes
4answers
11k views

Why does the $PATH of an ssh remote command differ from that of an interactive shell?

I have a user that has made no modifications to the $PATH in any dot-files: it is exactly the system default setting. From a login shell: $ ssh example.com user@example.com:~$ cat /tmp/hello.hs #!/...
10
votes
3answers
4k views

Logging a “persons” activity in Linux

So I've read many of the posts related to this and have just come up more confused than before. There are recommendations for various tools including ttyrec, snoopy, acct, rootsh, sudosh, ttyrpld, ...
10
votes
3answers
18k views

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?
10
votes
3answers
12k views

iftop - how to generate text file with its output?

iftop is great tool to view almost live bandwidth usage distinguished by source-ip source-port destination-ip destination port. I'm using it to see which client's ip is using most bandwidth. Now I ...
10
votes
8answers
24k views

How do I read multiple lines from STDIN into a variable?

I've been googling this question to no avail. I'm automating a build process here at work, and all I'm trying to do is get version numbers and a tiny description of the build which may be multi-line. ...
10
votes
1answer
3k views

Where is $BASH_ENV usually set?

I have twin Linux servers that should be configured identically, however ssh commands to one of them are failing for commands that require a path that's specified in ~/.bashrc. For example, I can use ...
10
votes
4answers
553 views

How would you simplify this command?

I'm quite new to strace / netstat / etc. I'm using this command to get a trace of the apache process handling my request (telnet), is there a way to simplify it a bit? sudo strace -o /tmp/strace -f -...
9
votes
9answers
17k views

'Argument list too long' error while copying a large number of files

I am using the following command: \cp -uf /home/ftpuser1/public_html/ftparea/*.jpg /home/ftpuser2/public_html/ftparea/ And I am getting the error: -bash: /bin/cp: Argument list too long I have ...
9
votes
1answer
2k views

reboot multiple machines remotely

I need to reboot a number of machines remotely. Normally I just issue for host in <hostlist>;do ssh ${host} 'sudo shutdown -r now';done But I want give the users some time before the ...
9
votes
3answers
12k views

Edit a file via bash script

I am a beginner in bash scripting.I want to create a bash script to install install and configure stuffs on my linux box in an automated way. Suppose i want to edit /etc/yum.repos.d/epel.repo by ...
9
votes
6answers
4k views

what are Powershell's advantages over cygwin/unix-shell

The obvious difference I'm aware of, is the ability to interface to certain MS products, such as Exchange. But for one not having to administer such products, what are the advantages of Powershell? ...
9
votes
4answers
12k views

Can not update Bash on Debian 6.0 (Squeeze)

I can not update Bash on a Debian 6.0 (Squeeze) server to get rid of the discovered vulnerability: bash --version GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu) apt-get update apt-get ...
9
votes
2answers
11k views

How to keep: daily backups for a week, weekly for a month, monthly for a year, and yearly after that

I need to backup data and config files on this server, daily. I need to keep: daily backups for a week weekly backups for a month monthly backups for a year yearly backups after that All of this ...
9
votes
3answers
15k views

Linux gzip multiple subdirectories into separate archives?

How would I be able to compress subdirectories into separate archives? Example: directory subdir1 subdir2 Should create subdir1(.tar).gz and subdir2(.tar).gz
9
votes
7answers
948 views

Find directories, where files with a specific ending are missing

I want to display all directories, that do not contain files with a specific file ending. Therefore I tried using the following code: find . -type d \! -exec test -e '{}/*.ENDING' \; -print In this ...
9
votes
2answers
13k views

Can I use rsync to create a list of only changed files?

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....
9
votes
3answers
9k views

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 ...
9
votes
4answers
20k views

kill a screen (but not all screens)

I have multiple screens running on an Ubuntu server that are initiated as: screen -dmS screen1 cmd screen -dmS screen2 cmd etc... And I need to kill one screen, but not all of them. What is the ...
9
votes
2answers
5k views

Fix for bash line-wrapping & backspace display bugs on Mac OS X?

When I open up Terminal (on Mac OS X 10.5.8) and type a long command line: ...the text doesn't go to the next line when it wraps around: Also, sometimes when I type a command and then backspace (...
9
votes
1answer
798 views

Is it possible to hide a malicious alias in Bash on Linux?

Is it possible to conceal the existence of a malicious alias in Bash on a Linux system and have it executed by the user without their knowledge?
9
votes
5answers
7k views

Different color prompts for different machines when using terminal/ssh?

I have 5 machines I constantly ssh into to do work. Its getting increasingly frustrating when I am issuing wrong commands on wrong boxes. Luckily I havent done anything bad yet. I wanted to know if ...
8
votes
4answers
9k views

Linux Bash Syntax: Meaning of &&, \, and -

What do the '&&', '\' and '-' mean at the end of bash commands? In particular, I came across the following combination of lines that are supposed to add public keys to Ubuntu's aptitude ...
8
votes
14answers
6k views

What are some informative and useful shell prompts? (Bash, csh, ksh, etc.)

One of my favorite Mac OS X Terminal tips involves adding the last running process into the terminal title using the following code in your .bashrc. trap 'printf "\033]0; `history 1 | cut -...
8
votes
7answers
6k views

In *nix, how to determine which filesystem a particular file is on?

In a generic, modern unix environment (say, GNU/Linux, GNU/Solaris, or Mac OS X), is there a good way to determine which mountpoint and filesystem-type a particular absolute file path is on? I ...
8
votes
3answers
711 views

Keyboard shortcut to store typed command and clean the line

You know the situation: You are halfway through typing a long command (for example a commit message) and realize that you have forgotten to execute some prerequisite command that can not be added with ...
8
votes
2answers
1k views

Symbolic link and sudo

I create a symbolic link: ln -s /tmp/folder1 /tmp/folder2 Then I go to /tmp/folder2 and run pwd: $ cd /tmp/folder2/ $ pwd /tmp/folder2 $ sudo pwd /tmp/folder1 # <-- This is the odd part Why ...
8
votes
2answers
11k views

Bash script count down 5 minutes display on single line [closed]

I would like to have a count down of 5 minutes, updating every second and showing the result on the same line. Is this even possible with Bash scripting?
8
votes
4answers
3k views

With a username passed to a script, find the user's home directory

I am writing a script that gets called when a user logs in and check if a certain folder exists or is a broken symlink. (This is on a Mac OS X system, but the question is purely bash). It is not ...
8
votes
1answer
4k views

What does “--” (double dash) mean in this shell command?

I have this shell command: kill `cat -- $PIDFILE` What the double -- does here? Why not use just kill `cat $PIDFILE`
8
votes
6answers
27k views

How should someone create an encrypted password for /etc/shadow?

I am setting up a new account on a Linux box for Subversion repository access, and can send the password to the new user. However, I think there was a command line utility for this new user to encrypt ...
8
votes
6answers
3k views

Prune duplicate entries from PATH variable

I modify my .bashrc frequently and then source it. However, when I have things like export PATH="~/bin:~/perl5/bin:$PATH" in my file, then the PATH environment variable grows every time I source the ...
8
votes
3answers
7k views

Bash script to count number of files

I have a script and I want to display different messages if a file exists or not. I have a script like: count=ls /import/*.zip | wc -l echo "Number of files: " $count if [ "$count" > "0" ]; then ...
8
votes
4answers
4k views

Execute program each time somebody logs in via SSH into a Linux box

I have a small SSH server, and I'd like to write a script to run each time somebody logs in via SSH. Now, how would I go about that? I'd like the script to run everytime ANYBODY logs in, and I need ...
8
votes
2answers
30k views

sed replace all tabs and spaces with a single space

I got a string like the following: test.de. 1547 IN SOA ns1.test.de. dnsmaster.test.de. 2012090701 900 1000 6000 600 now I want to replace all the tabs/spaces inbetween the ...
8
votes
4answers
6k views

Possible to disable “You have new mail in /var/mail/root”?

I would like to disable the mailcheck in FreeBSD 9.1. My login shell is BASH, so I have tried to add unset MAILCHECK in /root/.bashrc and /root/.profile, but I still get those messages. Question ...
8
votes
1answer
2k views

get notification when systemd-monitored service enters failed state

I need to have network messages sent when a systemd service I have crashes or is hung (i.e., enters failed state; I monitor for hung by using WatchdogSec=). I noticed that newer systemd have ...
8
votes
4answers
13k views

Using sed to remove both an opening and closing square bracket around a string

I'm running this command in a bash shell on Ubuntu 12.04.1 LTS. I'm attempting to remove both the [ and ] characters in one fell swoop, i.e. without having to pipe to sed a second time. I know square ...
8
votes
1answer
4k views

How can I get remaining args after pulling out parsed items using getopts?

I want to parse some arguments to a bash script using getopts but want to be able to access the remaining args that are not included in the option list. So for example, if I have a call: % script -a -...
8
votes
5answers
10k views

chsh: PAM authentication failed

i want to change default shell env and run chsh -s /bin/zsh as root user, but a error message appeared: chsh: PAM authentication failed. i find this thread http://ubuntuforums.org/showthread.php?t=...
8
votes
1answer
2k views

Can i call pushd/popd and prevent it printing the stack?

After calling pushd/popd in bash, it will print off the current directory stack. Is there any way to prevent this behaviour, so that it will act 'quitely'? This sort of noise in a command is uncommon ...
8
votes
4answers
18k views

What's a proper way of checking if a PID is running?

I have a .pid file, and I need to check if the process is running. So far I found two options kill -0 `cat something.pid` which prints out an error if the pid isn't running. I know this can be ...
8
votes
3answers
11k views

Stdout/stderr redirects in start-stop-daemon

I'm trying to write init config that will redirect output of my daemon to two files (for stdout and stderr). The problem is, it's not working. I'm reading this right now. So, I've done this shell ...
8
votes
2answers
7k views

linux: kill all my processes but not this terminal

I want an easy way in linux to kill all my current processes. The problem with kill -9 -1 is that it also kills the current terminal. Is there an easy way to kill everything except the current ...
8
votes
1answer
3k views

Debian SSH - Resizing terminal does not register with bash

We recently reinstalled our server due to a disk failure, and now we're having an issue with resizing terminals. We installed Debian 6.0.6. Symptoms When you resize a terminal, no ncurses-based apps ...
8
votes
4answers
256 views

Bash one-liner to atomically create a file if it doesn't exist

I want a Bash one-liner that atomically creates a file if it doesn't exist. That means essentially "if file doesn't exist, create it" but ensuring that no one else manages to create the file in the ...
7
votes
4answers
922 views

Script to automatically install packages

I want to write a bash or perl script to install a number of packages on my debian based machine. I want it to be something like : aptitude install package1 aptitude install package2 But, I do ...
7
votes
9answers
13k views

Bash snippet to move all files in a directory into that directory

I have a directory with lots of files and directories in it. In order to tidy it up, I'm going to put all those files into a directory, so I was going to do something like this: $ ls | wc -l 123 $ ...
7
votes
4answers
5k views

Count number of bytes piped from one process to another

I'm running a shell script that pipes data from one process to another process_a | process_b Does anyone know a way to find out how many bytes were passed between the two programs? The only ...
7
votes
3answers
3k views

Copy a file's owner permissions to group permissions

How can I copy a file's user/owner permissions to it's group permissions? For example if the permissions are 755 I want them to become 775. Clarification: 755 -> 775 123 -> 113 abc -> aac Bonus if ...
7
votes
9answers
333 views

How would I grab a text file off of a windows machine from a linux cli?

I am writing a bash script to analyze the mail logs on our network, which is mostly postfix boxes, but would like to include MS Exchange logs in the analysis if possible. Is there any way to copy a ...