The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
2answers
64 views

Help me please to find my misunderstanding about this little piece of shell script

Actually, I have a folder which contains several sub folders with lots of images in each. I am trying to gather all the names of the files in each sub folder in a text file (filesNames.txt) in that ...
0
votes
2answers
30 views

Switch case not working in Shell

I am new to shell and am intending to use gdialog to to take user input and feed it to switch case in shell. Below is my code: #!/bin/sh which gdialog 2> /dev/null && DIALOG=gdialog || ...
15
votes
4answers
7k views

How to set window size and location of an application on screen via command line?

I want Firefox window to be opened in a specific size, and location on screen using a shell command, for example: firefox myfile.html size 800x600 location bottom-left Is there such a command?
1
vote
2answers
448 views

How to automate ktutil to immediately list keytab entries?

I use MIT ktutil a lot on Linux and I am fed up using the following sequence, even if command shortcuts and file name completion are here to help: ktutil rkt my.keytab l Isn't there a way to get ...
23
votes
7answers
59k views

How to read first and last line from cat output?

I have text file. Task - get first and last line from file after $ cat file | grep -E "1|2|3|4" | commandtoprint $ cat file 1 2 3 4 5 Need this without cat output (only 1 and 5). ~$ cat file | ...
0
votes
1answer
108 views

How to spawn new processes for new instances of the same shell script?

I'm trying to lock a file using the command lock. Its syntax is ./lock </path/to/file/name> I need to lock a bunch of files in a given directory and in order to achieve this I'm using two ...
25
votes
4answers
16k views

Why isn't there any shell command to create files?

Attention please: I am not asking how to make a file from the command line! I have been using touch for making files for years without paying attention that its main purpose is something else. If ...
2
votes
5answers
3k views

Why does the command shuf file > file leave an empty file, but similar commands do not?

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
0answers
23 views

awk used for duplicate is failing while recreating same file [duplicate]

When i am running command below its just vanishing the complete data from the appirx.txt. Can any one explain the mechanism behind it.It might be basic question awk '!seen[$0]++' appirx.txt > ...
2
votes
1answer
47 views

How variables inside braces are evaluated

I'm new to shell scripting and I came across these expressions ${var:-val} and ${var-val} ${var:+val} and ${var+val} ${var:=val} and ${var=val} so how are they evaluated and what are the ...
83
votes
3answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
2
votes
2answers
272 views

Tar a list of files which don't all exist

I'm running a command from a script like tar -c -f ar.tar a b c d where b, c, and d may not exist, and may be directories. The solutions that I've come up with are piping the output of ls -d to ...
1
vote
0answers
11 views

find-like tool to search (recursively) in MailDir folders by size, sender, recipient, attachment name regex, etc

I am not looking for a tool like locate, that works by creating an index in the MailDir, or generating other runtime files there; I am searching for real-time, direct search on live MailDirs. The ...
1
vote
2answers
45 views

Use variables in here-string

To feed input to an interactive script, I've been using a here-string: script <<< $'1 2\n3 4\n5 6\nq' This effectively enters 1 2 3 4 5 6 q into the script. But how can I replace one of ...
2
votes
4answers
45 views

Access a file located with find

In many cases after I find a file using the find command I then want to open the file or cat it or maybe print it. How can I operate on the result from find? For example, : find . -name "myfile.txt" ...
2
votes
1answer
51 views

on-line tally of unique lines

uniq -c is very useful for counting the number of times the same line appears consecutively $ seq 1 1000 | awk '{ if ($1 > 100 && $1 <= 200) { print "hi" } else {print "bye"} }' | uniq ...
1
vote
1answer
32 views

Move files several directories up for several directories with similar layout

I have a directory with the following layout (the layout in Directory 1 is repeated in every other Directory <num>): Parent directory Directory 1 some directory another ...
6
votes
4answers
267 views

Run command in bash after a certain length of time has elapsed?

If I'm executing a long process, is there any way I can execute some time-based commands? For example, I'm running a really long process which runs for roughly 10 minutes. After 5 minutes, I would ...
0
votes
1answer
36 views

Shell prompt displays .f>

I am running SSH through this command: ssh <machine-name> But instead of seeing the machine name in the prompt, I see .f>. Normally the prompt looks something like machinename> Any ...
1
vote
3answers
32 views

how to spawn a separate process in the background while running a foreground process

e.g., I want run a python -m HTTPSimpleServer in the background while running a watch in the background python -m HTTPSimpleServer; watch -n (my awesome test command) how can I run both in ...
2
votes
1answer
37 views

Get DISPLAY value by username

I run following commands to get DISPLAY value for a logged in user. $ loginctl list-sessions SESSION UID USER SEAT c2 1000 asif seat0 ...
3
votes
1answer
16 views

Start new process group in .xinitrc

I have a statusbar (lemonbar) to which I pipe the output of a couple of scripts (time, battery, volume, etc.). These scripts, and the statusbar itself, are all started in a single bash script ...
3
votes
1answer
42 views

Shell syntax for redirecting arguments?

If I want to redirect not the stdio but as arguments the output of a program , should I use xargs? For example, I do ls and I want the filenames to be arguments to the next command rather than an ...
2
votes
1answer
80 views

what is the difference between “./command” and “bash command”

I have simple bash script file, it contains only one line: rvm gemset use --create 2.0.0@PRJ_NAME If I run this script with: ./scriptname.sh I get a well-known error message from RVM RVM is not ...
1
vote
1answer
866 views

what's wrong with embedding php scripts inside bash ones?

I was trying to use php inside bash script, but I came across several problems. My first try failed with error about bash not being able to find end of here-document. The minimal version that still ...
142
votes
8answers
184k views

How to split the terminal into more than one “view”?

From vi, if you issue the command :sp, the screen splits into two "views", allowing you to edit more than one file from the same terminal. Along those same lines, is there a way to have multiple ...
0
votes
1answer
46 views

How to merge or join more than 2 files? [duplicate]

I have four files; file1: gene_id FPKM TRINITY_DN56960_c4_g1 36.91 TRINITY_DN42427_c0_g1 12.83 TRINITY_DN48728_c0_g1 6.22 TRINITY_DN50706_c0_g2 6604.75 TRINITY_DN51449_c1_g1 8.19 ...
0
votes
1answer
1k views

openSuse, not running the cron job

I have created a cron job in the /etc/cron.d/dispatchingEmail_I the permissions of dispatchingEmail_I are the following: -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I content of ...
1
vote
2answers
17 views

Get owner / user of a cronjob

In Linux (Mint / Ubuntu), I can create cronjobs for each user individually. Is there any way, I can find out the name of the user against whome the cronjob is running. I want to get the username of ...
17
votes
4answers
9k views

bulk rename (or correctly display) files with special characters

I have a bunch of directories and subdirectories that contain files with special characters, like this file: robbie@phil:~$ ls test�sktest.txt test?sktest.txt Find reveals an escape sequence: ...
3
votes
1answer
9k views

Linux: set command for local variables

I am trying to understand local/environment variables and export/set commands. $ set FILEM="razrax" $ echo $FILEM $ FILEN="test" $ echo $FILEN test Please explain why echo $FILEM returns empty ...
4
votes
2answers
847 views

What are the new features available to bash 4?

I was using bash3 up to now, and just got a copy of the latest version $ ./bash --version GNU bash, version 4.1.0(1)-release (i686-pc-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. ...
1
vote
2answers
40 views

A quicker way to change owner/group recursively? [duplicate]

Currently, when I want to change owner/group recursively, I do this: find . -type f -exec chown <owner>.<group> {} \; find . -type d -exec chown <owner>.<group> {} \; But ...
-1
votes
0answers
35 views

How to write the shell script which check if the file is present on the cluster file system?

Suppose we have pscp on Windows, and remote control to Linux cluster through key key.ppk, the user and host is name@cluster.com. How, by using shell script (in cmd file), check if some file is present ...
3
votes
3answers
885 views

How to open process substituted file from php?

Here's what I tried to do myself: $ type 1.sh #!/bin/bash -eu php -r 'var_dump(file_get_contents($_SERVER["argv"][1]));' -- <(echo 1) $ ./1.sh PHP Warning: file_get_contents(/dev/fd/63): failed ...
7
votes
4answers
16k views

Rename files in the local folder adding a prefix or suffix

I have many files in a folder and I want to add either prefix or a suffix (not both) to them. I checked here and found out I can use for filename in *.jpg; do mv "$filename" "prefix_$filename"; done; ...
3
votes
0answers
54 views

Exploit in bash script parameter possible?

I want to pass an e-mail address from a web form to a bash script. I'm using the following regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/ Is this sufficient? Or could one embed an ...
92
votes
3answers
54k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
0
votes
2answers
40 views

Shell Script to insert lines in between file

Suppose there is one file1.txt where content is written Ramesh Suresh Raman From the below shell script ,I am reading the content name from file1 .txt and preparing the Name=$line in echo ...
3
votes
4answers
118 views

Where should I save color codes for the PS1 command line / terminal? [closed]

This question is about best practices. I know logging in over secure shell or switching users su, and su -l have different effects. Also, in the event you make a typo in the configuration, you still ...
0
votes
0answers
38 views

Send command to open process in Shell file

In bash how can I issue a command to a running process I just started? For example; # Start Bluez gatttool then Connect to bluetooth device gatttool -b $MAC -I connect # send 'connect' to the ...
4
votes
4answers
50 views

Does \ work for escaping functions?

I have a function defined in my .bashrc that I would like to bypass: function func() { // func } export -f func When I run env -i func I can access the func command without the function in the ...
3
votes
1answer
25 views

.ksh session hangs after being inactive

While remotely connecting to a Linux machine using ssh, my .ksh session hangs after being inactive for sometime. If I try to type or ctrl-z, the prompt does not respond. Is there a way to restore my ...
69
votes
4answers
120k views

How to suspend and bring a background process to foreground

I have a process originally running in the foreground. I suspended by Ctrl+Z, and then resume its running in the background by bg <jobid>. I wonder how to suspend a process running in the ...
3
votes
3answers
294 views

Sourcing a shell script from within Emacs

I would like to source a shell script that changes my environment variables from within Emacs. That is, I would like the shell script to change the environment in which Emacs runs, and I would like to ...
5
votes
3answers
12k views

Cant ssh, connection terminates immediately with exit status 254

The most recent thing I remember is changing the soft and hard memlock ulimit to unlimited. Now I cant ssh into the machine. This is the ssh log. Authenticated to IP ([IP]:22). debug1: channel 0: ...
15
votes
5answers
14k views

How to recover a shell after a disconnection

Am doing some work on a remote CentOS 5.6 machine and my network keeps dropping. Is there a way that I can recover my hung sessions after I reconnect? EDIT: am doing some updating and installing with ...
10
votes
3answers
780 views

How does a shell execute a program?

If I compile a program using gcc, and try to execute it from the bash shell, what is the exact sequence of steps followed by bash to execute it ? I know fork(), execve(), loader, dynamic linker (and ...
1
vote
3answers
64 views

Where are shell variables stored?

For example, if I make a parameter expansion: $ b=1 $ echo $b 1 Where is b stored internally? I checked and it is not an environment variable because it is not listed by printenv. I'm writing my ...
1
vote
1answer
40 views

Shell Font Over SSH

I have a Linux machine (CentOS 7) in which I frequently SSH into from multiple devices. I have installed ZSH and Oh-my-zsh on the remote machine. I would like to install the following theme: ...