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
1answer
49 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 ...
2
votes
2answers
126 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
94 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 ...
1
vote
0answers
24 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 : ...
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 ...
33
votes
4answers
28k views

How to combine 2 -name conditions in find?

I would like to search for files that would not match 2 -name conditions. I can do it like so : find /media/d/ -type f -size +50M ! -name "*deb" ! -name "*vmdk" and this will yield proper result ...
8
votes
8answers
12k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
0
votes
0answers
59 views

Understanding bash script for getting drop down option

I have this script which reads the user input for executing some command, This is working fine. User=0 Path="/root/file/" Path1="/root/domain/samples/file" echo "Please select k1 l3 l8 o5 s2 s1 ...
3
votes
3answers
832 views

Unicode text doesn't appear correctly in shell

I'm using the terminal in Kali Linux and I try to type Arabic text the characters are shown but separated (appearance not correct) This what my shell shows me ex. لا ا ل ه ا لا ا ل ل ه, which should ...
-1
votes
2answers
51 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 ...
-2
votes
2answers
62 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 ...
1
vote
1answer
35 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
29 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. ...
3
votes
2answers
67 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 ...
4
votes
1answer
845 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
5
votes
4answers
5k views

Sending the output from 'dd' to awk/sed/grep

I'm trying to approximate the computer's write speed using dd: dd if=/dev/urandom of=/dev/null bs=1K count=10000 which gives the following output 10000+0 records in 10000+0 records out 10240000 ...
1
vote
2answers
37 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
23 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)?
158
votes
3answers
10k views

Why not use “which”? What to use then?

When looking for the path to an executable or checking what would happen would you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, ...
0
votes
1answer
25 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
2answers
81 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 ...
2
votes
1answer
30 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 ...
22
votes
2answers
41k 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 ...
2
votes
2answers
88 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
votes
2answers
164 views

How to sum many numbers inside 2D array using awk

I need to sum numbers located in a file like this one: column1 column2 column3 row1 a(1,1) a(1,2) a(1,3) row2 a(2,1) a(2,2) a(2,3) row3 a(3,1) a(3,2) a(3,3) row4 a(4,1) ...
148
votes
8answers
191k 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 ...
167
votes
5answers
364k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
5
votes
3answers
995 views

How to view last 5 lines from last created/modified file?

Every day I have to take backup and update the status to support teams at particular time for which I need to check last 5 lines of last created/modified *.aff file in a directory and update them. ...
32
votes
12answers
12k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
2
votes
0answers
47 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 ...
107
votes
7answers
69k views

Allow setuid on shell scripts

The setuid permission bit tells Linux to run a program with the effective user id of the owner instead of the executor: > cat setuid-test.c #include <stdio.h> #include <unistd.h> int ...
5
votes
2answers
11k views
2
votes
2answers
70 views

Is there a way to route all commands through a shell script instead of running directly?

Sorry about the title, I can't explain it very well without an example. I want to be able to have everything being executed, rather than running the program, runs a shell script with the executable as ...
1
vote
1answer
67 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
65 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 ...
23
votes
5answers
18k views

What's the easiest way to find an unused local port?

What's the easiest way to find an unused local port? Currently I'm using something similar to this: port=$RANDOM quit=0 while [ "$quit" -ne 1 ]; do netstat -a | grep $port >> /dev/null if ...
12
votes
8answers
11k views

How to rsync files between two remotes?

I would like to transfer files between two remote hosts using on local shell, but it seems rsync doesn't support synchronisation if two remotes are specified as follow: $ rsync -vuar host1:/var/www ...
1
vote
1answer
44 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)}'` ...
0
votes
1answer
63 views

Weird user in shell

I use iTerm on OS X 10.10 When I start iTerm I get the weird user unknownA988274AC:~ myUserName$: That was not there before. Before there was myUserName$: Any ideas where that comes from?!
1
vote
1answer
26 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 ...
19
votes
4answers
10k views

Four tasks in parallel… how do I do that?

I have a bunch of PNG images on a directory. I have an application called pngout that I run to compress these images. This application is called by a script I did. The problem is that this script does ...
0
votes
2answers
48 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 ...
4
votes
3answers
3k views

How to match * with hidden files inside a directory

How to match the hidden files inside the given directories for example If I give the below command it's not giving the result of the hidden files, du -b maybehere*/* how to achieve this ...
0
votes
2answers
116 views

How do I print 'block' letters in the terminal?

How do I echo/print block lettering in the terminal like: ? figlet and toilet don't help. Neither do U+25A0 or U+2588 unicode characters. This is not a duplicate. As I said, figlet, banner and ...
52
votes
10answers
4k views

Use of touch and vi?

Is there a benefit of creating a file with touch prior to edit.. like: touch foo vi foo versus getting it to editor straight-away? Like: vi foo I see quite a few tutorials using the former (...
4
votes
4answers
44 views

Running multiple programs in the background and checking their return value

suppose I want to run a few (say, three) programs at once, like this program1 & program2 & program3 & if I want to know their pid's, I think the best way is to store them, like this ...
89
votes
31answers
27k views

Quick directory navigation in the terminal

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd /[full-path]/...
1
vote
2answers
65 views

How to make sure that a child process of a supervisor job dies when I kill supervisor

My app is a jar file that requires some environment variables. I have all the environment variables in one file, which looks like this: export VAR=value export VAR2=value2 #....etc My supervisor ...
1
vote
1answer
37 views

cd to previous directories [duplicate]

I'm running CentOS 7, but hoping there is a general Linux way of doing this. So you can cd back and forth between the previous and current directory with this: cd - Is there I way can cd back ...
1
vote
1answer
69 views

Bash Function Parameters - Spaces in Filename [duplicate]

I know there are rules for quoting parameters, but no matter what I try, I can't seem to figure out how to make this work. I have a function that takes a single filename as a parameter, then uses ...