Skip to main content

Questions tagged [shell]

A shell is terminology for a command-line interpreter most commonly used with Unix-like operating systems, but also used to interact with GUI-based operating systems in a more granular fashion. Not only does it allows the user to run programs from a text interface, but frequently offers basic programming features such as variables, substitution, output redirection, and wildcards.

Filter by
Sorted by
Tagged with
548 votes
5 answers
276k views

What is the difference between double and single square brackets in bash?

I just wondered what exactly the difference between [[ $STRING != foo ]] and [ $STRING != foo ] is, apart from that the latter is POSIX-compliant, found in sh and the former is an extension found in ...
0x89's user avatar
  • 6,495
227 votes
14 answers
435k views

Shell command to monitor changes in a file

I know there was a command on Unix that I could use to monitor a file and see changes that are getting written to it. This was quite useful especially for checking log files. Do you know what it is ...
Sebastian Hoitz's user avatar
191 votes
10 answers
325k views

What is "-bash: !": event not found"

Try executing the following under a bash shell echo "Reboot your instance!" On my installation: root@domU-12-31-39-04-11-83:/usr/local/bin# bash --version GNU bash, version 4.1.5(1)-release (i686-pc-...
Maxim Veksler's user avatar
165 votes
8 answers
132k views

What does 'set -e' do, and why might it be considered dangerous?

This question has appeared on a pre-interview quiz and it's making me crazy. Can anyone answer this and put me at ease? The quiz has no reference to a particular shell but the job description is for a ...
egorgry's user avatar
  • 2,911
155 votes
19 answers
471k views

How to add a timestamp to bash script log?

I have a constantly running script that I output to a log file: script.sh >> /var/log/logfile I'd like to add a timestamp before each line that is appended to the log. Like: Sat Sep 10 21:33:...
Antonius Bloch's user avatar
130 votes
2 answers
48k views

Colors in bash after piping through less?

When I have dircolors defined life is full of... color. When I pipe ls through less to scroll around I lose the colors. Any suggestions?
MathewC's user avatar
  • 7,017
124 votes
8 answers
320k views

How can I kill all stopped jobs?

When I try to exit from my Linux server I get the message: There are stopped jobs. : Is there a single command to kill these?
yazz.com's user avatar
  • 7,543
118 votes
5 answers
78k views

What's the difference between the single dash and double dash flags on shell commands?

I'm new to working in the shell and the usage of these commands seems arbitrary. Is there a reason one flag has a single dash and another might have a double dash?
kylex's user avatar
  • 1,443
116 votes
8 answers
172k views

How to run command as user who has /usr/sbin/nologin as Shell?

All I need to do is to run a specific script as a particular user who does have the nologin/false shell indicated in /etc/passwd. I would run the script as root and this should run as another user. ...
Tommaso's user avatar
  • 1,181
115 votes
6 answers
184k views

How to let 'cp' command don't fire an error when source file does not exist?

I'm using Mac OS X. I'm trying to copying some files with cp command for a build script like this. cp ./src/*/*.h ./aaa But this command fires an error if there is no .h file in ./src directory. How ...
Eonil's user avatar
  • 10.7k
105 votes
7 answers
189k views

Is there a way to do a remote "ls" much like "scp" does a remote copy?

Is there a way to do a remote "ls" much like "scp" does a remote copy in a standard linux shell?
yazz.com's user avatar
  • 7,543
103 votes
6 answers
314k views

Adding a directory to $PATH in CentOS?

We just got our new server(s) up and we're running CentOS on them all. After successfully installing Ruby Enterprise Edition, I would now like to add the REE /bin (located at /usr/lib/ruby-enterprise/...
vonconrad's user avatar
  • 1,281
78 votes
7 answers
58k views

How do I join two named pipes into single input stream in linux

Using the pipes (|) feature in Linux I can forward chain the standard input to one or several output streams. I can use tee to split the output to separate sub processes. Is there a command to ...
user avatar
77 votes
6 answers
53k views

How can I check in bash if a shell is running in interactive mode?

How can I tell (in ~/.bashrc) if I'm running in interactive mode, or, say, executing a command over ssh. I want to avoid printing of ANSI escape sequences in .bashrc if it's the latter.
Alex B's user avatar
  • 1,794
76 votes
9 answers
89k views

Command to prepend string to each line?

Looking for something like this? Any ideas? cmd | prepend "[ERRORS] " [ERROR] line1 text [ERROR] line2 text [ERROR] line3 text ... etc
user14645's user avatar
  • 1,690
75 votes
3 answers
50k views

What is the difference between unlink and rm?

Is unlink any faster than rm?
Marcin's user avatar
  • 853
73 votes
11 answers
178k views

Linux: using find to locate files older than <date>

find has good support for finding files the more modified less than X days ago, but how can I use find to locate all files modified before a certain date? I can't find anything in the find man page to ...
DrStalker's user avatar
  • 7,106
67 votes
5 answers
26k views

How can I set environment variable for just one command in fish shell?

In bash, I can do EDITOR=vim crontab -e. Can I get similar effect in Fish shell?
skalee's user avatar
  • 783
67 votes
10 answers
19k views

Unique Features of bash compared to zsh

I have been a zsh user for quite some time (before that tcsh and before that csh). I am quite happy with it, but was wondering if there are any compelling features of bash that do not exist in zsh. ...
Tim's user avatar
  • 1,899
66 votes
7 answers
136k views

Choosing the shell that SSH uses?

How do I set the shell that is used when a user SSHs to a server. For example I can't stand BASH and need to use ZSH, how do I make it so ZSH is loaded along with my profile (.zsh_profile) when I ssh ...
JP Silvashy's user avatar
  • 1,487
65 votes
9 answers
147k views

How to split a PEM file

Note : This is not really a question because I already found the answer but since I didn't find it easily here I will post it so that it can benefit others. Question : How to read a concatenated PEM ...
Cerber's user avatar
  • 1,271
62 votes
5 answers
209k views

How can I hide the output of a shell application in Linux?

How can I hide the screen output (printf) of a shell application in Linux?
Jader Dias's user avatar
  • 4,745
60 votes
8 answers
274k views

Run a shell script as a different user

What's a good way of running a shell script as a different user. I'm using Debian etch, and I know which user I want to impersonate. If I was doing it manually, I would do: su postgres ./backup_db....
Wadih M.'s user avatar
  • 1,052
60 votes
1 answer
18k views

What is the difference between a 'Login' and an 'Interactive' bash shell

What is the difference between a ‘Login’ and an ‘Interactive’ bash shell? I have quoted Wikipedia below but can anybody give a better answer? EDIT: This is a community wiki so maybe rather than voting ...
59 votes
3 answers
65k views

find command default sorting order

what is the default sorting order for entries returned by the linux find command? For example, if I issue find . -type f -name '*mp3' and the output consists of multiple files across multiple sub-...
Nasko's user avatar
  • 593
58 votes
1 answer
174k views

What's the difference between sudo su - postgres and sudo -u postgres?

PostgreSQL users peer authentication on unix sockets by default, where the unix user must be the same as the PostgreSQL user. So people frequently use su or sudo to become the postgres superuser. I ...
Craig Ringer's user avatar
  • 11.3k
57 votes
7 answers
140k views

Force SSH to use a specific shell

Is there any way to force SSH to use a particular shell on the remote end, regardless of what the user's default shell is? I've tried solutions akin to: ssh host.domain.com /bin/bash -c 'complicated,...
plinehan's user avatar
  • 715
56 votes
6 answers
75k views

Cron: Only get errors in emails?

I finally set up a realistic backup schedule on my data through a shell script, which are handled by cron on tight intervals. Unfortunately, I keep getting empty emails each time the CRON has been ...
Industrial's user avatar
  • 1,599
54 votes
14 answers
88k views

Templating with Linux in a Shell Script?

What I want to acomplish is: Having a config file as template, with variables like $version $path (for example apache config) Having a shell script that "fills in" the variables of the ...
Markus's user avatar
  • 887
46 votes
4 answers
64k views

How to list symbolic link chains?

Given this example: mkdir a ln -s a b ln -s b c ln -s c d If I execute: ls -l d It will show: d -> c Is there a way for ls or any other linux command to show d -> c -> b -> a instead?...
Kalecser's user avatar
  • 563
44 votes
23 answers
71k views

Finding the Public IP address in a shell script

I can find my IP address using ifconfig or hostname -i command. But how do I find my Public IP? (I have a static public IP but I want to find it out using unix command)
shantanuo's user avatar
  • 3,619
43 votes
6 answers
91k views

Shell command to see the HTTP headers

Is there a shell command to see the headers of a HTTP request? For example, I would like to know what the headers retrieved from www.example.com/test.php are How can I do this?
Damiano's user avatar
  • 431
43 votes
5 answers
21k views

Faking the date for a specific shell session

I'm certainly trying to achieve something weird here, but I want to fake the date locally for a shell session on GNU/Linux. I need to black-box test how a program behaves at different dates, and ...
nicoulaj's user avatar
  • 1,205
42 votes
2 answers
33k views

Run command as Linux "system" user (shell = /bin/false)

I created a "system" user in Ubuntu 11.04 (adduser --system) for running certain cron jobs, but sometimes I want to test things out by manually running commands as that user. What's the easiest way to ...
EMP's user avatar
  • 5,194
41 votes
9 answers
71k views

Need to fix file permissions in a user's home directory

Does anyone have a tool or script that will recursively correct the file permissions on a directory? On an Ubuntu Linux machine, a bunch of files were copied to a USB disk with full 777 permissions (...
mlambie's user avatar
  • 1,241
41 votes
6 answers
136k views

How to rename multiple files by replacing word in file name?

Replace ACDC to AC-DC For example we have these files ACDC - Rock N' Roll Ain't Noise Pollution.xxx ACDC - Rocker.xxx ACDC - Shoot To Thrill.xxx I want them to become: AC-DC - Rock N' Roll Ain't ...
holms's user avatar
  • 1,604
39 votes
1 answer
32k views

Run command in detached tmux session

This is probably simple, but I really can't find out how you do it. I have read the man pages and googled without results. Problem: How do I run a command in a detached tmux window? Example: I want ...
Accatyyc's user avatar
  • 495
38 votes
3 answers
7k views

#!/bin/sh vs #!/bin/bash for maximum portability

I usually work with Ubuntu LTS servers which from what I understand symlink /bin/sh to /bin/dash. A lot of other distros though symlink /bin/sh to /bin/bash. From that I understand that if a script ...
cherouvim's user avatar
  • 844
36 votes
8 answers
25k views

Is there any reason to use bash over zsh? [closed]

I'm curious about why one would want to run bash instead of zsh. I mean zsh is fully backwards-compatible with bash. Don't get me wrong: I don't dislike bash or anything. I just genuinely want to ...
Jason Baker's user avatar
  • 1,229
36 votes
16 answers
52k views

Can't run AWS CLI from CRON (credentials)

Trying to run a simple AWS CLI backup script. It loops through lines in an include file, backs those paths up to S3, and dumps output to a log file. When I run this command directly, it runs without ...
binaryorganic's user avatar
34 votes
12 answers
131k views

How to find the gateway IP address in Linux

What command can you use to find the Gateway IP Address (ie. home router address) for eth0 in Linux? I need to get the IP address from a command line app to use in a shell script.
J. Polfer's user avatar
  • 609
34 votes
4 answers
55k views

Append an echo to file?

In linux, how do I do something like echo 'hello world' > log.txt but instead of overwriting the contents of log.txt, it appends to the end of of log.txt?
learningtech's user avatar
  • 7,549
34 votes
4 answers
32k views

What is /bin/dash?

I thought /bin/sh was a symlink to my shell of choice. I've always used bash, so I assumed that /bin/sh would point to /bin/bash. It turns out, though, that it points to /bin/dash. It gets funnier. I ...
aioobe's user avatar
  • 391
33 votes
14 answers
94k views

How can I display the IP address of an interface?

If I want to display the IP address that is assigned to eth1, how can I do this in Bash?
user47556's user avatar
  • 549
33 votes
8 answers
86k views

How do I exclude directories when listing files?

How do I exclude directories when listing files in the current directory? ls . ^ will include directories in the listing.
Stephen Watkins's user avatar
32 votes
12 answers
21k views

How to pass alias through sudo

I have an alias that passes in some parameters to a tool that I use often. Sometimes I run as myself, sometimes under sudo. Unfortunately, of course, sudo doesn't recognise the alias. Does anyone ...
Tanktalus's user avatar
  • 461
31 votes
7 answers
91k views

Don't need the whole line, just the match from regular expression

I simply need to get the match from a regular expression: $ cat myfile.txt | SOMETHING_HERE "/(\w).+/" The output has to be only what was matched, inside the parenthesis. Don't think I can use grep ...
Alex L's user avatar
  • 591
31 votes
3 answers
6k views

Did a cat /dev/urandom - Broken terminal

Out of curiosity, when your shell character set breaks from doing something like cat /dev/urandom is there a way to fix that in place?
Pedro Montoto García's user avatar
31 votes
6 answers
4k views

Linux server out of space

I have been asked this question in two consecutive interviews, but after some research and checking with various systems administrators I haven't received a good answer. I am wondering if somebody can ...
user avatar
31 votes
8 answers
12k views

Why does it take tens of seconds to get a shell prompt?

It's a sort of regular occurrence that, after SSHing to a server (or even opening a terminal on my Mac), the login banner prints immediately but it takes ~10 seconds to a minute for the shell prompt ...
jacobbaer's user avatar
  • 473

1
2 3 4 5
28