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

learn more… | top users | synonyms (1)

5
votes
5answers
17k views

Read the first line of a file using bash

Does anyone know of a simple one liner to read the first line of a file in bash?
5
votes
3answers
1k views

Why does 'pkill /?' kill my SSH session?

After running the following commands (bash) as root via SSH: pkill --help pkill -h pkill /? The first two commands didn't provide me any information, that's why ran the third (kinda ...
5
votes
9answers
10k 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 ...
5
votes
5answers
15k views

Bash child proccess PID - how do you get it?

Can any one tell me how to get the PID of a command executed in bash. E.g. I have a bash script that runs imapsync. When the script is killed the imapsync process does not always get killed, so I'd ...
5
votes
9answers
882 views

Best practices to prevent 'rm -rf /' in bash scripts

It's well known fact that extra space in env.variable can lead to deletion of / directory in bash script. #!/bin/bash ... rm -rf /$MYPATH if $MYPATH contains values like " dir" or "dir /" it will ...
5
votes
6answers
3k 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 ...
5
votes
3answers
3k views

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
5
votes
8answers
3k views

Bash can't start a programme that's there and has all the right permissions

This is a gentoo server. There's a programme prog that can't execute. (Yes the execute permission is set) About the file $ ls prog $ ./prog bash: ./prog: No such file or directory $ file prog prog: ...
5
votes
3answers
4k views

bash script: repeat command if it returns an error

I would like to create a loop that repeats a ncftp transfer if it returns an error. I'm a little unsure how the exit code variable can be used in a loop. Would something like this work? until [$? ...
5
votes
3answers
1k views

Send message to IRC channel from bash

I have installed ircd-hybrid on my Ubuntu Server (192.168.1.2, example.com). We use #teamchannel to communicate inside the team. The question is: how can I send some short message from example.com to ...
5
votes
3answers
2k views

Bash command for regular expression substitution

What bash command can be used for regex substitution on a pipe? cat foo.txt | someprogram
5
votes
3answers
347 views

Bash variable assignment using another variable as part

I have the following excerpt from a bash script used to backup a database #!/bin/bash DB=database_name DBUSER=username FILENAME=$DB_$(date +%s).sql I am trying to reuse the value of DB within the ...
5
votes
6answers
2k views

how do I make solaris shell more familiar for a linux user? [closed]

I've been a linux user for years. Very used to the bash shell, used to linux shell key mappings that come with most mainstream distros. I'm also a happy vim user in linux & love my arrow keys. ...
5
votes
3answers
3k views

Linux file copy with ETA?

I'm copying a large amount of files between disks. There's approximately 16 GB of data. I'd like to see progress information, and even an estimated time of completion from the command line. Any ...
5
votes
1answer
471 views

how to pre-create directories on linux for file storage

looking for a way to pre-create directories on linux to be used to store a large number of files. We will be generating file ids using a GUID - I need to keep a copy of these files on a linux web ...
5
votes
3answers
2k views

echo based on grep result

I need a one liner which displays 'yes' or 'no' whether grep finds any results. I have played with grep -c, but without success.
5
votes
3answers
3k views

Determine if file is in the process of being written upon?

I need to deploy an automated process (via 1 min cron script) that looks for tar files in a specific directory. If a tar file is found, it is untarred to the appropriate location and then the tar file ...
5
votes
2answers
783 views

What is the purpose of each of the different UNIX/Linux shell startup files?

Previously, when setting up a *NIX environment for the first time, I would put all of my shell customisations into .bashrc, with the following .bash_profile: if [ -f $HOME/.bashrc ]; then . ...
5
votes
4answers
3k 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 ...
5
votes
4answers
3k views

Prompt customization: how to detect when there is no tty

I have a customized prompt with colors (using tput) and every time I start a non-interactive session in the server I get a bunch of errors. For instance if I start a non-interactive session like this: ...
5
votes
5answers
256 views

Not able to delete lot of files at once in linux

I have run the following command, from inside of these log folders. But it looks like each folder will take infinite time. find . -type f -exec rm -v {} \; rwxrwxr-x 2 root root ...
5
votes
2answers
695 views

-bash: ./flume: No such file or directory BUT flume is there and works elsewhere

We have a product built on CentOS 4 32-bit Linux that runs unmodified on 32- and 64-bit CentOS/RHEL 4 and 5 and SLES 10. It also runs unmodified on SLES 9 64-bit. [SLES 9 32-bit requires a different ...
5
votes
1answer
2k views

Add server to known_hosts

I would like to add github.com to the known_hosts file from the command line as I am creating a puppet manifest to provision a remote server. I have tried: "ssh-keyscan -H github.com > ...
5
votes
5answers
4k views

BSD - Remove non-ascii characters from all files in a directory recursively

I'm trying to migrate a bunch (300GB+) of files from a FAT32 drive to my freeNas ZFS filesystem but every command I throw at it (tar,pax,mv,cp) throws an 'invalid argument' when it encounters a ...
5
votes
2answers
1k views

What is the maximum length of a command line in Mac OS X?

I'm generating models in Ruby on Rails, and some of these tables have an awful lot of columns. What's maximum length of a command in Mac OS X?
5
votes
2answers
2k views

Is there a way to configure bash to always page output?

I'd like to configure bash to page the output of all commands. Essentially, I want bash to behave as if every command I enter ended with '| less'. Is this possible?
5
votes
2answers
225 views

Any repercussions from not using default primary groups for Linux users?

We were thinking of not using the default primary group for our RHEL users. What I mean by default: User: melbin Primary group: melbin We will instead do something like: User: melbin Primary ...
5
votes
2answers
539 views

Why does CTRL-r act weirdly (showing only part of a command) on OS X

Ctrl-r is a great little tool for searching your .bash_history for previously run commands. However, when I use it in my OS X Terminal.app I see weird behavior, and I was wondering if anyone else ...
5
votes
2answers
593 views

What does this Linux command do?

I have by a mistake written this command on a CentOS server xargs rpm -e|rpm -qa|grep test11 where I meant rpm -qa|grep test11|xargs rpm -e which should uninstall all packages matching "test11". ...
5
votes
1answer
568 views

Verify disown command

I issued the ^z; bg; disown sequence in order to allow me to close an ssh session in which I am running a super-important long-running process. This process writes status output to stderr, and it has ...
5
votes
1answer
556 views

Script launching 3 copies of rsync

I have a simple script that uses rsync to copy a Postgres database to a backup location for use with Point In Time Recovery. The script is run every 2 hours via a cron job for the postgres user. For ...
5
votes
3answers
513 views

Reconstructing .bashrc from running session

I accidentally deleted my .bashrc. I still have the terminal running. What settings can I recover? I already have the aliases (from the alias command). I assume that all ifs and cases are gone, but I ...
5
votes
1answer
479 views

What to do if wget's progress:mega doen't cut it anymore?

I have script for downloading large files in a queue. Now I would really appreciate it, if I had a decent log. Specifying the -o or -a option is apparently specially made for that, however as of the ...
5
votes
1answer
945 views

Should the 'nobody' user on my headless Ubuntu server have shell access?

I've read conflicting stuff on a few forums etc. regarding this. When I enter the following line: grep nobody /etc/passwd I get the following output ...
5
votes
4answers
2k views

How can one set a terminal's title with the 'tput' command?

I discovered through this answer that I've been setting terminal colours in my prompt in a naive way for years. I've now modified my .bashrc to use 'tput' commands to colourise various elements of my ...
5
votes
3answers
748 views

Getting more helpful tab completion prompts in bash?

Let's say I have a directory with a few files in it like this: $ ls file1 file2 file3 And I want to do some tab completion in bash: $ cat file<tab> file1 file2 file3 I remember ...
5
votes
2answers
3k 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 ...
5
votes
7answers
7k 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. ...
5
votes
2answers
4k 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 ...
5
votes
2answers
1k views

Bash: menu-complete only for few matches

With Bash auto-completion, is there a way to cycle through matches using menu-complete only if there are 1-2 options, and use listing with complete otherwise? Example home directory contains ...
5
votes
1answer
398 views

bash tab completion only works for root

I set up an Ubuntu 12 server (on rackspace cloud using their preconfigured image) and created a non-root user. When I log in as the standard user, pressing [TAB] at the terminal outputs an actual tab ...
4
votes
3answers
806 views

Bash: How can I add a line to the end of a file which I only have access to via sudo?

I have tried: sudo "some string" >> test.txt But am being denied permission. Can anyone help?
4
votes
4answers
2k views

Combine multiple unix commands into one output

I need to search our mail logs for a specific e-mail address. We keep a current file named maillog as well as a week's worth of .bz2 files in the same folder. Currently, I'm running the following ...
4
votes
8answers
6k 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 $ ...
4
votes
4answers
17k views

How can i fully log all bash scripts actions?

I want to capture ALL the logs data, both with error messages, from my script output, and redirect them all to log file. I have script like below: #!/bin/bash ( echo " `date` : part 1 - start " ssh ...
4
votes
3answers
769 views

Possible to ignore the users shell in “su” command?

If I do su - -c 'mkdir bin' user1 then I get su: /usr/bin/ksh: No such file or directory because the users shell is set to ksh in /etc/passwd and ksh is not installed. Question How do I carry ...
4
votes
2answers
808 views

AWK and file names with space in it.

I'm trying to parse files with awk to change their names. Everything went well until im started to do this with files with space in file name. File names are something like 11237_712312955_2012-01-04 ...
4
votes
4answers
390 views

In the Bash prompt, why does Control+x and Backspace clear the current line?

I discovered this by mistake: Control+x followed by Backspace Does anyone know why this clears the line? Any documentation?
4
votes
6answers
2k views

Bash Script To Repair Directory and File Ownership

My client had me deploy some folders out to a bunch of home directories for his customer websites. I did this with a Bash script, but it ended up using the root account permissions. How do I make a ...
4
votes
3answers
176 views

Pipe stderr and stdout to different commands (not just to files)

I'm making a backup script for ldap. I want the errors to go to a file in /var/log and the output to go to another file in the backup folder. Currently I'm redirecting to a temp file and then sending ...