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)

0
votes
2answers
41 views

cat doesn't join my files when I run inside script

I'm doing a restore backups script, and when I try to join files which are splitted, cat prints that error: cat: fullbackup_mrbsNuevo_15_6_2016.tar.gz.*: No such file or directory The line that ...
1
vote
1answer
422 views

Edit the editor in bash and other shells

Executing the fc builtin causes bash and other shells to fire up $FCEDIT on the last command. Because FCEDIT is a variable, this is inherently customizable. Is it possible to also customize the ...
1
vote
1answer
457 views

How to sed -i '`[echo $var]`i word' file?

Code: pos=2; printf "Masi \nwas \nhere" > /tmp/1 sed -i '`echo $pos`i huhu' /tmp/1 Expected output: Masi huhu was here Current output: sed: -e expression #1, char 1: unknown command: ``'
-1
votes
1answer
51 views

using shell script to posting Json body to curl by loop

Hi I have many Json file which need to be post to curl. so can some one help me how to write loop for the same? am trying this way for FILES in $~/network_map_ingestion/networkmap/data/consolidation ...
-1
votes
1answer
53 views

How can I pass the file names to xargs and truncate them? [closed]

I have to write a script which will ssh into servers and truncate log files My script is #!/bin/bash for server in $(cat c10_servers.txt) do ssh $server " ls /var/log/hello grep -i hello.log. |...
10
votes
1answer
290 views

How does ksh93 avoid forks in command substitution

Given cmd='fun(){ echo "$@"; }; fun $(fun $(fun hi))' shells tend to need to make 2 forks to make it happen strace-f(){ strace -f "$@" 2>&1; }; for sh in dash bash zsh ksh; do ...
3
votes
1answer
38 views

Capture output (sdout/stderr) of SSH port forwarder

I would like to store the error below in a variable: ssh -M -S /invalid/path/forwarder.socket -fnNT -Llocalhost:6301:remote_server:22 proxy_server muxserver_listen bind(): No such file or directory ...
1
vote
1answer
59 views

How do I find and list folders with a specific folder name, containing files modified recently?

I have a set of folders that are regularly updated, which I would like to regularly parse through and update to a simple text file list. This list gets used with rsync so I shorten the file names ...
1
vote
1answer
48 views

Shell - PTS/0 Suddenly Changed to PTS/1 Why did it happen and how to change it back?

Whenever I enter the who command in the SSH I see the PTS/1 after my username. Two days ago it was still PTS/0. Is this called the TTY? How do I make it PTS/0 again? Also the path now is /dev/pts/1 ...
0
votes
1answer
32 views

System messages in vim

O/S: Arch Linux (Kernel 4.3.3-2-ARCH) While editing files with VIM 7.4 it occassionally happens that system messages appear on the screen, ruining my workflow but obviously not altering the ...
2
votes
1answer
164 views

specify shell for ssh session

I am logging to a remote server via ssh as user www-data. User www-data on the server has his default shell set to /bin/sh, and when I log in, I get dash as my shell. I can then type bash and get bash ...
1
vote
2answers
65 views

Wait until a process comes back from sleep

script.sh is run by run.sh N times in parallel. For N=1, the script.sh process is set to sleep 30-45 seconds before it actually starts. How can I order ALL script.sh instances for N>1 not to start ...
12
votes
1answer
263 views

Setting temporary bash aliases when entering a folder

Sometimes I like to have very customized bash aliases and maybe keybindings when I enter on a folder (can be a project where I'm used to type lots of commands from CLI). Lets suppose when I enter a ...
0
votes
1answer
51 views

Difference between set variable “value” and set variable value?

What is the difference between the following 2 examples in a shell script: set variable1 "value" set variable2 value
1
vote
2answers
89 views

Copy files that are created today without FIND command and SFTP to another server

I have a directory with 'n' number of files in it. I am trying to write a shell script which will list only the files created on the particular day the script is running, and will use sftp to move the ...
0
votes
1answer
40 views

find: missing argument to '-exec'

this is my first post, as I am completely new to the programming world. Basically I'm taking a UNIX class and I have an assignment asking me to check the size of regular files in my home directory for ...
5
votes
1answer
678 views

When files are being moved are they stored in a memory?

When I move a file using the mv command, is this file first read, fully cached into a memory and then saved as another file? Or is it the same as writing while read line; do echo "$line" >>...
0
votes
1answer
72 views

Curl a string with whitespaces and characters in it? [duplicate]

I'm trying to create a "simple" script that I'm going to use to create some documentation for Unix/Mac machines. I've successfully received the information I need, but it seems like I can't send it ...
5
votes
2answers
374 views

nested double quotes in highly-voted one-liner

A StackOverflow answer with > 3.5K votes features this one-liner for assigning to DIR the directory of the current bash script: DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" I'm ...
0
votes
0answers
44 views

tailing file in new terminal window

I have the following two bash scripts (perhaps they can be condensed into one). // pre-tail.sh #!/usr/bin/env bash open -b com.apple.terminal `dirname $0`/tail.sh // tail.sh #!/usr/bin/env bash ...
4
votes
2answers
42 views

Is it possible to print an iterated range of arguments via cli from a csv? (see example)

I have hundreds of logs spread across a few thousand VM's and I'm trying to create a few scripts to quickly scan logs and I have figured out the majority of the presentation and wanted to know if ...
-2
votes
1answer
45 views

Write shell script for logging in servers and run command after logging in

I have wrote a shell script for logging into servers and run few commands to start and stop processes running on it, So I tried below code, but it is showing error, please help me with the script. ...
2
votes
4answers
250 views

How to match “4.4” from `uname -r`?

Pseudocode [ `uname -r` =~ ^4\.4.*$ ] && echo "yes" which is, however, unsuccessful in all cases. The uname -r command gives things like 4.6.0-040600-generic as an output.
0
votes
1answer
49 views

What's the usage of rbash?

I've read some questions about the difference of TTY, console, terminal, etc here and on Askubuntu. Someone mentioned restricted shell, like rbash or bash -r. I first fought it is good to give ...
-3
votes
2answers
45 views

Apache log sorting most visited ip [closed]

cat access.log | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | sort -n | uniq -c | sort -n I don't understand this statement. Somebody please explain.
0
votes
1answer
45 views

help to analyse a log file

How does sed 's/\[//' work in case of analyzing log files for the time stamp fields? I found a solution online and I saw this line "$(head-1 "$1" | awk '{print $4}'| sed 's/\[//')". Can someone ...
1
vote
1answer
61 views

pass arguments to python program in shell

I am unable to run python script within a shell script. Following is the script.sh file where 3 arguments are being passed to the python script. python main.py 1.0 0.1 10 The python program is not ...
1
vote
0answers
25 views

Read a log file to extract various fields and count the occurance [closed]

I have a logger file like this: 2016-06-11 07:34:01.542 98459 [Thread-23-Job-parser-bolt] INFO JobLoader c.t.commerce.common.utils.APIUtils - Enrichment data updated successful for partnumber : ...
2
votes
2answers
132 views

Multiplying numbers in-place in a file

I have ASCII file contain numbers as follow: 1 2 3 5 6 9 7 8 9 . . . . . . . . . . . . . . . etc I want to upgrade this file by multiplying each value by "3" to get : 3 6 9 15 18 27 21 24 27 ...
1
vote
2answers
102 views

What exactly is terminal? What is shell? [duplicate]

I know about Linux terminal. I can also issue many advanced commands over terminal. But one simple concept is not clear to me. What is terminal and how does it work? I know about hardware which ...
0
votes
1answer
34 views

Read file upon .bashrc startup, based on date

I'd like to put a script in my startup that reads a line from a text file, and echoes this to the screen. However, I'd like a different line from the file based on what day of the month it is. Thus ...
-2
votes
2answers
66 views

Find all line in a file which start with g or any digit from 0to9

How do I find all lines in a file which start with g or any digit from 0 to 9? Can any one help me using command line? I try and I know how to do if start with g but don't know how to do with g and 0 ...
0
votes
5answers
110 views

how to iterate through files in directory excluding hidden files

Using: for eachfile in /mnt/thara/* Which iterates through hidden files as well. I don't need hidden files.
3
votes
2answers
73 views

obtain shell prompt in python

I want to obtain the (zsh) shell prompt in a python script. Simply using import os prompt = os.environ['PS1'] seems not to be the right way, because PS1 is usually not forwarded to subprocesses. In ...
1
vote
2answers
39 views

Shell shows I have mail, but how can I check it

When I startup the shell, it displays the message You have mail. and this is because I touched a file /var/mail/${USER} and wrote to it. But how can I check it? I use mail, but it shows me No mail ...
0
votes
1answer
26 views

Continue monitor web server and download newly added files

What are the best way to continuously monitor a web server (HTTP) and download newly added file with min. delay (ideally < 1min. delay)?
-1
votes
2answers
53 views

exit code from a builtin shell command [closed]

I'm writing a custom shell and I want to run a shell script with my own shell. I'm trying to check if the less program is installed and if it is, use the less program otherwise use more. However, my ...
0
votes
1answer
27 views

User Input Shell Script Syntax Error

I'm new to shell scripts and all, and wanted to write a script that would automatically perform this command for me: sudo aireplay-ng -0 (given number) -a (Router MAC Address) -c (Target MAC address) ...
1
vote
1answer
36 views

How to batch rename files by exchanging substrings in the filenames?

I have files like ABC_asd_f.txt, DEF_qwe_r.txt, ... How can I exchange the uppercases before the first underscore with the lowercases after? So ABC_asd_f.txt becomes asd_f_ABC.txt, DEF_qwe_r.txt ...
1
vote
1answer
37 views

.shinit vs. .shrc

When logging in to a Linux/Unix system via the old Bourne shell (sh), we have the .profile file to customize our environment for us. Some sources also reference either a .shinit file or a .shrc file. ...
1
vote
2answers
83 views

After small code change 'awk' prints header and blank lines, (not header repeated)

data-file content: k = 0.1667 0.0962 0.0000 ( 4922 PWs) bands (ev): -7.1689 -7.1043 -6.1682 -6.0658 1.1309 1.5196 3.0894 3.1087 3.3846 3.7588 4.2143 4.2220 4.3882 ...
0
votes
0answers
89 views

How to write Shell Script for Mongo Find query.?

i am new to Shell Scripting, Actually i am writing a shell Script for mongo to find specific document, this Shell Script Except a Argument and use in Find Query, So i had write a simple find query: ...
2
votes
1answer
34 views

Cannot stop bash to expand star (wildcard character) passed to app from shellscript

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the ...
2
votes
0answers
49 views

Network traffic monitor “nettop” morphing away from expected results

On Mac, I open a new shell and enter nettop. For a split second I see chrome (as I expected) and some other things going on (had to record screen to catch them); then I'm only shown data on ...
1
vote
1answer
78 views

Convert vertical array data to horizontal array data

I have a file with 25 matrices in a file, and each matrix is has 128 rows and 5 columns. Each matrix are putted one after the other, in a vertical way. Like this File input(file1): Array1 Array2 ...
2
votes
2answers
67 views

What is the best way to unlink hard-linked files?

Using rdfind I found a lot of hard-linked files (~60-90) and I want to unlink all of them. One possible solution is to just find all files -link +1 and just copy them, delete them and move it back to ...
2
votes
2answers
92 views

Use env with environment variables from file

Let's say I have a file (called e) with this content: a=3 b="5 6" How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to: $ env a=3 b="5 6" ...
1
vote
1answer
50 views

Spawn command not found

I trying to use the spawn command to connect to remote server, execute some commands/script. Here is script: #!/usr/bin/expect for i in `srvctl status database -d PROD | awk -F " " '{print $(NF)}'` ...
1
vote
1answer
27 views

Group or world writable directory

I'm trying to use a script but get the following error: Directory is group or world writeable. This is insecure, since any malicious user can trick you to write newly generated private key into his ...
0
votes
2answers
54 views

How to fetch all the even lines and odd lines from a file and save them into two different files such as Evenfile & Oddfile? [duplicate]

The question is very simple. Suppose I've a file named "a.txt" and it has 100 lines. Now I want to extract odd lines i.e lines 1,3,5...etc and save them to a different file such as Odd.txt and the ...