Bash is the shell used in Ubuntu's command-line interface.
67
votes
10answers
23k views
Moving from bash to zsh
I'm considering moving from bash to zsh as I often come across posts praising zsh. I'm an experienced command line user and I'm assuming the basics are pretty much the same, so I'm looking for advice ...
60
votes
8answers
5k views
How can I tell what date Ubuntu was installed?
is there a command which will output the date that ubuntu (or any distribution) was installed?
45
votes
3answers
1k views
Is #!/bin/sh read by the interpreter?
In bash or sh, I guess anything which starts with # is a comment.
But in bash scripts we write:
#!/bin/bash
And in Python scripts, there is:
#!/bin/python
Does this mean that # by itself is a ...
41
votes
6answers
5k views
What to do when Ctrl-C won't kill running job?
Sometimes, processes ignore the SIGINT signal sent by Ctrl-C in Bash. For instance, man and vi. Assuming you don't want to google or read the manual on how to exit the running process, is there any ...
40
votes
4answers
20k views
How do I sudo a command in a script without being asked for a password?
I want to turn my system on automatically every day. So I use the below code in my Python script, but sudo asks me for a password every time:
os.system('sudo sh -c "echo date \'+%s\' -d \'+ \
...
39
votes
5answers
3k views
How can I easily share the output of a command or a text file with others?
I recently asked a question on AskUbuntu (or somewhere else), and a comment or answer asks me to paste the contents of some file or the output of a command to troubleshoot my problem.
How do I do ...
35
votes
3answers
5k views
How can I determine whether a shellscript runs as root or not? [duplicate]
Possible Duplicate:
How can a script check if it’s being run as root?
This is something I've been curious about. I make a lot of small bash scripts (.sh files) to do tasks that I routinely ...
32
votes
4answers
2k views
How can I undo the last cd command?
Is there any way to jump back to the previous working directory after doing a cd to a different directory?
My use-case is that I'm traversing a directory structure for a Java project, and I'm ...
30
votes
6answers
2k views
Is there a difference between the '&&' and ';' symbols in a standard BASH terminal?
They seem to both signal BASH to commence with another command following the symbols but is there a distinct difference?
29
votes
4answers
1k views
Removing files with a certain extension except one file from terminal
I need to remove all files with .gif extension except one file with name say "filename.gif". What is the optimal way to go about doing this in terminal?
The command rm *.gif removes all gif files ...
26
votes
2answers
3k views
bashrc or bash_profile?
I know the difference between the two bash login scripts:
.bashrc is run only by "non-login" shells.
.bash_profile (or .bash_login or .profile) is executed by "login" shells.
Does anyone have some ...
23
votes
4answers
1k views
What is the purpose of the -9 option in the kill command?
Is there a difference between
kill -9 212121
and
kill 212121
22
votes
3answers
13k views
Why ~/.bash_profile is not getting sourced when opening a terminal?
Problem
I have an Ubuntu 11.04 Virtual Machine and I wanted to set up my Java development environment. I did as follows
sudo apt-get install openjdk-6-jdk
Added the following entries to ...
22
votes
3answers
12k views
/etc/profile not being sourced
For 11.04, I did a fresh install of my system. Part of that install was to install rvm, which sticks a rvm.sh in /etc/profile.d/. This doesn't work as /etc/profile (which loads each +r in ...
20
votes
5answers
2k views
Removing folder named ~
This is the output of ls -l
ls -l
total 53484
drwxr-xr-x 3 root root 4096 2011-02-10 05:59 ~
-rw-r--r-- 1 root root 54313810 2011-02-13 05:09 jobs.jar
-rw-r--r-- 1 root root 384035 2011-02-15 ...
20
votes
2answers
579 views
How to run a script every time internet connects
I often mount a remote drive using sshfs. I would love to have this mount automatically. However, if I mount it in my .bashrc or startup scripts, the mount often fails because my wireless internet ...
20
votes
6answers
20k views
How do you select the fastest mirror from the command line?
I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple ...
18
votes
4answers
1k 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:
./ ...
18
votes
4answers
2k views
How save my “alias” entries forever
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
18
votes
2answers
3k views
What is the difference between “source” and “.” in bash?
As the question says, what is the difference between executing a script with source command and with . , i.e.:
source /some/script
and
. /some/script
17
votes
4answers
8k views
Running programs in the background from terminal
How do I run a program in the background of a shell, with the ability to close the shell while leaving the program running?
Lets say my UI is having problems or for some reason, I need to boot up a ...
17
votes
3answers
8k views
How to grep for tabs without using literal tabs and why does \t not work?
When I search for tabs in a file with (e)grep I use the litteral tab (^v + <tab>). I can not utilize \t as a replacement for tabs in regular expressions. With e.g. sed this expression works very ...
17
votes
5answers
1k views
How do I teach bash in Ubuntu some curse words?
When bash encounters an unknown command(word?) it does this :
The program 'hello' can be found in the following packages:
* hello
* hello-debhelper
Try: sudo apt-get install <selected ...
17
votes
3answers
2k views
Bash auto-completion with added spaces – why, and how to fix?
I use tab completion more than typing letters. I used to type rm ~/De<TAB> and it would be completed to rm ~/Desktop/ so that I could continue on the next level.
Recently, that behaviour ...
17
votes
3answers
335 views
Switch terminal output language from native language to english
How can I switch the terminal output language from my native language to English, so I can post my Ask Ubuntu question with English terminal output (error messages)?
16
votes
4answers
8k 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 ...
16
votes
2answers
1k views
How does this [t]ricky bracket expression in grep work?
I saw this one-liner recently:
$ ps -ef | grep [f]irefox
thorsen 16730 1 1 Jun19 ? 00:27:27 /usr/lib/firefox/firefox ...
So it seems to return the list of processes with "firefox" ...
16
votes
2answers
8k views
How do I add environment variables?
I'm running Ubuntu 11.04. I use the terminal to start a bash session, and I want to add an environment variable:
$r@hajt:~$ env THEVAR=/example
But it's not working. It shows all the variables with ...
16
votes
1answer
448 views
What's the difference between set, export and env and when should I use each?
Every so often I'll bash out a bash script and it strikes me there are a few ways of setting a variable:
key=value
env key=value
export key=value
When you're inside a script or a single command ...
16
votes
0answers
4k views
How do I set a path permanently? [duplicate]
Possible Duplicate:
How to add a directory to my path?
I am trying to install the play framework permanently.
http://www.playframework.org/documentation/2.0.2/Installing
export ...
15
votes
4answers
2k views
15
votes
2answers
514 views
Bash: delete from cursor till end of line with a keyboard shortcut
Consider the following bash prompt, where ^ denotes the prompt location:
# git commit -am "[bug 123456] Do this and that with the bug"
^
Suppose that I want to commit ...
15
votes
2answers
4k 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 ...
15
votes
5answers
1k views
Repercussions to sharing .bashrc across machines with Dropbox?
I work on a lot of different machines, all running Ubuntu (not always the same version). I have some really basic customizations to my prompt I would like to have available on all machines.
I ...
15
votes
3answers
2k views
How do I modify my PATH so that the changes are available in every Terminal session
I want to add a directory to search my search path. I know I have to modify the $PATH environment variable. However, I want the change to be permanent, so that it is always in effect, for every ...
15
votes
6answers
4k views
How do I make my terminal display graphical pictures?
This is a quick mockup i copy and pasted together. I imagine this being super cool and useful.
Does something like this exist already?
14
votes
5answers
540 views
Teaching bash to beginners who only used Windows
I'm supposed to give an introduction to using the shell (i.e. bash) to total beginners. Which is the most basic/useful stuff I can teach someone within 1 1/2 hours without demanding too much?
Here ...
14
votes
3answers
1k views
How do I search a PDF file from command line?
I'm checking references of a paper and want to find the positions in the body where some paper (in the references list) is referenced. Is there a PDF editor which supports search via bash and extract ...
14
votes
2answers
4k views
How can I tell if my system was booted as EFI/UEFI or BIOS?
How do I determine whether a particular running Ubuntu system was booted using EFI/UEFI, or BIOS?
14
votes
1answer
238 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?
13
votes
5answers
17k views
Bash remove first and last characters from a string
I have a string like that:
|abcdefg|
And i want to get a new string called in someway (like string2) with the original string without the two | at the start and at the end of it
so that i will ...
13
votes
5answers
1k views
How can I create an alias for cd and ls?
I frequently run the ls command after running the cd command. How can I create an alias (like cs) for this operation?
13
votes
5answers
9k views
How can I decode a base64 string from the command line?
I would like to write a bash script to decode a base64 string. For example I type decode QWxhZGRpbjpvcGVuIHNlc2FtZQ== and it prints Aladdin:open sesame and returns to the prompt.
So far I have tried ...
13
votes
2answers
553 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 ...
13
votes
3answers
602 views
iPython Like Command History For Shell
For those of you who don't do python programming on ubuntu, ipython is a python shell on steroids, but it has this amazing feature that it not only autcompletes based on known names (i.e. the same way ...
13
votes
4answers
16k views
How to clear bash history compeletly?
I want to clear all before command from history of my server. I use history -c it seems all things are cleared but when I ssh to the server,all commands are still there.
How can I clear them ...
13
votes
5answers
3k views
How to avoid duplicate entries in .bash_history
The same command is listed in my history again and again. How can I avoid this? I know it's possible via HISTCONTROL but I haven't found the right way.
13
votes
3answers
483 views
How (and where) can one change 'user@host $:' pattern in gnome-terminal?
When I start terminal in Ubuntu, I see:
ilya@HOST:~$
I need to add a timestamp to this, something like:
2011-10-09T09:32:00 ilya@HOST:~$
How can I configure this?
13
votes
2answers
2k views
Is it possible to make writing to .bash_history immediate?
I often open lots and lots of Terminals [Right now I have 7 open on this workspace] and I often search history with grep to find a command I've just written recently, but I don't want to hunt down the ...
12
votes
5answers
781 views
Shell script to -9 kill based on name
Is there a way (perhaps a script) how to automate this process:
petr@sova:~$ ps -ef | grep middleman
petr 18445 2312 1 12:06 pts/2 00:00:01 /home/petr/.rvm/gems/ruby-1.9.3-p362/bin/middleman ...



