Bash is the shell used in Ubuntu's command-line interface.

learn more… | top users | synonyms (1)

31
votes
2answers
19k views

Explanation of the command to check shellshock

Here is the command I have used to check my bash shell for the Shellshock bug: env x='() { :;}; echo vulnerable' bash -c "echo this is a test" Can anyone please explain the command in details?
26
votes
5answers
26k views

difference between bash.bashrc and /etc/environment file

Till date I used to set my environment variables in the bash.bashrc file. Recently I was told to use the /etc/environment file. Well, both work fine. So, what is the difference between them? I ...
20
votes
2answers
7k views

How can a script detect a user's idle time?

I want to check, inside a bash script, how long the user of a X session has been idle. The user himself does not have to be using bash, but just X. If the user just moved the mouse, for example, a ...
14
votes
2answers
7k views

Command for deleting temporary files ending with ~

Many days ago, I found this useful bash alias (contents of my ~/.bash_aliases) # aliases # finds temporary files ending with '~' and deletes them alias rm~='find . -name '*~' -print0 | xargs -0 ...
7
votes
3answers
24k views

Proper way to add a user account via bash script

Here's the script code I'm using now: getent group $MYGROUP if [ $? -ne 0 ] ; then sudo su -c "groupadd $MYGROUP" fi sudo su -c "useradd mynewuser -p mypassword -m -g $PRIMARYGRP -G $MYGROUP" ...
21
votes
4answers
30k views

How to save output from command (eg. diff) into a variable

I want to test if there is any output from the diff (test if files are same), if none echo "Passed $x" else echo "Failed $x". I came up with some intermidiate step (save the output from diff to a file ...
11
votes
2answers
17k views

How to pass results of bc to a variable

I'm writing a script and I would like to pass the results from bc into a variable. I've declared 2 variables (var1 and var2) and have given them values. In my script I want to pass the results from ...
11
votes
4answers
10k views

Autocompletion doesn't work while logged as root

I have just came across something that is really bothering me. Autocompletion on ubuntu works like a charm but when I login as root, e.g. su I get tab autocompletion only sometimes. Why does it work ...
5
votes
1answer
71k views

Run executable file on terminal

I'm new to Ubuntu and currently on it because of assignment. I would like to ask few questions: How do I make new command to run a shell script? For example, when you type passwd on terminal it runs ...
31
votes
7answers
4k views

How to access bash without a terminal emulator?

Say I've accidentally uninstalled every terminal emulator on my system: xterm, uxterm, gnome-terminal, guake, etc. Is there a way I can access bash without a terminal emulator? One possible way I can ...
22
votes
4answers
24k views

How save my “alias” entries forever [duplicate]

I want to save my alias commands forever like the default ones when I type "alias" so I don't retype them every time I leave my bash
15
votes
2answers
567 views

What's the missing argument to -exec?

I use the following command to clear a directory, of files and directories over 30 days old, and move them to an archive directory which I can delete after a few weeks if nobody asks for their files ...
11
votes
2answers
1k views

Re-run an application script when it crashes?

I have some applications that need to run on my laptop all the time. I use a bash script to start these applications. In my script I have a loop that looks similar to this: while true; do ...
8
votes
1answer
53k views

How to run Bash script as root with no password? [duplicate]

Possible Duplicate: How do I use sudo in my script without needing a password? I want to run a bash script as root with no password prompt. I tried visudo with no luck(your_username ...
6
votes
2answers
2k views

Get a file's emblem from command line?

I'd like to be able to determine what emblem a file has from the command line. Is there a way to determine this? Also, is there a way to apply emblems from the command line? I usually have a cron ...
5
votes
1answer
2k views

Getting the default text editor used in system

I have been searching and browsing for a long time and have not been able to find an answer to my question. I have used select-editor and I note that I am using /usr/bin/nano. Is this the default ...
20
votes
6answers
20k views

How to start a terminal with certain text already input on the command-line?

Rather than rephrasing my question, let me describe to you the desired user-case: I create a short shell-script to run command "gnome-terminal --someoptionflagname 'my text to be posted'", and ...
19
votes
2answers
28k views

How to grep 2 or 3 lines, one containing the text I want, and the others just below it?

This is a snapshot of error log: 06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed ...
18
votes
3answers
32k views

How to delete selected results from bash history?

history command shows all the results but we can filter to get particular command using history | grep searchingCommand. It is really helpful. But the problem is it shows those commands also which ...
8
votes
1answer
26k views

cp command to exclude certain files from being copied

Is there a way to use command 'cp' to copy a directory and exclude certain files/sub-directories within it?
6
votes
2answers
11k views

How to write Bash script What is the command to open a terminal with two different tabed terminals and execute some commands separately tabs?

How to write Bash script to open a terminal with two tabs, and execute commands in both tabs? for instance: tab 1 opens skype tab 2 opens chromium-browser In the end, I want one more thing: write a ...
6
votes
4answers
3k views

Keep a program running in terminal

So I am well aware of nohup and suffixing commands with & to ensure that they go into the background. However if I run a graphical application - sometimes using neither seems to do the job. So ...
4
votes
3answers
31k views

how to check if $1 and $2 are null?

I am running some script which passing the string argument and I want to do if else statement shown as below: if [ $1 != '' ] && [ $2 != '' ] then do something..... but it shown Error ...
3
votes
3answers
2k views

How do I list all available shell builtin commands?

We know bash supports number of buitin commands like: $ type type cd help command type is a shell builtin cd is a shell builtin help is a shell builtin command is a shell builtin I want to get ...
3
votes
1answer
5k views

How do I launch a bash script using a keyboard shortcut?

Just like the title says, how do I launch a bash script in my ~/Downloads folder using a keyboard shortcut? I've tried binding cd ~/Downloads && ./bash-script.sh to different accelerators (ex. ...
2
votes
1answer
6k views

bash comparing multiple column in two files with different length

I have following data set in text file data.txt d1,40,gold d2,30,silver d3,20,bronze d4,10,iron d5,5,wood d6,20,gold d7,10,wood d8,5,gold d9,10,silver . . . def.txt gold,40 silver,30 bronze,20 ...
19
votes
1answer
1k views

Why use env in shebang?

What is the purpose of using #!/usr/bin/env <sh|bash|python> shebang compared to #!/bin/bash, #!/bin/sh or #!/usr/bin/python?
10
votes
1answer
3k views

How do I show a message with username and date at login?

How to show the message "hello $username, today's date is $date" as soon as you login to Ubuntu.
8
votes
1answer
27k views

Find file or directory in whole directory structure

How can I find a file with a specific name in bash. I want to search through the whole system. I tried with find, but that only work through one level.
6
votes
1answer
40k views

The fastest way to create a file from a terminal

What is the simplest way to create a file using a command-line? Usually I use: touch filename But is this the simplest/fastest way?
6
votes
1answer
7k views

How to execute script on shutdown?

I want to execute script before I shutdown my machine that writes date to a file (so I do know what time I finish working). How to do it?
6
votes
2answers
934 views

How do the environments of a standard Terminal command-line and a bash script differ?

I know there is something different about the environment of the Terminal command-line and the environment in a bash script, but I don't know what that difference is... Here is the example which ...
6
votes
5answers
24k views

Add a string to a text file from terminal

I would like to modify a bunch of text files from the terminal, more precisey: add the string '50' to the first line of every text file in /mydat/ ? Alternatively, if you know of a link to a page on ...
3
votes
1answer
2k views

Sort files in directory by creation date(Birth)

In my Download folder I have a lot of files.I need first a way to arrange them by type second files with same type arrangement become by the type that i added(or can say downloaded or birth (if i am ...
3
votes
1answer
1k views

How to extract/inject ID3 tags via bash?

I have a huge collection of MP3 files that have ID3 metadata. Is it possible to extract existing tags and images to plain text (e.g. JSON, XML)? Can I inject from plain text to MP3 file? How can I do ...
3
votes
2answers
10k views

Creating a script to install software after a clean install?

I find myself moving between multiple new machines lately (new laptop, new computer at work, etc.). I want to create a bash script to install all the software I use. Ninite is not reach enough. I have ...
0
votes
2answers
98 views

Select Command not working while run shell scripts on remote machine

I want to run my shell script on a remote machine and I need user want to give value for some variable for that we use Read command while run script on local machine but I use the same command while ...
20
votes
4answers
3k views

What is the meaning of ./ before a given path?

I've been told to run this: ./yiic message ./app/messages/config.php But I don't understand the ./ meaning, can anyone clarify please. Note: Believe me, we can't google that. I've tried: ./ ...
20
votes
5answers
10k views

Showing a “cowsay” fortune in every new terminal session

I wish to display a cowsay message in every terminal window. The command I use is fortune | cowsay Any ideas how to make it appear whenever I start a new terminal session?
13
votes
4answers
27k views

error while loading shared libraries libSDL-1.2.so.0

I am trying to install ioquake on my ubuntu server. When I try to run it, I get this message: # ./ioquake3 ./ioquake3.x86_64: error while loading shared libraries: libSDL-1.2.so.0: cannot open ...
11
votes
4answers
2k views

Running a script created in Notepad (Windows) on Ubuntu

I created a Notepad file on Windows and copied it to Ubuntu. The file contains some iptables rules. After making the file executable using chmod +x and executing it, it didn't work. However, when I ...
10
votes
2answers
14k views

How can I protect parentheses passed to a cd command?

I asked here how to make cd protect spaces. Tab completion is great, but sometimes you paste the path from the clipboard so this is useful. The solution breaks with parentheses however. No matter how ...
9
votes
4answers
4k views

How can I play a song in the background via my command line?

I have installed play : sudo apt-get install sox libsox-fmt-mp3 I can now play my audio files like this : play Desktop/SONGS/01\ -\ Oh\ Baby\ Girl.mp3 Since I'm learning shell, I wish I could ...
8
votes
3answers
585 views

How to run a script when a directory is changed by another user?

I know has been a bit of discussion about topics similar to this. But here is what I am basically trying to do. I have a watch directory called watched and whenever a file is added to that directory, ...
8
votes
2answers
1k views

What's the use of complete command?

While running the complete command on my gnome-terminal, it shows some commands.What are they? And what is the use of complete command? $ complete complete -F _minimal complete -F _filedir_xspec ...
7
votes
4answers
2k views

Use of default alias “alert”

The default alias Alert is for the command notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e ...
7
votes
2answers
840 views

What is the difference between `VAR=…` and `export VAR=…`?

What is the difference in doing $ MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=384m" to doing $ export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=384m" and is there any side-effect of doing either in an SSH ...
7
votes
5answers
8k views

How to have a path containing spaces in PATH?

I tried export TASK=$HOME/Ubuntu\ One and export TASK="$HOME/Ubuntu One" but neither works.
6
votes
5answers
3k views

Redirect pipe output to the same file

Is there any short way to save the pipe output to the same file that it's processed. For example, this is what I am actually doing $ cat filename | sort | uniq > result $ rm -f filename $ mv ...
6
votes
4answers
1k views

Pipable command to print in color?

I'm a bit new to bash scripting, and I'm wondering if there is a program or built-in command to pipe to that will print in a specified color? Or is there an echo argument to do so? Like I could do: ...