A shell script is a script written for the shell, or command line interpreter, of an operating system.

learn more… | top users | synonyms (1)

61
votes
1answer
36k views

Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin [duplicate]

I'm running an Ubuntu Server 13.04, but I see the same on a 12.04: I have six directories with command files. These are: /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin What are the ...
54
votes
1answer
6k views

Can I make the webcam take a picture when an incorrect password is entered?

I am using a laptop . I was thinking to have a support in my Ubuntu machine. When an incorrect password is entered, a picture is taken later revealing who has been trying to gain access. I have ...
51
votes
3answers
58k views

How can I get a list of all repositories and PPAs from the command line?

I know how to list all packages installed on my system. But how could I get a list of all repositories and PPA's? I know I can look into /etc/apt/sources.list and /etc/apt/sources.list.d, but I'm ...
48
votes
3answers
3k 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 ...
45
votes
2answers
14k 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
43
votes
6answers
10k views

What is the difference between ./ and sh to run a script?

I have written a simple script. When I runsh <myscriptname.sh>, i got the correct output, but when I run ./<myscriptname.sh>, I got an error. What is difference between when I do sh and ...
42
votes
2answers
86k views

What is difference between #!/bin/sh and #!/bin/bash?

if I write, #!/bin/bash echo "foo" or #!/bin/sh echo "foo" both yields same. I have seen some scripts starting with #!/bin/sh or #!/bin/bash. Is there any difference between them?
41
votes
3answers
47k views

ssh: automatically accept keys

I've written this small utility script: for h in $SERVER_LIST; do ssh $h "uptime"; done When a new server is added to $SERVER_LIST, the script is stopped with: The authenticity of host ...
41
votes
5answers
9k views

How do I create a deb package for a single python script?

I have a single python script that I want to distribute as a deb package. It is a indicator which shows local date in Unity panel. I did follow create a .deb Package from scripts or binaries but I ...
40
votes
0answers
10k 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 ...
34
votes
7answers
13k views

Repeat a command every x interval of time in terminal?

How can I repeat a command every interval of time , so that it will allow me to run commands for checking or monitoring directories ? There is no need for a script, i need just a simple command ...
33
votes
2answers
61k views

How to add a shell script to launcher as shortcut [duplicate]

Possible Duplicate: How can I edit/create new launcher items in Unity by hand? How can I create launchers on my desktop? I want to add some shell scripts in my launcher as shortcuts.. ...
32
votes
2answers
6k 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 ...
30
votes
3answers
1k views

Should I save my scripts with the .sh extension?

I have some functional scripts and I want to copy to /usr/bin I want to use them as normal terminal commands. Is it a good practice to use them with the .sh extension or can I save them without ...
30
votes
1answer
1k views

How can I make cowsay say something every time I close the terminal?

I want cowsay to print something like "have a nice day" when I close the terminal. I know I have to have some kind of script, but I'm not even sure how to write a script or how to use it once it's ...
29
votes
6answers
69k 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 ...
29
votes
3answers
7k views

How to make Skype use notify-osd?

How do I make Skype use the default Ubuntu notify-osd to display notifications (incoming messages, users connecting, etc.) instead of the Skype's own "ugly" message box?
28
votes
5answers
24k views

Beep in shell script not working?

I'd like to use a beep sound in a shell script. Unfortunately none of the methods I found via Google work for me. I tried echo -e '\a' echo -ne '\007' and the command beep after I installed it ...
28
votes
9answers
93k views

How can I create a select menu in a shell script?

I'm creating a simple bash script and I want to create a select menu in it, like this: ./script echo "Choose your option:" 1) Option 1 2) Option 2 3) Option 3 4) Quit And according to user's ...
28
votes
3answers
93k views

'chmod u+x' versus 'chmod +x'

What is the difference between chmod u+x and just chmod +x? I have seen a ton of tutorials that say to use u+x to make scripts executable. However, the u is not mentioned in the chmod help or ...
26
votes
5answers
35k views

How to execute a script just by double clicking like .EXE files in Windows?

How can I make a bash script executable by double clicking just like .exe files in Windows? I tried creating a launcher and assigning the script to it, but there are two consequences: the terminal ...
26
votes
8answers
2k views

How to keep “dot files” under version control?

Etckeeper is a great tool for keeping track of changes to your configuration files in /etc A few key things about it really stand out. It can be used with a wide variety of VCSs: git, mercurial, ...
25
votes
1answer
62k views

Command to append line to a text file without opening an editor

Assuming i have a line that i want to add to a file without opening an editor. How could i append this line alias list='ls -cl --group-directories-first' to this file config.fish
24
votes
7answers
2k views

Delete all files apart from pdf files in a directory

I have a directory that contains the following: x.pdf y.zip z.mp3 a.pdf I want to delete all files apart from x.pdf and a.pdf. How do I do this from the terminal? There are no subdirectories so no ...
23
votes
3answers
2k views

Where should I put my script so that I can run it by a direct command?

Where can (should) I put my (bash) script so that it can be used (forever) by terminal or by a direct command: Alt+F2? I know there is /usr/bin and /sbin & /bindirectories but when should I use ...
23
votes
3answers
2k views

Can I modify a bash script (.sh) file while it is running?

Suppose I have a script script.sh, which takes some time to execute. I execute it, ./script.sh. While it is running in a terminal window, I modify the file script.sh. Will this have any effect on the ...
22
votes
5answers
51k views

How can I make a script that opens terminal windows and executes commands in them?

I have three scripts I need to run when I start up my Ubuntu machine, they start services I use in my development environment. To do that, I manually open three terminals and type in the commands. ...
21
votes
4answers
46k views

How to install an init.d script in ubuntu?

I am trying to install an init.d script, to run celery for scheduling tasks. Here is the steps I followed: copied the file celeryd and pasted it in folder /etc/init.d/ created a configuration file ...
21
votes
4answers
70k views

I've downloaded a .sh file - how do I install this?

I'm new to Ubuntu and know installing programs only from window. It is very easy there: Just double-click the setup.exe and the things start. But how do I install a program on Ubuntu? I want to ...
21
votes
1answer
10k views

how to execute a command after resume from suspend?

I've got a script that is executed in order to have suspending/resuming working in my laptop. Then I have another series of xinput,xkbset and xmodmap commands that are executed when I initiate a ...
20
votes
4answers
33k views

How to run an alias in a shell script?

I have an executable file mpiexec, whose full path is ~/petsc-3.2-p6/petsc-arch/bin/mpiexec. Since I want to execute this command in different directories (without having to retype the entire path), ...
18
votes
3answers
960 views

How can I initiate Nautilus file operations from the command line?

How can I start Nautilus's "File Operations" GUI from the command line? My goal is to include this in a Nautilus script.
17
votes
7answers
8k views

How can a script check if it's being run as root?

I'm writing a simple bash script, but I need it to check whether it's being run as root or not. I know there's probably a very simple way to do that, but I have no idea how. Just to be clear: What's ...
17
votes
7answers
15k views

Command to convert an upper-case string to lower-case?

What is the Bash command I can use to convert an upper-case string to lower-case and vice-versa? Thank you.
17
votes
3answers
4k views

Why doesn't “cd” work in a shell script?

What is wrong with this easy script? I just want to write an script which change my directory: A. I put below commands on the file witch its name is pathABC on the /home/alex directory, #!/bin/sh cd ...
17
votes
5answers
41k views

How to determine if a string is a substring of another in bash?

I want to see if a string is inside a portion of another string. e.g.: 'ab' in 'abc' -> true 'ab' in 'bcd' -> false How can I do this in a conditional of a bash script?
17
votes
5answers
26k views

How do I tell a start up program to start minimized?

Here is a quesion that has been bugging me. You know how you can set up a program to run on start up right? Well, how can i tell it to start minimized, like you would do in windows? TeamViewer ...
17
votes
3answers
91k views

How can I make “rc.local” run on startup?

I have a script that I would like to run when my system starts. I have put it on "rc.local", but it doesn't work. How can I enable it to run on startup? Thanks!
17
votes
5answers
10k views

Execute script before shutting down

When I shut down my computer I want to show some pending tasks that I have to do before leaving the office... I did a local application to manage those tasks, basically I just want to run a command, ...
16
votes
6answers
21k views

Upstart script doesn't start

Ubuntu 10.04 I have created this upstart script (/etc/init/pure-ftpd.conf): # pure-ftpd - FTP server description "Pure-FTPd server" start on filesystem stop on runlevel S respawn respawn limit ...
16
votes
2answers
7k views

Record a programs output with PulseAudio

I would like to record an output of a program with PulseAudio using command line/bash script. It is important not to record every output of the sound card, but only the one of one specific program. I ...
15
votes
6answers
33k views

Not able to execute a .sh file: /bin/bash^M: bad interpreter

I wanted to execute a shell script: -rwxr-x--x 1 root root 17234 Jun 6 18:31 create_mgw_3shelf_6xIPNI1P.sh I tried to do a standard procedure, but I am got this error: ...
15
votes
4answers
10k views

Script to display all terminal colors

Throughout the internet I have seen many people with scripts that prints out a bunch of stuff in all the colors defined in ~/.Xdefaults. However when I try to use these, I always get error: Bad ...
15
votes
3answers
24k views

At what time does cron execute daily scripts?

If I place a shell script in /etc/cron.daily/, at what time of the day will it be executed?
15
votes
5answers
15k 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 ...
15
votes
2answers
4k views

How can I find the location (on the desktop) of a window on the command line?

I'm trying to write a little script to help manage my windows via keyboard shortcuts. In order to do what I want, I need to be able to find the current location and size of the "active" (focused) ...
14
votes
7answers
59k views

How to run scripts every 5 seconds using cron?

I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?
14
votes
2answers
1k views

What is apt-fast and should I use it?

Several times over the past couple years, I've heard of people using apt-fast for updating and installing packages, but I'm not really sure what it does. I think I've traced its origin to this forum ...
14
votes
2answers
3k views

Installing breach browser

EDIT: Just look at the accepted answer. I wasn't how it worked at the time of writing so I just guessed below. I am new to Linux so this might be a noob question. I am trying to install a new web ...
14
votes
2answers
2k views

How can I write Nautilus scripts in Python?

I want to write a Nautilus script in Python. Is that possible? If it is possible, how can I do that?