Questions tagged [bash]
Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).
207
questions
82
votes
7
answers
121k
views
Log all commands run by admins on production servers
It is company policy for admins to login to the servers via a personal username, and then run sudo -i to become root. Upon running sudo -i, sudo will create an environmental variable called SUDO_USER,...
38
votes
7
answers
51k
views
How can I determine what is taking up so much space? [duplicate]
I was using df -h to print out human readable disk usage. I would like to figure out what is taking up so much space. For instance, is there a way to pipe this command so that it prints out files that ...
1459
votes
39
answers
1.2m
views
How can I sort du -h output by size
I need to get a list of human readable du output.
However, du does not have a "sort by size" option, and piping to sort doesn't work with the human readable flag.
For example, running:
du | sort -...
104
votes
7
answers
110k
views
SSH from A through B to C, using private key on B [closed]
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 ...
25
votes
4
answers
17k
views
Do background processes get a SIGHUP when logging off?
This is a followup to this question.
I've run some more tests; looks like it really doesn't matter if this is done at the physical console or via SSH, neither does this happen only with SCP; I also ...
147
votes
9
answers
121k
views
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 ...
141
votes
39
answers
148k
views
What useful things can one add to one's .bashrc? [closed]
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 -...
3
votes
3
answers
32k
views
Deleting files from Remote FTP-Server older than x days
i've got a remote FTP server where i store some backups via cronjob.
The Problem is that i only got a little amount of space so im doing incremental backups. I want to keep the backups about 14 days.
...
123
votes
8
answers
278k
views
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 '/<myCommand&...
8
votes
2
answers
6k
views
My cron tasks report command not found [duplicate]
This is the contents of my crontab file:
0 0,6,12,18 * * * cd /var/www/app/current && backup perform --trigger db_backup --config_file config/backup.rb --data-path db --log-path log --tmp-...
80
votes
6
answers
65k
views
How to test if my server is vulnerable to the ShellShock bug?
How can I ensure my Bash installation is not vulnerable to the ShellShock bug anymore after the updates?
56
votes
6
answers
74k
views
Cron: Only get errors in emails?
I finally set up a realistic backup schedule on my data through a shell script, which are handled by cron on tight intervals. Unfortunately, I keep getting empty emails each time the CRON has been ...
55
votes
16
answers
110k
views
Stop ssh login from printing motd from the client?
I've got SSH passwordless set up, however it prints the MoTD when it logs in. Is there anyway to stop that happening from the client side?
I've tried ssh -q but that doesn't work. I don't want to use ...
53
votes
9
answers
209k
views
Determine if filesystem or partition is mounted RO or RW via Bash Script?
Is there an easy way to determine if a mounted filesystem is mounted as Read-Only or Read-Write? I was thinking just to pipe mount but I thought there might be an easier way.
42
votes
6
answers
6k
views
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?
39
votes
7
answers
59k
views
If I launch a background process and then log out, will it continue to run?
Asking this after a prolonged discussion with a coworker, I'd really like a clarification here.
I launch a background process, either by appending "&" to the command line or by stopping it with ...
33
votes
4
answers
55k
views
Writing to stdin of background process
I'm on an Ubuntu 10.04 box, and started a server in the background (myserver &) over ssh. It's been running fine, but I need a way to get at the server's stdin, as the only way to control the ...
33
votes
4
answers
35k
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
[email protected]:~$ cat /tmp/hello.hs
#!/...
32
votes
14
answers
87k
views
How can I display the IP address of an interface?
If I want to display the IP address that is assigned to eth1, how can I do this in Bash?
32
votes
8
answers
48k
views
Rsync seems incompatible with .bashrc (causes "is your shell clean?")
It turns out rsync can't work with a remote server which has a .bashrc file?
At local client i got when run rsync:
protocol version mismatch -- is your shell clean?
(see the rsync man page for an ...
19
votes
2
answers
82k
views
What is the difference between sudo -i and sudo su -
What is the difference between commands sudo -i and sudo su -?
Are they the same?
13
votes
3
answers
50k
views
how to filter rsyslog messages by tags
I have several applications and scripts that I want to redirect the output to custom files.
I launch those applications using
command | logger -t TAG
I would like to filter these messages based on ...
11
votes
2
answers
26k
views
No TTY present when running commands over SSH in here-document
I'm trying to run a command over SSH like this in a here-document:
ssh example.com <<END
sudo /etc/init.d/apache2 reload
END
Which normally works except when I'm trying to run something that ...
3
votes
5
answers
6k
views
Difference of running scripts manually or with a cronjob
I have a PHP script that I want to run every 10 minutes, going through database records and creating/editing movies through MEncoder. I've set up cron job to accomplish this, but it doesn't work very ...
1
vote
3
answers
2k
views
Bash piping answer in Ubuntu
In a bash script, I want to know know how to pipe in answers like for example:
ssh -l username -i /home/ubuntu/.ssh/id host.com < yes
The ssh connection would ask if I would like to continue the ...
1014
votes
15
answers
1.4m
views
How to determine if a bash variable is empty?
What is the best way to determine if a variable in bash is empty ("")?
I have heard that it is recommended that I do if [ "x$variable" = "x" ]
Is that the correct way? (there must be something more ...
547
votes
5
answers
275k
views
What is the difference between double and single square brackets in bash?
I just wondered what exactly the difference between
[[ $STRING != foo ]]
and
[ $STRING != foo ]
is, apart from that the latter is POSIX-compliant, found in sh and the former is an extension found in ...
184
votes
31
answers
100k
views
How do I prevent accidental rm -rf /*?
I just ran rm -rf /* accidentally, but I meant rm -rf ./* (notice the star after the slash).
alias rm='rm -i' and --preserve-root by default didn't save me, so are there any automatic safeguards for ...
179
votes
11
answers
111k
views
Run an interactive bash subshell with initial commands without returning to the ("super") shell immediately
I want to run a bash subshell, (1) run a few commands, (2) and then remain in that subshell to do as I please. I can do each of these individually:
Run command using -c flag:
$> bash -c "ls; pwd; ...
116
votes
8
answers
170k
views
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.
...
112
votes
85
answers
22k
views
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, ...
85
votes
6
answers
48k
views
What does passing the -xe parameters to /bin/bash do
Exactly what the title says. I'm not having much luck finding the proper documentation to see what -xe does in the following use case:
#!/bin/bash -xe
what do those parameters do and where it is ...
79
votes
3
answers
25k
views
In Bash, are wildcard expansions guaranteed to be in order?
Is the expansion of a wildcard in Bash guaranteed to be in alphabetical order? I am forced to split a large file into 10 Mb pieces so that they can be be accepted by my Mercurial repository.
So I was ...
71
votes
11
answers
34k
views
Linux: How to use a file as input and output at the same time?
I've just run the following in bash:
uniq .bash_history > .bash_history
and my history file ended up completely empty.
I guess I need a way to read the whole file before writing to it.
How is ...
62
votes
6
answers
730k
views
How to pass password to scp command used in bash script? [duplicate]
Possible Duplicate:
Connect through SSH and type in password automatically, without using a public key
I have a bash script that makes dump of DB then copies file from one server to another but ...
41
votes
2
answers
56k
views
How do ulimit -n and /proc/sys/fs/file-max differ?
I notice that on a new CentOS image that I just booted up off of EC2 that the ulimit default is 1024 open files, but /proc/sys/fs/file-max is set at 761,408 and I'm wondering how these two limits work ...
38
votes
4
answers
52k
views
How to repeatedly call rsync until files are sucessfully transferred
I'm trying to syncronize files from a remote server that is not reliable, meaning the connection tends to fail "randomly" with
rsync: connection unexpectedly closed
Rsync is called with --...
38
votes
7
answers
22k
views
SSH into a box with a frequently changed IP
I have some cloud boxes that change their IP frequently.
I ssh using the hostname but have to edit the known_hosts file every time the server launches because of this error message:
@@@@@@@@@@@@@@@@@...
37
votes
3
answers
15k
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 ...
23
votes
5
answers
42k
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 ...
22
votes
3
answers
41k
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 ...
22
votes
3
answers
21k
views
Bash prompt on Ubuntu - FQDN (\H) same as hostname (\h)
We've got seperate environments at my workplace for development, testing, integration, and staging.
Within those envs, we've overloaded the hostnames in DNS - e.g. in the dev environment, the primary ...
22
votes
6
answers
58k
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 ...
20
votes
1
answer
5k
views
Shell command slow when using pipe, fast with intermediate file
Does anyone understand this huge difference in processing time, when using an intermediate file, or when using a pipe? I'm converting tiff to pdf using standard tools on a fresh debian squeeze server. ...
16
votes
1
answer
940
views
can't type lower cased e in amazon ec2 (Amazon Linux)
After a few days of operation on my new ec2 build, the following happens:
I log into SSH, everything is fine, I do my coding
I return the next day, and log into SSH
I cannot type a lower cased e ...
14
votes
6
answers
35k
views
Log commands executed over SSH
I would like to log all commands executed over SSH.
Say,
ssh [email protected] COMMAND
I want to log "COMMAND" on server.com
I did search extensively but could not find anything.
There ...
13
votes
3
answers
11k
views
SSH from A through B to C, using private key on A
These is my scenario:
Host C is not accessible from A.
Host B is accessible from A.
Host C is accessible from B.
Both B and C have ~/.ssh/id_rsa.pub (from A) in authorized_keys
B does not have the ...
13
votes
4
answers
16k
views
Escaping spaces in a remote path when using rsync over a remote SSH connection
When using SSH to connect rsync to a remote server, how do you escape spaces and such in the remote path? A simple backslash escapes the space for the local bash prompt, but on the remote machine the ...
11
votes
5
answers
8k
views
less with "update file" like functionality
I want to watch a file that gets overwritten every 5 minutes with less. How can I make less follow the new file descriptor instead of keeping the old one displayed? watch "cat file" won't do it ...
11
votes
4
answers
28k
views
In unix, what's the best way to reduce the size of a massive log file that is actively being written to?
On a linux server, I want to reduce the size of a log file which is several GB big. Cutting off the top half, or maybe the first million lines would work.