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,400
questions
20
votes
3
answers
4k
views
What does 'apt-get install update' do?
I saw this snippet in some installation instructions:
$ apt-get install update
I know what apt-get install XXXX does and I know what apt-get update does, but I can't find any info on what this ...
20
votes
2
answers
8k
views
Can I create a separate bash history file for each terminal profile?
I use a bash script to start gnome-terminal with multiple tabs, each tab using a different profile, working directory, and in some cases executing a command within the tab.
In this situation, I'd ...
20
votes
8
answers
24k
views
remove file but exclude all files in a list
I need to cleanup a folder periodically.
I get a filelist which contains text, which files are allowed.
Now I have to delete all files which are not in this file.
Example:
dont-delete.txt:
...
19
votes
3
answers
30k
views
How to skip the evaluation of ampersand in command line?
When inputting a Google Maps Directions URL into the command line (for opening with Chromium browser via the terminal) there is an ampersand (&) in the URL, however the terminal breaks it there ...
19
votes
1
answer
8k
views
How to get the PID of my script?
If I have the script "script1.sh" and I want to make it print its own PID as a first step. How can I do this in bash?
19
votes
2
answers
3k
views
Why use env in shebang? [duplicate]
What is the purpose of using #!/usr/bin/env <sh|bash|python> shebang compared to #!/bin/bash, #!/bin/sh or #!/usr/bin/python?
19
votes
2
answers
8k
views
Can anyone explain why sudo ls with a wildcard doesn't work?
$ sudo -iu abc ls -ltr /sites/servers/server_instance/logs/access*
ls: cannot access /sites/servers/server_instance/logs/access*: No such file or directory
$ sudo -iu abc ls -ltr /sites/servers/...
19
votes
2
answers
8k
views
How to list all the shell keywords?
$ type if
if is a shell keyword
I don't know the other shell keywords.
Is there any command
to list all the bash shell keywords.?
Note: help -m displays both shell builtins and shell keywords.
19
votes
5
answers
8k
views
How do I execute multiple commands using the same argument?
I wonder if it is possible to make chain actions in Ubuntu terminal like:
action 1 on objectA . then action 2 on objectA
without having to repeat the name of objectA anymore.
Example:
touch ...
18
votes
2
answers
18k
views
How to package a simple bash script [duplicate]
The below bash script was written in ~10 sec, but packaging it would take me hours of skimming through big walls of text so I ask my self if there is an easy way out there that I don't know about.
#!/...
18
votes
1
answer
3k
views
Why does bash thinks that 010 is 8?
Why does bash think the number 010 = 8?
x=010
echo $x
010
echo $(( x+0 ))
8
echo $(( x-2 ))
6
I thought it might be binary, but 010 = 10 = 2. So why does it get 8, and how can I make it think ...
18
votes
2
answers
21k
views
Auto confirm when running bash scripts?
I am working on a simple bash script that configures new servers how I want them. It's nothing special but it will hopefully save me quite a lot of time in the future.
How do I prevent prompts like ...
18
votes
1
answer
7k
views
PS1 problem, messing up CLI
I did a simple PS1 assignment
PS1="\e[0;31m[\W]\$ \e[m "
All I wanted to do was to change the prompt color and display only the relative path. However this messes up the CLI. For example, when ...
17
votes
1
answer
3k
views
How can I automatically time commands in bash?
In tcsh, there's the variable time:
The time shell variable can be set to execute the time builtin command
after the completion of any process that takes more than a given number
of CPU ...
17
votes
1
answer
8k
views
Detect clipboard copy/paste event and modify clipboard contents
After something is copied to clipboard (using ctrl+c) I want a script (bash, python or any other language) to automatically detect that new entry is added to clipboard, change it's content and put it ...
16
votes
1
answer
71k
views
Run script on login (script with sudo) or startup
#!/bin/bash
ids=$(xinput list | awk '/SteelSeries Sensei Raw Gaming Mouse .*pointer/ {print $8}' | sed 's/id=\(.*\)/\1/')
if [ -z "$ids" ]; then
exit 0;
fi
read -a ids_array <<< $ids
...
16
votes
7
answers
13k
views
Auto complete for often used command line commands?
For some projects I often type in a couple commands, like for example:
cd an/extremely/long/path/in/which/I/have/some/kinda/project
and
./runmyproject --with some --command line --options set
...
16
votes
5
answers
15k
views
ZSH removed, cannot relogin
So I have install zsh and I didnt like it.
so I did apt-get remove zsh
From that point I cannot relogin, i click my user.. and then it just go back to the login screen. I can only login with the ...
16
votes
0
answers
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 PATH=$PATH:/path/...
16
votes
3
answers
135k
views
configure: error: C compiler cannot create executables
I was trying to install rvm using \curl -L https://get.rvm.io | bash -s stable --ruby --autolibs=enable --auto-dotfiles. It worked fine until I got a configure error:
Error running './configure --...
16
votes
9
answers
4k
views
Renaming large number of image files with bash
I need to rename approx. 70,000 files. For example:
From sb_606_HBO_DPM_0089000 to sb_606_dpm_0089000 etc.
The number range goes from 0089000 to 0163022. It's only the first part of the name that ...
16
votes
4
answers
42k
views
Bash command history not working
The command history between sessions is not getting saved. I'm using guake and the history for the session is working fine.
I noticed that .bash_history had some commands I executed in sudo -s mode ...
15
votes
2
answers
12k
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 /bin/...
15
votes
4
answers
4k
views
Why does division in bash arithmetic compute most percentages as 0?
Attempting bash arithemetic for a script, but $e does not update till the end. The output speaks for itself.
max=5
for e in $(seq 1 1 $max); do
percent=$(( $e/$max*100 ))
echo "echo $e / $...
15
votes
2
answers
2k
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 ...
15
votes
8
answers
10k
views
How can I count files with a particular extension, and the directories they are in?
I want to know how many regular files have the extension .c in a large complex directory structure, and also how many directories these files are spread across. The output I want is just those two ...
15
votes
2
answers
3k
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 ...
14
votes
5
answers
18k
views
Unique sorting: Redirect 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 ...
14
votes
5
answers
6k
views
Is there any default function/utility to prompt the user for yes/no in a Bash script?
Sometimes I need to ask the user for yes/no to confirm something.
Usually I use something like this:
# Yes/no dialog. The first argument is the message that the user will see.
# If the user enters n/...
14
votes
1
answer
69k
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?
14
votes
5
answers
13k
views
Am I using bash or sh? [duplicate]
I'm connected to a remote shell and many keys aren't working properly such as arrows and the escape key. This answer Arrow keys, tab-complete not working suggested I might be in the wrong shell, so I ...
13
votes
2
answers
35k
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 ...
13
votes
4
answers
9k
views
Is it possible to cancel or clear a notification created by using notify-send?
So I wrote a little script that makes sure a certain user plugs in a laptop when he logs on (it disables if he doesn't). The script uses notify-send to tell him to plug it in. If he plugs it in, the ...
13
votes
4
answers
8k
views
How can I have mkdir cd into the newly-created directory? [duplicate]
Frequently, I type these commands in bash:
mkdir something
cd something
I almost never do this:
mkdir something
ls # something in the current directory, not ./something/
And never this:
mkdir ...
12
votes
5
answers
8k
views
How can I kill a specific X window
Given IDs produced by wmctrl -l, I d like to be able to kill the process linked to the window ID.
How would you suggest to do it?'
12
votes
4
answers
4k
views
Bash script to limit the number of logins
My company has the requirement that I have one server application running, which all users accessing it via putty terminal. I want to write a shell script that only 20 putty terminal should be open. ...
12
votes
1
answer
15k
views
Cannot activate virtual environment with a shell script [duplicate]
I read similar questions and have tried their suggestions but I still cannot activate my virtual environment. The hierarchy of directories is:
myproject
-- virtualenv
-- startvenv.sh
startvenv.sh is:...
12
votes
2
answers
9k
views
How to automatically set terminal title to directory name without path
Currently, my bash terminal/tab title is set based on the directory I'm in. For example:
bob@bobscomputer:~/i/had/some/great/pie/yesterday
This isn't very useful if I have multiple tabs open side-by-...
11
votes
2
answers
5k
views
How can I pass filenames with spaces as arguments?
I have a Python script which accepts string arguments.
$ python script.py "one image.jpg" "another image.jpg"
This works as expected.
Python argparse: ["one image.jpg", "another image.jpg"]
If I ...
11
votes
2
answers
2k
views
Excluding certain files and directories when deleting files
My top-level directory is data. data includes several directories and these directories have sub-directories. I need to remove all files and directories inside data/ except several files in some ...
11
votes
6
answers
6k
views
Reuse the `apt up` part of the `apt update` and `apt upgrade` commands to execute both in sequence in just one line
How to reuse the apt up part of the apt update and apt upgrade commands to execute both commands in sequence in just one line without an alias.
Something like: apt up{date,grade}.
11
votes
3
answers
75k
views
bin/bash: bad interpreter: No such file or directory
I just shifted from Windows to Linux (Ubuntu 18.04)...and following a tutorial to learn bash scripting...
I wrote a simple shell script
#!bin/bash
echo "Hello World"
but when I tried to run it ...
11
votes
1
answer
10k
views
how to pass a{sv} arguments to gdbus?
i have problem to passing the arguments of the function in a dictionary format (string,variant); i try to run a screencast in gnome and to start the function i need to pass these asrguments:
-method ...
11
votes
4
answers
37k
views
bash profile works for user but not sudo
I've modified my .profile to include a folder if a flash drive is plugged in. When running the command as the user it works fine but tells me the scrip must be run by sudo (this is what i want). ...
10
votes
2
answers
9k
views
How to toggle xinput device prop
I can disable a device like this:
xinput set-prop 13 "Device Enabled" 0
But I want to actually set a custom shortcut that toggles this between 0\1. My bash skills are kinda rusty, so how can I do ...
10
votes
3
answers
9k
views
Can you use gnome keyring in bash script, if yes then how?
I am developing a automated mounting script for Windows shares. I have finished the script and it works just fine, but is it possible to add Gnome Keyring to the bash so once user writes hes/hers ...
10
votes
1
answer
11k
views
Why is "rm" so much slower than deleting files via the File Manager?
I witnessed that deleting directories (with the size of a couple of gigabytes) which contain many files is very slow when using rm. It takes up to several minutes!
When deleting the same folder via ...
10
votes
3
answers
9k
views
echo the alias command before running it
I've got a few aliases I want to clarify. They are working. How can I make this an option for many other aliases. Awk or grep? And pointers helpful. Thanks.
# IP addresses
alias myip="echo '# myip ...
10
votes
1
answer
9k
views
What does the syntax of pipe and ending dash mean? [duplicate]
Disclaimer. I'm a long-time Windows user and just starting to get my head around the Linux paradigm. While excited by it, I understand that my formulations might be poorly chosen due to ignorance.
I'...
10
votes
5
answers
26k
views
Assign VNC password using script
I am using a script to automatically set up a computer. I need to assign a password to the vnc server for the user, which is normally done using the vncserver command. However, it prompts for the user ...