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)

4
votes
1answer
2k views

Substitute pattern within a file with the content of other file

I have a text file (devel.xml). I added the word REPLACETHIS to it in order to replace this string with the content within a different file (temp.txt). The closest thing I have is this: sed -i -e ...
5
votes
3answers
17k views

How to merge two files based on the matching of two columns?

I have file1 likes: 0 AFFX-SNP-000541 NA 0 AFFX-SNP-002255 NA 1 rs12103 0.6401 1 rs12103_1247494 0.696 1 rs12142199 0.7672 And a file2: 0 AFFX-SNP-000541 1 0 ...
9
votes
4answers
3k views

Local, timestamped logging of all ssh commands?

How can I keep a local, timestamped record of all remote commands I use in ssh (command-line openssh client started through bash)? Requirements: Essential: 100% client-side without relying on ...
6
votes
3answers
1k views

How to go back n levels of directories from the command line?

For example, I do the following cds in succession- cd /tmp cd /home/admin cd /root/ cd /some_other/directory Now I am in /some_other/directory. Now, is there anyway to go back to /tmp, the ...
0
votes
2answers
54 views

How to install GMP on CentOS?

I tried to install GMP on CentOS but I could not. The output message is: [root@localhost fedora]# wget https://ftp.gnu.org/gnu/gmp/gmp-6.0.0a.tar.xz --2015-06-04 01:43:53-- ...
3
votes
6answers
22k views

Extract date from a variable in a different format

Let me explain you the problem $ date +%c -d "$d" Tue 31 Dec 2013 01:13:06 PM CET $ date +'Today is %F' -d "$d" Today is 2013-12-31 This solution corresponds to current date. But I have one ...
1
vote
3answers
2k views

Find files containing one string but not the other

I am in a folder with lots of .txt file, I would like to find all the files which contain stringA, but don't contain stringB (they are not necessarily in the same line). Does anyone know how to do ...
-2
votes
1answer
20 views

How to Upload To vsftpd default dir with scp

I have been working on uploading from shell and I need to upload from shell I found scp in openssh-client . and it work perfectly but in this command I have to set destination path in ftp server like ...
1
vote
2answers
104 views

How to see if the directory exists?

How can I check if /bin/x86_64/bin/ls is a directory in a bash shell script Here is what I tried: #!/bin/bash if [ $# -eq 2 ]; then if [[ "$1" = /* ]] then cd ./bin/x86_64/bin/ls ...
1
vote
3answers
62 views

How to scp all files of a certain owner?

I want to scp all files of certain owners. For example, if this is my ls -la output: -rw-rw-r-- 1 owner1 ad 704 Jun 1 18:16 file1 -rw-rw-r-- 1 owner2 ad 798 May 29 11:15 file2 -rw-rw-r-- 1 ...
0
votes
5answers
111 views

How to grep an xml block in an xml file using a keyword in ksh

I have a file Sample.xml which contains a lot of services inside it and the structure looks like this Notes: I cannot use any XML parser tool as I don't have permission , read only My xmllint ...
-1
votes
3answers
74 views

Need to Split the output in Row & Column

I am just a beginner in shell scripting and currently working on one script which will capture all the Endpoint Name & Ongoing calls on my switch and will send the output to one file. Output is ...
10
votes
3answers
6k views

What is the purpose of -e in sed command?

I can't find any documentation about the sed -e switch, for simple replace, do I need it? e.g. sed 's/foo/bar/' VS sed -e 's/foo/bar/'
1
vote
1answer
42 views

Auto login by device followed by login by user?

Question: Does anyone know of any methods to perform a "second" login without using su, or a means to use su that requires the user to enter their username after the su command is issued? Situation: ...
0
votes
3answers
64 views

get value after specific word

I have this file 1 deiauk David Smith from California 12 58 2 edvin from Nevada 12 5 8 95 2 48 5 3 jaco My Name Is Jacob I'm from NY 5 6 845 156 585 4 from Miami And I need to get values after ...
-1
votes
1answer
73 views

How to set Row & Column in shell Script

I am a beginner in shell scripting. Just made 1 script with the help of others and it is working like we expected. However i want to organize it more. Current Script { date '+%F %T'; ...
1
vote
2answers
255 views

Why are bash tests so picky about whitespace?

As a primarily Java programmer, I find the bash if-then construct quite confusing, especially regarding whitespace. Can anyone explain why the first one works, but not the second or third? #works if ...
2
votes
1answer
45 views

How to output a comparison of values in separate files

With the following two files available with build names and version numbers available: server.txt Build2 200 Build3 100 Build1 400 Build7 200 local.txt Build1 300 Build2 200 Build3 100 In my ...
-1
votes
3answers
52 views

find files in current directory [closed]

I have a txt file with some current directory names a.txt b.txt and here's my all file in directory a.txt b.txt c.txt d.txt ... I need to find files from txt file and remove files from my ...
6
votes
5answers
883 views

Semi-asynchronous pipe

Assume I have the following pipe: a | b | c | d How can I wait for the completion of c (or b) in sh or bash? This means that script d can start any time (and does not need to be waited for) but ...
47
votes
2answers
6k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
1
vote
2answers
1k views

How to do a grep on remote machine and print out the line which contains those words?

I have few logs files in my machineB under this directory /opt/ptd/Logs/ as shown below - My logs files are pretty big. david@machineB:/opt/ptd/Logs$ ls -lt -rw-r--r-- 1 david david 49651720 Oct 11 ...
25
votes
3answers
8k views

Quoting within $(command substitution) in Bash

In my Bash environment I use variables containing spaces, and I use these variables within command substitution. Unfortunately I cannot find the answer on SE. What is the correct way to quote my ...
0
votes
1answer
41 views

How to parse through a .dat file and get patterns such as timestamps and file size of a .jar file declared inside

I want to compare the size and timestamp of the following jar files in separate directories. First data is fetched by: grep -Eo ...
1
vote
3answers
56 views

Get specific number in line

I have this file 123 My name is Lorry I'm 29 years old 10000 45 148 Name - Dan 20000 18 895 My name is John Lazaro I like tennis 30000 63 And I want to print only last numbers in a line ...
10
votes
1answer
154 views

Why is nullglob not default?

In most shells nullglob isn't the default. That means, for example, if you run this command ls * in an empty directory, it will expand the *-glob to a literal ' * ', instead to an empty list of ...
0
votes
2answers
2k views

Why doesn't alias work in AIX (Korn shell, .profile)?

I have these files in my home directory: drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 . drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 .. -rw------- 1 meuser staff ...
0
votes
1answer
11 views

see newest release last (YML release files with the same timestamp from Git)

I pull from Git *yml files with "$packagename-$release.yml". The highest number is the most recent release. I wish to have the listening with latest release last. Correct sort order ...
4
votes
4answers
131 views

A shell tool to “tablify” input data containing ANSI escape codes

I have input containing ANSI color codes that I'd like to tablify. I want the output to remain colored, so the tablified output should maintain the ANSI color codes. Hence, naively stripping them away ...
1
vote
3answers
131 views

Using AWK to convert numbers to 0 or 1

This might be a simple question but I can't figure it out for the life of me. I have a file called keyout.dat which looks like this: Title 1 Variable -999 -999 0.234 0.123 -999 -999 0.555 The file ...
0
votes
1answer
44 views

tar exclude files *.zip

Why don't *.zip patterns work in tar : tar cfjv backup.tar.bz2 --exclude mydir/files/*.zip mydir Is there another syntax?
0
votes
2answers
43 views

Can't get if statement to run correctly. Beginner. [duplicate]

I am very new to bash, just playing around in my free time off work. I want to check if a file exists, and if it doesn't exists, I want to ask the user if they'd like to create it. Whether the user ...
9
votes
3answers
6k views

Can files be created with permissions set on the command line?

When creating directories, mkdir -m <mode> <dir> provides for creating one or more directories with the given mode/permissions set (atomically). Is there an equivalent for creating files, ...
0
votes
0answers
51 views

$PATH variable on Fish Shell OS X

I have somehow screwed up my path variables with Fish shell on OS X. Is this the proper $PATH variable in the config.fish? user@host ~> more ~/.config/fish/config.fish set -g -x PATH ...
8
votes
2answers
505 views

Why does --text=“$@” only pass the first word?

When I run the following script with some arguments like arg1 arg2 arg3: #!/bin/bash zenity --entry --text="$@" zenity creates an entry dialog with this text: "arg1" whereas I expect "arg1 arg2 ...
46
votes
5answers
32k 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
3answers
109 views

find directories with specific patterns leads to Permission denied error and no result

I have this kind of shell script on Linux: #!/bin/sh echo -n "Please enter directory pattern: " read dirs find $dirs > /tmp/justbay.txt allDirs=$(find $dirs ! -readable -prune) echo $allDirs ...
1
vote
0answers
61 views

Easy way to compare BIOS information between two machines?

I have two machines - machineA and machineB running Ubuntu 12.04 Is there any easy way I can compare BIOS settings between those two machine and see the difference instead of doing it manually using ...
1
vote
2answers
85 views

works as a command but not as a shell script. Why?

$ grep "apple" fruits.txt apple $ if [ $? == 0 ] ; then echo "A"; else echo "B"; fi A When I execute the above commands it works fine but when I run these commands as a shell script it throws error ...
0
votes
2answers
4k views

Got “syntax error near unexpected end of file” in bash script

I'm making an script that gives me a day like this jjj/yyyy when I give it a day like this dd/mm/yyyy and I need it to have an error when you don't write correctly but I'm starting and it's not ...
3
votes
4answers
50 views

find on a set of dirs that may not exist

I need to invoke find on a set of "starting points" which is generated, but some of paths may not be valid: paths() { # # mock version of the generator # echo /bin echo kjsdfhk ...
2
votes
2answers
145 views

bash: can't set a variable to a solid string [duplicate]

I cannot set a variable with a whole command-string as following: A="/bin/ps wwwaux" for a in $A do echo "$a" done It assigns array instead of solid string somewhy. Could you assist, please. My ...
10
votes
7answers
17k 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
4answers
65 views

How to track/log commands executed on a shell?

Can commands be written to a logfile before they were executed in any shells? I know there is a patch for ssh to log all commands from ssh sessions, but i want to log even commands executed from a ...
3
votes
3answers
69 views

Copying a Parent Directory into a Subdirectory Without an Infinite Loop

For application specific reasons, I need to copy an entire parent directory into a subdirectory. E.g., cp -r ../ tmp/ The problem with this is that it gets stuck in an infinite loop, recursively ...
29
votes
4answers
13k views

Clone ownership and permissions from another file?

Is there a command or flag to clone the user/group ownership and permissions on a file from another file? To make the perms and ownership exactly "like" that of another file?
1
vote
2answers
35 views

Shell script exit code and logging

I have got following simple shell script, in which I am trying to send STDERR & STDOUT to both screen and log it in a file(test.log). Also, while exiting I am trying to exit with appropriate exit ...
17
votes
5answers
23k views

How to match case insensitive patterns with ls?

I would like to list all files matching a certain pattern while ignoring the case. For example, I run the following commands: ls *abc* I need to see all the file that have "abc" as a part of the ...
0
votes
2answers
35 views

sed replace ;“ content with ';”

I have files that contain ;" and I need it replaced with ';" The following sed command does not work: sed -i "s/;"/';"/g" /root/bashy.sh How can I do this? The solution doesn't have to be sed.
2
votes
1answer
68 views

Get all filenames in a directory created before input date

I have a directory containing lots of files. The output of ls command is -rw-r--r-- 1 nobody nogroup 427494 May 26 13:59 14_20150526065238928590_102.txt -rw-r--r-- 1 nobody nogroup 2113592 May ...