Questions tagged [bash]

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

Filter by
Sorted by
Tagged with
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,...
Soviero's user avatar
  • 4,376
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 ...
syn4k's user avatar
  • 579
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 -...
Tom Feiner's user avatar
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 ...
wrangler's user avatar
  • 3,170
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 ...
Massimo's user avatar
  • 71.3k
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 ...
doc_id's user avatar
  • 1,509
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. ...
user25634's user avatar
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&...
rafalmag's user avatar
  • 1,341
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-...
DEfusion's user avatar
  • 287
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?
gtirloni's user avatar
  • 5,795
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 ...
Industrial's user avatar
  • 1,599
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 ...
Amandasaurus's user avatar
  • 32.3k
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.
Jake Wilson's user avatar
  • 8,924
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?
Luc M's user avatar
  • 3,290
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 ...
Massimo's user avatar
  • 71.3k
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 ...
tajmorton's user avatar
  • 445
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 #!/...
troutwine's user avatar
  • 1,482
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?
user47556's user avatar
  • 539
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 ...
Computist's user avatar
  • 473
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?
Howard's user avatar
  • 2,175
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 ...
mistyrouge's user avatar
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 ...
lpfavreau's user avatar
  • 439
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 ...
Björn's user avatar
  • 135
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 ...
user avatar
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 ...
Brent 's user avatar
  • 23.3k
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 ...
0x89's user avatar
  • 6,485
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 ...
Valentin Nemcev's user avatar
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; ...
SABBATINI Luca's user avatar
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. ...
Tommaso's user avatar
  • 1,181
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 ...
imaginative's user avatar
  • 1,981
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 ...
Sled's user avatar
  • 937
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 ...
MilliaLover's user avatar
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 ...
chubbyk's user avatar
  • 883
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 ...
bantic's user avatar
  • 1,549
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 --...
Bruno Lopes's user avatar
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: @@@@@@@@@@@@@@@@@...
coneybeare's user avatar
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 ...
AnnanFay's user avatar
  • 610
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 ...
Florin Andrei's user avatar
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 ...
mickula's user avatar
  • 342
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 ...
Ben Williams's user avatar
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 ...
BassKozz's user avatar
  • 655
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. ...
plang's user avatar
  • 325
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 ...
Kato's user avatar
  • 263
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 ...
Prashanth's user avatar
  • 271
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 ...
blueFast's user avatar
  • 4,330
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 ...
purefusion's user avatar
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 ...
d135-1r43's user avatar
  • 401
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.
Phil's user avatar
  • 113

1
2 3 4 5