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
10 views

What command(s) will feed a tab-delimited text file and cut each line to 80 characters?

I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the ...
11
votes
5answers
1k views

Shell: “Display all 2588 possibilities?”

So, I was moving my laptop around (and I have the bad habit of setting things on the keyboard...) and I woke up to discover this: $ Display all 2588 possibilities? (y or n) What command would ...
2
votes
3answers
10k views

Executing a shell command from PHP with shell_exec

Included in my thesis is to create an administration interface, in which an administrator can approve users whom have asked for access to use OpenNebula. Upon approval the users should be added to ...
1
vote
1answer
8 views

Get chronological list of dates & times an entry will run from crontab

Given a job specification in crontab, is there any way to get the list of dates and times the job in cron will run in the next week? For example, given a string 10 13 * * *, is there any way to get ...
1
vote
1answer
46 views

Why string comparision results always false

I am trying to do a one time check about apache's mod-status page for updates like this(this is just a test script): firstcontent=$(lynx -dump http://some-server/server-status-page) echo ...
2
votes
2answers
26 views

Bash globs as non-file arguments. Example: apt-get remove pkg-*

I know * and other glob patterns are transformed into words by pathname expansion, based on the current working directory. Hovever, some commands seem to use them for non file arguments. For example, ...
1
vote
1answer
10 views

Pipelines, Jobs and Processes in Zsh

I went through the Jobs & Signals documentation in Zsh, but some things aren't still clear to me. It says: If the MONITOR option is set, an interactive shell associates a job with each ...
0
votes
2answers
30 views

Bash Script Parsing Argument not working correctly

i have the following bash script (taken from FFmpeg) #!/bin/bash ################################################################################ # # Script name: MultiMedia Concat Script (mmcat) # ...
2
votes
1answer
56 views

Problematic bc calculation in shell script

On Ubuntu 14.04.1 64-bit LTS I am writing a shell script and if I define the start of the sequence used in the for loop with a variable instead of a constant I get really weird behavior and there are ...
1
vote
2answers
36 views

Creating a list of files, removing “duplicates” with different suffix

I have a problem that (I think) require a bit of script-magic - not sure what would be best though... I have one directory with lots pictures in different formats - jpg, gif, png, tiff and svg. Some ...
2
votes
6answers
253 views

Print first and last line of all files in folder

I have a bunch of log files that get overwritten (file.log.1, file.log.2 etc). When I copy them from the device making them onto my local machine I lose the original time stamps. So I'd like to put ...
2
votes
2answers
44 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
24
votes
3answers
476 views

Switch to parent shell without logging out

Let's say I start in my local account: avindra@host:~> then I switch to root: host:~ # Then I switch to oracle: [ oracle@host:~] Is there a way for me to drop back into the root shell (the ...
0
votes
1answer
18 views

if statment on installed script in sbin failing

I have a simple block of code that seems to fail and I'm not 100% sure why, if ! -h /usr/sbin/gitploy; then curl https://raw.githubusercontent.com/jeremyBass/gitploy/master/gitploy | sudo sh -s ...
-4
votes
1answer
33 views

What is “jobs” commmand in Redhat Linux [on hold]

What is jobs command in Linux and how to use it? Please give some example.
1
vote
1answer
33 views

Equivalent command for ``time`` for memory usage?

by using time we can easily get the information about how long a program run, I was wondering if there is any equivalent command I can use for memory usages? Like how many memory are allocated for ...
19
votes
4answers
17k views

Usage of dash (-) in place of a filename

For a command, if using - as an argument in place of a file name will mean STDIN or STDOUT. But in this example, it creates a file with the name -: echo hello > - How can I make - in this ...
5
votes
4answers
314 views

Remove next-to-last extension in a file name

Suppose a folder with many files with bad extensions,for example Song1.avi.mp3 Song2.avi.mp3 Song32.web.mp3 Song23.mp4.mp3 Song2a.mp9.mp3 I want to remove only the second field (web, avi, mp4). I ...
1
vote
3answers
55 views

looping a command without waiting for the first run

I want a better way to do this, mostly for command line use: while sleep 60; do mysql -e 'show processlist'; done This is better than: while mysql -e 'show processlist'; do sleep 60; done ...
1
vote
2answers
63 views

Is there a reason to quote the exit status $? variable?

I was looking at Google's style guides for their bash scripts, and saw that they quote the exit status variable $? here. if [[ "$?" -ne 0 ]]; then error_message fi I thought return values are ...
1
vote
2answers
59 views

How does bash's arithmetic work?

read num1 2 read num2 5 echo "$((num1+num2))" 7 echo "$(($num1+$num2))" 7 I referred this. I don't understand how the above both expressions yields same result? Please explain. echo ...
1
vote
1answer
1k views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
-1
votes
2answers
18 views

How to compare strings in Bash script [on hold]

I have one strings like "9999991385" now I want to match first 4 digits from one file if it's match or not ??
4
votes
1answer
72 views

How is ksh93 so fast?

So, in general, I tend to look to sed for text processing - especially for large files - and usually avoid doing those sorts of things in the shell itself. I think, though, that may change. I was ...
0
votes
1answer
21 views

Why doesn't this tee with process substitution produce the 1st and chosen lines? [duplicate]

What I want is printing the output the first line ( table head ) of ps aux and the grep result. After search, I come up with following. ps aux | tee >(head -1 > /dev/tty) | grep mongo But I ...
37
votes
5answers
20k views

How can I send stdout to multiple commands?

There are some commands which filter or act on input, and then pass it along as output, I think usually to stdout - but some commands will just take the stdin and do whatever they do with it, and ...
2
votes
1answer
21 views

Check which RPMs depend on this package

I want to get a list of packages which depend on requested package. For example, I want to get all packages, which depend on telnet. I came up with this script: for i in `rpm -qa | sort`; do rpm ...
0
votes
0answers
32 views

Parameter passed to Shell script is not getting populated under printf command [on hold]

I am calling a script and building html table out of it. The val1 which i am passing is being captured in variable cluster. But its not getting printed in output. sh script.sh val1 > out.htm ...
-3
votes
2answers
14k views

“install: missing destination file operand after `rootterminal'”

When I open root terminal then it simply starts a normal terminal. I cannot access root terminal. When I update my root terminal by the following command sudo apt-get update && install ...
2
votes
1answer
27 views

apt-get update exit status

How check the status of apt-get update? $ apt-get update ; echo "status is: $?" Err http://security.debian.org stable/updates Release.gpg Could not resolve 'security.debian.org' Hit ...
6
votes
3answers
1k views

Equivalent of date --reference in Solaris

The GNU implementation of the date command has a nice feature to show the date of the last modification of a reference file. Then using the +FORMAT parameter it's easy to get the date in any format, ...
1
vote
1answer
32 views

why does grep '\;.' expand to grep '\''\;.'\''' when executed over ssh?

$cat test.sh ssh HOST -l root -o StrictHostKeyChecking=no -q "/bin/bash -l -c /bin/env | grep -w PATH | grep '\;.'" $bash -x test.sh + ssh HOST -l root -o StrictHostKeyChecking=no -q '/bin/bash -l -c ...
1
vote
1answer
41 views

Preventing user from accessing parent folders [duplicate]

I have a user who I only want to be able to access /var/www/ucp/ (his home directory). I have executed the following command on the / directory, the /var/ directory and the /var/www/ directory: chmod ...
1
vote
2answers
136 views

How to change dir to the last directory?

I have very long directories list, like /dir/dir/dir/../../../../../../../../../.. ../../ ../../last dir Is it possible to change to the last dir immediately?
1
vote
0answers
33 views

pkill -P $ID working while kill — -$ID not

I was playing around with creating and killing process groups on linux ( ubuntu ) I am trying to kill a process group and am being driven crazy by the fact that pkill -P $ID works while kill -- -$ID ...
3
votes
2answers
72 views

Am I hitting a race condition in bash?

I have a script which compares the output of a command with the output of the same command as it was ran previously, it works most of the time, but every now and then it doesn't work as expected. ...
0
votes
1answer
38 views

Debugging with shell programming and cpp files?

I am having trouble understanding how my code is working. I am new to this project and never learned unix before. My coworker quickly showed me how to run the program but didn't explain how it worked ...
53
votes
14answers
50k views

How can I get distribution name and version number in a simple shell script?

I'm working on a simple bash script that should be able to run on Ubuntu and CentOS distributions (support for Debian and Fedora/RHEL would be a plus) and I need to know the name and version of the ...
8
votes
2answers
138 views

How can I conditionally pass a subshell through 'time'?

I have a setup script for a Vagrant box where I used to measure single steps with time. Now I would like to conditionally enable or disable the time measurements. For example, previously a line would ...
5
votes
5answers
10k views

Disable user shell for security reasons

We have several user accounts that we create for automated tasks that require fine-grained permissions, such as file transfer across systems, monitoring, etc. How do we lock down these user accounts ...
2
votes
2answers
55 views

Shell Script - number of minutes

Shell How can I write a shell script, using only shell features (and the date command), to output the number of minutes that have elapsed in the current day?
5
votes
6answers
4k views

How to append data of multiple files into single file?

For example: I have 01.txt and 02.txt files and need to append data of these files into new file new.txt. It should append data based on 01.txt followed by 02.txt files. Before this I have to delete ...
0
votes
1answer
25 views

How do I suppress all email notification from cron for particular job?

I am scheduling the following shell script #!/bin/bash (echo open mailserver.nowhere.local 25; sleep 1; echo EHLO; echo quit)\ | telnet | grep "?Invalid command" if [ $? -eq 1 ]; then ...
0
votes
0answers
10 views

pdf2swf give result blank swf [closed]

I need to convert pdf file into swf Command I've tried: $PDF2SWFcommand = "pdf2swf /pdf/file/unsecured.pdf -o /swf/file/output%.swf -f -T 9 -t -s storeallcharacters > /dev/null 2>&1 & ...
1
vote
2answers
24 views

Count and list down + advanced features

I have a few questions: I have listed the number of lines in the files in /group/book/four/word, sorted by the number of lines they contain using $ wc -l /group/book/four/word/*|sort -n ...and ...
0
votes
1answer
972 views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
-2
votes
4answers
44 views

How to ignore the lines starts with # using grep / awk

cat /etc/oratab #test1:/opt/oracle/app/oracle/product/11.2.0.4:N +ASM2:/grid/oracle/app/oracle/product/11.2.0.4:N # line added by Agent test2:/opt/oracle/app/oracle/product/11.2.0.4:N ...
0
votes
1answer
44 views

Create A Script That Responds To A Password Prompt

I'm writing a shell script that will respond to a prompt. For example, when I execute a file, the executed file will then prompt the user with this: Please enter the password: Then I want the script ...
6
votes
3answers
190 views

sed with multiple expression for in-place arguement

I am trying to replace multiple words in file by using sed -i #expression1 #expression2 file Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 Output (Desired) ...
1
vote
4answers
102 views

Killing a shell script running in background

I have written a shell script to monitor a directory using the inotifywait utility of inotifyt-tools. I want that script to run continuously in the background, but I also want to be able to stop it ...