Questions tagged [bash]
Bash (Bourne-Again SHell), is the default interactive user shell used in Ubuntu. Use this tag for questions specific to Bash, as opposed to generic POSIX shells.
1,402
questions
157
votes
5
answers
98k
views
How to navigate long commands faster?
Is there a way speed up Linux CLI navigation when I must enter long commands?
I simply use arrows right now, and - if I have a long command it takes some time to get from start of the command to the ...
129
votes
1
answer
145k
views
Cannot echo "hello" > x.txt even with sudo? [duplicate]
Possible Duplicate:
sudo & redirect output
I'm trying to create a file in /var/www, but even with sudo this fails:
user@debVirtual:/var/www$ sudo echo "hello" > f.txt
-bash: f.txt: ...
106
votes
12
answers
135k
views
Adding timestamps to terminal prompts?
I was wondering if it was possible to add timestamps to terminal prompts, and if so, how could I achieve this?
97
votes
5
answers
150k
views
How to do: underline, bold, italic, strikethrough, color, background, and size in Gnome Terminal?
How to do: underline, bold, italic, strikethrough, and color in Gnome Terminal?
Bold
Italic
u̲n̲d̲e̲r̲l̲i̲n̲e̲
s̶t̶r̶i̶k̶e̶ ̶i̶t̶ ̶l̶i̶k̶̶e̶ ̶i̶t̶s̶ ̶h̶o̶t
Color
background
font < (its mono if you ...
90
votes
5
answers
76k
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 ...
83
votes
12
answers
137k
views
How do I set up an email alert when a ssh login is successful?
Does anyone have a bash script that will email or notify someone in the case of a successful login to a ssh server? I want to be notified if anyone logs into my personal box.
I'm using Ubuntu 12.04 ...
78
votes
12
answers
236k
views
How to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash?
Is there a command to remove all files and subdirectories in a directory without deleting the directory?
For example if I have directory dontDeleteMe with subdirectories 1, 2, 3 and each subdirectory ...
76
votes
4
answers
113k
views
`apt-get` autocompletion of package name is broken
At some moment, the apt-get install autocomplete was broken. It was very useful to me to see the names of packages available for installation when pressing Tab.
For example, if I would press the Tab ...
67
votes
9
answers
147k
views
How do I use wget/curl to download from a site I am logged into?
Some parts of wikipedia appear differently when you're logged in. I would like to wget user pages so they would appear as if I was logged in.
Is there a way I can wget user pages like this
http://...
60
votes
5
answers
114k
views
Tab completion doesn't work for commands
I am trying to use tab completion for commands in Ubuntu 11.04 Beta 1, running all the latest updates, but it doesn't seem to work. (Though package bash-completion is installed)
Tab completion works ...
58
votes
10
answers
126k
views
Filenames with spaces breaking for loop, find command
I have a script which searches all files in multiple subfolders and archives to tar. My script is
for FILE in `find . -type f -name '*.*'`
do
if [[ ! -f archive.tar ]]; then
tar -cpf archive....
53
votes
3
answers
159k
views
How do you change the default shell for ALL USERS to bash?
I want every new user from now on to have bash as their shell by default.
I know that to change your own shell to bash, you would use the command "chsh -s /bin/bash", but how do I automatically set ...
51
votes
6
answers
78k
views
Why is /etc/profile not being loaded during non-login bash shell sessions?
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 /etc/profile....
51
votes
2
answers
20k
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 ...
51
votes
3
answers
112k
views
How to escape file path in SED?
I would like to replace $fileWithPath in $file, however this doesn't work because (I think) path is not escaped. How to escape it?
sed -i 's/${fileWithPath}/HAHA/g' $file
39
votes
6
answers
24k
views
How do I split a "/proc/*/environ" file in separate lines?
I'm trying to get the content of any /proc/*PID*/environ file in more readable format. I'm able to do that in the way shown below, but I'm sure this isn't the proper way.
$ cat "/proc/$(pgrep gnome-...
39
votes
2
answers
45k
views
Split a large file into smaller files and then integrate them to get the original file [duplicate]
How do I split a 7GB (movie) file into smaller files of (say) 1GB, and then (in another Ubuntu computer) integrate them to get the original file (using just bash commands)?
38
votes
2
answers
34k
views
xclip on headless server
I've been using xclip to copy the output of bash commands like so:
pwd | tr -d "\n" | xclip -selection c
So that I can then paste the output into another terminal session.
I was trying to use it on ...
34
votes
3
answers
34k
views
Using grep with pipe and ampersand to filter errors from find
I am using cygwin to find a file on the cygdrive.
However I need to suppress the permission denied messages (otherwise the results get hidden in the error messages). The following command works:
...
34
votes
6
answers
7k
views
In what order does the shell execute commands and stream redirection?
I was trying to redirect both stdout and stderr to a file today, and I came across this:
<command> > file.txt 2>&1
This apparently redirects stderr to stdout first, and then the ...
32
votes
2
answers
123k
views
What is the difference between 'su -' , 'sudo bash' and 'sudo sh'?
I would like to know what is the difference between
su -
sudo bash
sudo sh
I cannot login as root while doing su - because I do not have the root password - I mean I have my user password with ...
31
votes
7
answers
38k
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 ...
26
votes
4
answers
20k
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:
./ ...
25
votes
4
answers
50k
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 ...
23
votes
2
answers
55k
views
How can I protect parentheses passed to a cd command? [duplicate]
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 ...
22
votes
2
answers
48k
views
Terminal, how to quit --More-- list
I use autocomplete a lot in the terminal, like for example for cp command. But sometimes, when I am putting in the directory for the cp command and I press Tab, the list of files is so long that ...
20
votes
5
answers
13k
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?
20
votes
2
answers
11k
views
Can I enable bash-completion for the new apt command?
The new apt command, present in Ubuntu since 14.04, seems to be a really useful intersection of functionality between apt-get and apt-cache but the current version of bash-completion doesn't know ...
19
votes
5
answers
10k
views
Where are commands `fg`, `bg` and `jobs` installed? [duplicate]
fg, bg and jobs are used for job management. And for some reason (maybe it's just me), I'm not able to find where their binaries are nor their manpages (whereis prints no information). which gives no ...
19
votes
3
answers
65k
views
Add bash script folder to path?
I have some bash scripts in an application folder that I'd like to use as if they were on my path. If they were straight-up applications, I'd just add the directory to ~/.bashrc, but these are ...
18
votes
2
answers
44k
views
How do I pause for the specific time between two commands in a script?
I want to do something like following:
#!/bin/bash
command1
<pause for 30 seconds>
command2
exit
How can I do it?
16
votes
1
answer
11k
views
Why does /bin/sh point to /bin/dash and not /bin/bash? [duplicate]
As far as I understand bash is the default shell in Ubuntu, so why does /bin/sh point to /bin/dash?
16
votes
1
answer
4k
views
Why don't custom upstart job names tab complete in the service command?
I'm used to create upstart services with a file in /etc/init/<service>.conf and it works perfectly fine, the only thing I'd like to is to have tab completion the same way that every service in /...
15
votes
4
answers
43k
views
How to separate command output to individual lines
list=`ls -a R*`
echo $list
Inside a shell script, this echo command will list all the files from current directory starting with R, but in one line. How can I print each item on one line?
I need a ...
13
votes
1
answer
5k
views
Select a particular result from completion suggestions
Let's say I have 3 files in a particular directory: abc.txt, aww.txt, ant.txt
If I do: cat a (and press tab to see options) terminal will display the 3 file names: abc.txt, aww.txt, ant.txt
Is there ...
12
votes
2
answers
3k
views
How can I toggle the touchpad depending on whether a mouse is connected?
I want to have my touchpad disabled automatically when an external mouse is connected and enabled when there is none. I have tried using touchpad-indicator but that fails in cases when the computer ...
11
votes
3
answers
10k
views
Where is my PATH variable being set?
I'm trying to set my path variable to look like this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jgrande/android-sdk-linux/platform-tools:/usr/lib/...
10
votes
2
answers
19k
views
Where are files saved when created in a WSL terminal window?
I recently installed Ubuntu in WSL on my Windows 10 system following the steps at How to install Windows Subsystem for Linux (WSL) on Windows 10 | Windows Central. I created files in a Terminal window ...
10
votes
2
answers
3k
views
I permanently changed my PATH variable by mistake, and I am unable to login now. How to change my PATH variable to default?
I used sudo -H gedit /etc/environment command on terminal to permanently change my PATH variable.
To correct it, I pressed Ctrl+Alt+F1, and used export PATH command, but access was denied.
Many ...
10
votes
2
answers
29k
views
Rename command not found when running a script
I'm trying to to execute a script, which uses the command rename.
When I execute it, I get a message rename: command not found. Any ideas?
if [[ -z '$3' ]]; then
shopt -s dotglob
rename "$...
9
votes
1
answer
193k
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 ...
9
votes
2
answers
3k
views
using '&' in a directory name [duplicate]
i have a directory name with ISO&Emulator having some Important Files. and this directory is in different partition, and partition not showing in my FileManager(Nautilus). so i mount my partition ...
9
votes
1
answer
29k
views
How Can I Make /bin/sh point to /bin/bash?
In Ubuntu, /bin/sh points to /bin/dash by default.
I want to use /bin/bash as my system-wide shell for /bin/sh. What is the best way to do this?
8
votes
2
answers
4k
views
Delete all files except specified files/folders using command line?
I have a folder containing a lot of folders and different files with the following structures :
NASA
│
├── a
│ ├── doc1
│ ├── doc2
│ ├── doc3
│ ├── folder1
│ └── folder2
│
├── b
│ ├── ...
7
votes
1
answer
3k
views
.bashrc edit messes up terminal command arrow-up history print
I wanted to give my terminal prompt in Ubuntu a more personal look, and wanted to change the text prior to the '$' when writing a command.
From what I've found this is done by editing the .bashrc ...
6
votes
7
answers
38k
views
Can I use fractions/decimals in a bash script?
Is there a certain syntax to use while using fractions or decimals in a bash script?
I tried using the following script (in Ubuntu 12.04):
#!/bin/bash
{
n=9
echo "$n"
for (( i=.5; $i <10; i++ ));
...
6
votes
3
answers
1k
views
Bash built-ins with no manual entries
Why do some bash built-ins (such as dirs, pushd or help) don't have manual entries?
4
votes
5
answers
8k
views
bash: /usr/bin/locale-check: No such file or directory error after i downgraded from ubuntu 18.10 to 18.04
After downgrading my Ubuntu from 18.10 to 18.04 when ever trying to login I am getting the following error:
And opening the terminal following error displays
bash: /usr/bin/locale-check: No such ...
4
votes
3
answers
15k
views
What is the syntax for IF/ELSE in bash?
I am trying to pull logs and doing few others things directly. written a small line BASH but not working. I am sure thats with IF Condition.
sed -rne '/21:25:07/,/21:50:07/ p' server.log.2015-04-...
4
votes
1
answer
9k
views
Open a new terminal and source scripts
I want to write a script to activate a virtual environment and run my server for Django project in a new terminal. My startProject.sh is:
#!/bin/bash
source virtualenv/bin/activate
python manage.py ...