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.

Filter by
Sorted by
Tagged with
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 ...
Zweih's user avatar
  • 329
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 ...
Inkayacu's user avatar
  • 815
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: ...
stefan83's user avatar
  • 333
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 ...
Leron's user avatar
  • 1,660
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?
Lautaro Alvarez's user avatar
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?
Tuminoid's user avatar
  • 3,952
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/...
Faisal's user avatar
  • 301
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.
Avinash Raj's user avatar
  • 78.5k
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 ...
HoCo_'s user avatar
  • 413
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. #!/...
Paradiesstaub's user avatar
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 ...
Tim's user avatar
  • 32.8k
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 ...
dannymcc's user avatar
  • 333
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 ...
yayu's user avatar
  • 3,391
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 ...
Eyal's user avatar
  • 1,221
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 ...
SidMan's user avatar
  • 401
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 ...
Karl Morrison's user avatar
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 ...
kramer65's user avatar
  • 2,133
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 ...
tubu13's user avatar
  • 291
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/...
Maik Klein's user avatar
  • 1,321
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 --...
naka's user avatar
  • 419
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 ...
rich's user avatar
  • 179
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 ...
user avatar
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/...
Vinayak Garg's user avatar
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 / $...
CybeX's user avatar
  • 526
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 ...
Arronical's user avatar
  • 19.9k
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 ...
Zanna's user avatar
  • 70.4k
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 ...
Pomario's user avatar
  • 2,038
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 ...
whitenoisedb's user avatar
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/...
c0rp's user avatar
  • 9,820
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?
Radu Rădeanu's user avatar
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 ...
Info5ek's user avatar
  • 251
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 ...
Ahmed Zain El Dein's user avatar
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 ...
evamvid's user avatar
  • 235
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 ...
user avatar
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?'
user123456's user avatar
  • 2,368
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. ...
vijay12289's user avatar
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:...
Heuyie's user avatar
  • 169
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-...
Staring Frog's user avatar
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 ...
autorun's user avatar
  • 273
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 ...
deepblue's user avatar
  • 284
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}.
Eleandro Duzentos's user avatar
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 ...
Shubham Pandey's user avatar
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 ...
user552771's user avatar
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). ...
user564448's user avatar
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 ...
yuvi's user avatar
  • 1,017
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 ...
cr0c's user avatar
  • 277
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 ...
schrobe's user avatar
  • 233
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 ...
listenlight's user avatar
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'...
Konrad Viltersten's user avatar
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 ...
William's user avatar
  • 7,668

1
8 9
10
11 12
28