The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks.

learn more… | top users | synonyms (1)

7
votes
4answers
532 views

How can I find a file whose name includes a given string, such as “abcde”?

Within a set of directories, how do I find a file whose name includes a given string, such as "abcde"?
6
votes
3answers
624 views

Why I can't escape spaces on a bash script?

I'm trying to escape the space char for a path in Bash, but neither using a backslash or quotes works. .sh script: ROOT="/home/hogar/Documents/files/" FILE=${ROOT}"bdd.encrypted" ...
6
votes
5answers
2k views

Why does shell Command Substitution gobble up a trailing newline char?

As per the following example, and as in my recent question In bash, where has the trailing newline char gone?, I want to know "why" it happens x="$(echo -ne "a\nb\n")" ; echo -n "$x" | xxd -p # ...
6
votes
7answers
1k views

Is it bad practice to set root's shell to something other than the default?

Once a friend of mine (who is an experienced Unix/Linux user) told me that setting root's shell to something other than sh (i.e bash or zsh) might create problems, because some script might assume ...
5
votes
3answers
7k views

Find files which are created a certain time after or before a particular file was created

I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created. If I go with find -newer, that means I'd have to create a temporary ...
4
votes
4answers
111 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
4
votes
5answers
715 views

Multiple ssh sessions in single command

I'm trying to copy a database from one server to another. I tried using the following command and it's getting tied up on entering the ssh passwords. If I put in one server's password, it complains ...
3
votes
1answer
126 views

Why is my find not recursive?

I am running the following command, but it is not performed recursively: find . -name *.java I know there are java files further down in the current directory but it is performing the find on the ...
3
votes
1answer
454 views

gnome-terminal: keep track of directory in new tab

I'm on Arch linux, and when I open a new terminal tab, it always goes to $HOME. How can I make it so that when I open a new tab, it opens the shell in the directory I was in previously?
3
votes
3answers
331 views

Concatenating thousands of files: > vs >>

I found two seemingly contradictory answers on StackOverflow to the following questions: Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure) How do I ...
3
votes
4answers
319 views

Piping paths with different types of quotes for slash substitution

I would like to use sed to convert a path with backslashes to the same path with forward slashes: E.g. I would like to pipe \\path\to\file\ and obtain /path/to/file None of the following commands ...
2
votes
4answers
72 views

Can a running script identify the logging context?

Let us say I redirect the STDOUT, STDERR of a program to files. ./script.sh 1> output.log 2> error.log Can the running program find this out i.e. know the paths to these files?
2
votes
5answers
606 views

Extract date from a variable in a different format

Let me explain you the problem $ date +%c -d "$d" Tue 31 Dec 2013 01:13:06 PM CET $ date +'Today is %F' -d "$d" Today is 2013-12-31 This solution corresponds to current date. But I have one ...
2
votes
5answers
456 views

How to start a program in the background

The program Boblight does not run in background. There is no noticeable difference between executing sudo boblightd and sudo boblightd& How can I solve this problem that the console will ...
2
votes
2answers
232 views

How to copy multiple files but keep their extensions the same?

I am looping through a number of files, and $file represents the current file. How can I make copies or renames and keep the extension the same for this current file? e.g. if $file = x.jpg How to ...
2
votes
2answers
380 views

Working of rm/ls with [0-9]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
2
votes
2answers
492 views

Use of quotes in GNU grep regular expressions

I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within ...
2
votes
2answers
428 views

Changing tmux .bash_profile behavior

I have a script in my .bash_profile that prompts for X sessions to boot. When I launch tmux, I get this prompt that I had only intended for the TTY login. Is there something I can put in ...
2
votes
3answers
1k views

Bash while loop and reading from pipe

I have a Windows command-line program that I'm running in a Bash script in Ubuntu via wine. The Bash script basically looks like this: wine myprogram.exe | while read line do # Process line done ...
2
votes
3answers
1k views

Switching to superuser while shell script is running

I have a shell script that contains the following lines: CURRENT_USER=${USER} echo $CURRENT_USER su echo switch to `who am i` Once the 2nd line is executed, the shell prompts me to enter the root ...
2
votes
2answers
398 views

How do I output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices

I am having trouble knowing how to output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices.
1
vote
1answer
107 views

how to send keyboard signal using a shell script

I have an application in graphical interface that when I run it, it's not opened in full screen mode, but when I use the keyboard shortcut Alt+Ctrl+M , it becomes fullscreen, I want to change the ...
1
vote
2answers
886 views

bash: syntax error near unexpected token `}'

I tried using this: $ if [$a == 1] then { echo 'yes'; } fi; but I get an error: -bash: syntax error near unexpected token `}' What is the correct format? I tried several with no luck.
1
vote
1answer
155 views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
1
vote
4answers
480 views

Stripping all vowels but the first from a set of strings

I have a string comprised of multiple substrings, separated by underscores. For example: AbcdAEfd_hEgdgE_AbAAAAA. I need to remove all vowels except the first from each substring. So: AbcdAEfd -> ...
1
vote
2answers
1k views

How to pass data outside process for zenity progress?

Usually this would be a question about how to pass data from a subprocess to a main process, but maybe zenity has some extra quirks so please focus on zenity. Example: #!/bin/sh ( echo "10" ; sleep ...
1
vote
1answer
15k views

How do I execute a remote shell script over SSH and be prompted for passwords by commands that require it in that script?

I want to do something like this ssh user@remote-domain.com ./remote_script.sh Contents of remote_script.sh #!/bin/bash hg pull This example is much simpler than what I am actually doing. I know ...
0
votes
1answer
38 views

Updating last modified time of a file

I have created a script to read 15 pcap files from a folder and merge then into one file using mergecap command. I want the merged file to have the creation time same as the first file of the 15 files ...
0
votes
4answers
134 views

Why does the command shuf file > file leave an empty file?

I know this is sort of a duplicate of another question (Why this sort command gives me an empty file?) but I wanted to expand on the question in response to the answers given. The command shuf ...
0
votes
1answer
4k views

mounting problem during installation of archlinux on dell xps one

I've been trying to install archlinux on xps one. the screen doesn't work because it has intel g45/g43 express chipset. I had to use nomodeset option as mentioned in the installation guide. Arch ...
0
votes
3answers
248 views

Syntax errors in a bash script executed from tcsh

I wrote the line below in order to verify if the first or second fields of a list of numbers are equal to 146. I want to run the line from tcsh, with one line interpreted by bash. What's the problem ...
0
votes
1answer
2k views

Script failing with “command not found: ^M”

When I try to run the following script in zsh, via the command /bin/zsh ~/.set_color_scheme.sh I get the following error: command not found: ^M The script has u+x permissions and it used to work on ...
0
votes
2answers
181 views

Why does this compound command report errors when copying directories?

if one executes the following two commands in one line, as follows, rm -rf dir ; cp -r dir2 dir it may complain that cp can not create directory dir/subdir: File exists but if these two commands ...
0
votes
2answers
240 views

2 consecutive ssh logins [duplicate]

Possible Duplicate: Common multiple SSH connections file handling issue I used to do something like that often: home $> ssh user@server1 user@server1's password: server1 $> ssh ...
30
votes
8answers
2k views

Output “Hollywood-hacker-scene” from a shell

This might seem like a strange question, but what would you use for creating the typical hollywood hacking scene? I got this request from a friend and my brain was blank. All I could think of was ...
26
votes
5answers
2k views

When do you use brace expansion?

I understand what brace expansion is, but I don't know how best to use it. When do you use it? Please teach me some convenient and remarkable examples if you have your own tip.
78
votes
3answers
7k views

Why is “echo” so much faster than “touch”?

I'm trying to update the timestamp to the current time on all of the xml files in my directory (recursively). I'm using Mac OSX 10.8.5. On about 300,000 files, the following echo command takes 10 ...
34
votes
6answers
33k views

How to add a newline to the end of a file?

Using version control systems I get annoyed at the noise when the diff says No newline at end of file. So I was wondering: How to add a newline at the end of a file to get rid off those messages?
22
votes
2answers
1k views

What does a “< <(…)” redirection mean?

I've seen that rvm (ruby version manager) is installed using the following command: bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) So as I ...
26
votes
2answers
1k views

Command line: <<< instead of <<

Why is the command md5sum <<< 'ddd' (output: d6d88f2e50080b9602da53dac1102762 -) right, and md5sum << 'ddd' not? What does <<< mean?
16
votes
4answers
2k views

Is there a program that can send me a notification e-mail when a process finishes?

I am a computational scientist, and I run a lot of lengthy calculations on Linux. Specifically, I run molecular dynamics (MD) simulations using the GROMACS package. These simulations can take days ...
15
votes
2answers
456 views

How can I stream data to a program that expects to read data from a file that is given as a argument?

I have a huge gzipped file and I want a program (4s-import in this case) to read it. It takes a lot of time to first unzip the file and then call the program with the path to the file as an argument. ...
17
votes
2answers
2k views

aliasing cd to pushd - is it a good idea?

Is it a good idea to use the following alias: cd() { pushd $1; } in bash? I think this would be very useful, since I can then use a series of popds instead of just a cd - once. Is there any ...
22
votes
3answers
4k views

Clone ownership and permissions from another file?

Is there a command or flag to clone the user/group ownership and permissions on a file from another file? To make the perms and ownership exactly "like" that of another file?
18
votes
4answers
2k views

Process substitution and pipe

I was wondering how to understand the following: Piping the stdout of a command into the stdin of another is a powerful technique. But, what if you need to pipe the stdout of multiple ...
14
votes
2answers
5k views

What does ${1+“$@”} mean in a shell script, and how does it differ from “$@”?

In the Perl documentation, perlrun(1) suggests launching Perl scripts using a bilingual shell/Perl header: #!/bin/sh #! -*-perl-*- eval 'exec perl -x -wS $0 ${1+"$@"}' if 0; What does ${1+"$@"} ...
12
votes
4answers
7k views

Converting relative path to absolute path

Is there a *nix command to get absolute(and canonicalized) path from relative path(with current path) or symbolic link?
18
votes
6answers
2k views

Using VI keys to edit shell commands in UNIX

I used to have a co-worker who was really good at UNIX. He showed me how to use Vi key bindings to edit my shell commands. He placed the command in a file that ran every time I logged in. Since ...
16
votes
4answers
1k views

What happens if you edit a script during execution?

I have a general question, which might be a result of misunderstanding of how processes are handled in Linux. For my purposes I am going to define a 'script' as a snippet of bash code saved to a text ...
15
votes
4answers
8k views

How to copy some, but not all files?

So, you can use the * as a wild card for all files when using cp within context of a directory. Is there a way to copy all files except x file?