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)

3
votes
1answer
37 views

Combining every two column values in file

I have a file with (with only one line) with multiple columns say 4 (in this case) : A B C D And I want the output as every possible combination of column values taking 2 at a time like: AB AC AD ...
1
vote
1answer
28 views

Remove certain types of files except in a folder

I have a command in my makefile for clean: rm -rf */*.o */*.cmo */*.cmi */*.cmx */*.cma */*.cmxa */*.annot Now I would like to write a cleanpartial that removes these files except those in the ...
3
votes
2answers
77 views

execute command from find called by find

Is there a way to call find recursively? I would like to search for files matching a given pattern only in directories matching another pattern. Basically: for each (sub)directory D matching ...
1
vote
2answers
46 views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
1
vote
0answers
22 views

Passing external parameter to .exe on Windows using winexe from Linux

I am trying to execute a .exe on Windows from Linux using winexe. This exe requires an external parameter (string) to be fed alongwith. With the following command I have succeeded in initialising the ...
1
vote
1answer
35 views

code to display the text TRUE

I'm a complete newbie and I'm starting to learn the basic for shell scripts. So I apologize if this question is very simple for most users. I'm trying to display the text TRUE to the screen if a file ...
2
votes
0answers
43 views

Prevent scp and less commands reading interactive tcsh script

I'm using tsch through PuTTY, and let's start by this: please don't try to convince me to migrate to another shell...:) It's being a long time that commands like scp and less didn't work well for me. ...
0
votes
0answers
17 views

vim + tmux: some shortcuts broken?

When I am using vim inside of tmux, some of my shortcuts are broken. E.g. I have bound Ctrl + up/down and Shift + up/down in my .vimrc and when I'm running vim inside of tmux these shortcuts do not ...
3
votes
2answers
88 views

Filter files generated by `find` by parsed output of `file` command

I'm writing a quick tool to inspect the contents of a node.js node_modules folder or python virtualenv for native dependencies. As a quick first approximation to this I wrote the following command. ...
0
votes
2answers
37 views

Flow control using Unix shell

I need to do an exercise at the university, its all about reading 3 values and identify if there is any duplicated value, which value is the greatest and which one is the least, the idea is if you ...
0
votes
1answer
32 views

How to insert a string before a matched string

How can I insert a string before a matched string. Suppose I want to insert a string a before "if (PROTOCOL == "https://")" string. Please tell me how can I do this?? or How to search and replace ...
0
votes
2answers
33 views

Compare and return first instance of n characters from a list

Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n ...
0
votes
1answer
27 views

Please verify the result which i get using grep for korn shell

when i run the command ps -ef | grep ksh on my server i get the result as - /bin/ksh ./abc.ksh ./xyz.ksh where abc and xyz are my shell scripts. what does this symbolize ? Is one script calling ...
3
votes
3answers
53 views

All files in a directory that do not end in a specific string?

I want to find all text files in a directory that do not end with the string: hello world How can I do this?
1
vote
1answer
33 views

Creating if/than statement to move files to another location based on value of 1 column?

I have thousands of xyz (latitude,longitude,elevation) text files that I want to separate by latitude or longitude. How and what commands could I use to create an "if latitude(column1) is greater than ...
0
votes
0answers
25 views

Is there a way to get partition information of a disk with sysfs?

my first question here - so please, don't be too hard with me... As the title says: I am wondering if there is a way to get partition information of a disk with sysfs. I know about some different ...
0
votes
1answer
30 views

how to input a file as a variable in a shell script

I need to input the path of a file in shell script as a variable and use the file in the same script.Suppose the path is /home/pi/dest/file and i want to use the file as a variable.Can anyone tell me ...
0
votes
0answers
21 views

Emptying a log file getting updated with 2>&1 output redirection [duplicate]

I have a server which constantly writes outputs and errors to stdout and stderr. The command line I use for running my server is: Server options-list > log.txt 2>&1 & Now the problem ...
0
votes
1answer
30 views

Printing Space Between Strings

#!/bin/bash ARRAY="185.18.207.66 31.18.212.113" result="" for i in $ARRAY do result=$(printf '%s %s' "$result" "$i" "checked") done paste <(printf "%s\n" $result) I am trying to print ...
0
votes
1answer
28 views

Shell script getting 'permission denied' despite using umask 000 before command

I have a shell script (build.sh) that ends by attempting to copy some files into a new directory. However it says: mkdir: cannot create directory ...
1
vote
1answer
19 views

variable doesn't change after find & while [duplicate]

My code var=34 find $1 -type f | while read line; do file_status=`file "$line"` file_name=`echo $line | sed s/".*\/"//g` line_length=${#file_name} if [ $line_length ...
1
vote
2answers
85 views

Escaping in bash

Given a text message, I need to programmatically generate a bash command to open terminal emulator and show this text in it. For example, for HelloWorld input string I need to return the following ...
0
votes
0answers
26 views

How to convert the timestamp to readable date format [duplicate]

$timestamp="160402074632" Dates=$timestamp +"%Y-%M-%D" I want this to be converted to a readable date format like “Thu Dec 9 12:50:32 CET” and store it in Dates variable if i give echo $Dates , i am ...
8
votes
2answers
404 views

Wait for stdout stream to finish and then add its contents to a file

I am trying to run a command in bash where I have a command 1 which accepts a large amount content through stdin and then outputs that content to a file.txt, however, command 1 generates a stream of ...
10
votes
2answers
263 views

What are the security issues and race conditions in using `find -exec`?

From the find man page: -exec command ; There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead. -execdir command {} + ...
0
votes
2answers
41 views

Extracting a certain folder from a tarball - how do I tell it where to put the file once extracted?

I've looked around at multiple sources for this question and I know how to extract the file, but neither source told me how to state where to put the folder once it has been extracted. I tried this: ...
0
votes
1answer
23 views

Excluding files whilst using tar to zip site contents not working [closed]

I'm trying to zip the contents of a site using tar and exclude a bunch of folders and error_log files but it doesn't seem to be working, when it's processing I still see many of the excluded files ...
-1
votes
1answer
51 views

Organize a file [closed]

I want to thank the great help and support. Well, I have the following file: name id alello chr pos snp s1 215 a 1 11 a215 s1 216 a 1 11 a216 s1 217 ...
1
vote
4answers
70 views

How do I echo a string with multiple spaces in bash “untouched”? [duplicate]

I assigned a var like this: MYCUSTOMTAB=' ' But using it in echo both: echo $MYCUSTOMTAB"blah blah" or echo -e $MYCUSTOMTAB"blah blah" just return a single space and the rest of the ...
3
votes
4answers
74 views

How can I save the output of “echo -e '\e]4;40;?\a'” into a variable, or pipe it?

Inspired by this forum post, I ran this command at a Bash prompt: echo -e '\e]4;40;?\a' Which outputs: # 4;rgb:8b8b/cdcd/0000 But the weird thing is, the output somehow becomes my prompt's next ...
0
votes
5answers
115 views

How do I display all the characters between two specific strings?

I want to display all the characters in a file between strings "xxx" and "yyy" (the quotes are not part of the delimiters). How can I do that ? For example, if i have input "Hello world xxx this is a ...
24
votes
2answers
1k views

Opening Your Command Prompt In A Text Editor - What Is This Called?

One of my favorite tricks in Bash is when I open my command prompt in a text editor. I do this (in vi mode) by pressing ESC v. When I do this, whatever is in my command prompt is now displayed in my ...
1
vote
1answer
34 views

Interactive remove files listed with paths in text file

I am trying to interactively remove files listed with their paths in a text file. The command I am trying is: xargs rm -i <filelist.txt The error I get is: rm cannot remove ...
1
vote
0answers
36 views

Add bash to base Linux Kernel?

We have a proprietary SBC (Single Board Computer) type of platform that is a large sized scale Raspberry Pi essentially. It is ARM based and uses Linux Kernel v3.# as its base. This isn't an Ubuntu ...
1
vote
3answers
31 views

Remove front-slash using sed

I have a text file that contains following https://git.centos.org/git/rpms/abc.git https://git.centos.org/git/rpms/abc.git/ https://git.centos.org/git/rpms/abc When I run the following command, ...
0
votes
1answer
37 views

sed cannot insert if a file ends with empty line

I have a file uca.xml (Thunar configuration for custom actions): <?xml encoding="UTF-8" version="1.0"?> <actions> <action> <!--some code--> </action> ...
0
votes
2answers
34 views

How to handle space character in input from user

I have recently started working with Shell scripting. So, I am facing one issue that when i am taking filename as an input from user, then if I give spaces then it does not get handled with my code. ...
-2
votes
0answers
14 views

Will zip -r command on remote server be cancelled if I exit terminal? [duplicate]

I have done a lot of Googling, and cannot find an answer. I have made a "zip -r home" request on my server via my terminal. The home directory is over 30GB. I need to leave the office at some point ...
-1
votes
2answers
24 views

collect and create tab separated matrix

I have 6 text files (each corresponds to a specific sample) and each file looks like this: Gene_ID Gene_Name Strand Start End Length Coverage FPKM TPM ENSMUSG00000102735 Gm7369 + ...
0
votes
1answer
49 views

syntax error: invalid arithmetic operator (error token is “.c”)

I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the ...
3
votes
4answers
93 views

How to execute multiple commands remotely on few servers?

I am trying to automate these steps so that I don't need to do this on every machines manually. I need to install latest app server software (abc.tar.gz) on all the unix boxes. I need to do this in ...
4
votes
1answer
59 views

Automatically open text files in editor instead of attempting to run them?

When I accidentally type the name of a text file without some kind of editor command, and the text file is not a shell script, I get a "permission denied" error*, since the file is not executable, and ...
1
vote
2answers
47 views

how to kill job in background?

I know how to kill a job with kill %(number) but is it possible to kill a job as background job, the question is "kill tail as a background job?"
0
votes
2answers
24 views

BASH How to save the output of rm -vri to a var [duplicate]

How can I save the output of this command into a var and still remove the files? rm -vri files | wc -l
0
votes
2answers
29 views

/usr/bin/find invocation doesn't work when used with command substitution [duplicate]

In a script, I have: CMD='/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; ' MD5=$("${CMD}") But the script gives the error: -bash: /usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; : ...
-1
votes
0answers
16 views

YumRepo Error in CentOS

when I run yum install lftp I get this error Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile YumRepo Error: All mirror URLs are not using ftp, http[s] or file. ...
-3
votes
3answers
35 views

unable to scp a file with a space in name [duplicate]

Actually the problem is that on the image bellow.
3
votes
4answers
93 views

How do I extract a long listing field?

I want to extract the access day of a file in a shell script. I tried by writing the following script but it doesn't work. When I echo accessday, the output is "staff". file=$1 accessday=$(ls -lu ...
0
votes
3answers
64 views

Why is the array empty after the while loop? [duplicate]

I try to initialize an array in bash-4.2 next way: ring=() ls -las | tail -n +4 | while read line > do > ring+=("$line") > echo ${ring[-1]} > done 3924 -rw-r--r-- 1 username group 4015716 ...
16
votes
5answers
2k views

Root shell mistakenly changed. How can I change it back to a valid shell?

I mistakenly entered chsh -s /usr/bin instead of chsh -s /bin/bash and now I can't log into a root shell, how do I start a bash shell as root manually ?