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

Syntax for rm command. Worried about using the -r option

I am trying to create a routine to manage the backup files I am creating, so that older folders will be deleted automatically in the process. Here’s what I've got: #!/bin/sh day=$(date +%m%d%y) ...
0
votes
1answer
46 views

How to grep response to figure out how many calls got timed out?

I have a curl command which is calling one of our service so if my service timesout, it returns JSON response like below: [{"results":{"response":null},"error":{"errorCode":1001,"message":"Service ...
0
votes
2answers
34 views

What is the difference between token identifier WORD and NAME?

In POSIX 7, the shell grammar (Section 2.10 in XCU) mentions several token identifiers. I am confused about two: WORD and NAME. What are their differences? For example, is a command's option WORD ...
3
votes
3answers
54 views

How to understand the order between expansions?

From POSIX 7: The order of word expansion shall be as follows: Tilde expansion (see Section 2.6.1), parameter expansion (see Section 2.6.2), command substitution (see Section ...
3
votes
1answer
55 views

How can I see the size of a partition's unallocated size on the command line after shrinking a partition with resize2fs?

I want to shrink my /dev/sda2 partition from 463.37GB to 400GB to make room for a new partition. So I did e2fsck -f /dev/sda2 followed by resize2fs /dev/sda2 400G. As per man resize2fs, the ...
1
vote
2answers
45 views

Does an external command which takes a command as its argument has restriction on the argument?

For an external command which takes a command as its argument, must the argument be an external command, not a shell's builtin command? I ask this question, based on the following two examples the ...
7
votes
1answer
578 views

What does `\time`, `t\ime` and `\cd` actually do? (fun with backslashes in shells)

While discussing over the differences between /usr/bin/time and the shell (bash and zsh) built-in time, someone mentioned that one can use \time as a shorthand to get /usr/bin/time. First it seemed ...
0
votes
3answers
120 views

Send command to the shell via Makefile

I'm building a Makefile to automate the start of docker on osx. At the end of the start docker requires to launch this command on the shell in order to configure the shell: eval "$(docker-machine env ...
0
votes
3answers
57 views

pipes in linux command line [duplicate]

Consider the following command: echo ’.dump’ | sqlite bacula.db > bacula.sq What is it doing and what does | do? Maybe someone could point me to a manual about piping, or explain what is going ...
0
votes
2answers
57 views

shell script - subtract 1 from hexadecimal mac address and add colons to it

I have mac address as 'C4:B9:83:7F:FF:AC' and I want to subtract 1 from its hex values which is C4B9837FFFAC so it will become C4B9837FFFAB and after this I again want to add colons to make it ...
4
votes
1answer
52 views

Bash script for showing newly introduced env variables

I'm making this test script to help me reverse engineer scripts in charge of setting the dev environment. The script: #env-changes #!/bin/bash TESTED_SCRIPT=$1 shift ENV_BEFORE=$(env | sort) . ...
3
votes
2answers
387 views

Printf printing only a single line

I'm trying to get the output of env in a shell variable and print it. #!/bin/sh ENV_BEFORE=$(env) printf $ENV_BEFORE As a result a single variable from the env output gets printed. When using echo ...
0
votes
2answers
26 views

Running source command with -x for debugging

I am trying to understand how a shell script is working. The tutorial states that the script should be run as the following way: source oe-init-build-env rpi-build Usually when doing this kind of ...
4
votes
0answers
74 views

bash process substitution with temporary file

Some programs needs their files to be seekable, for example objdump does. $ objdump -D -b binary -m i8086 <(echo 0xea 0x5b 0xe0 0x00 0xf0|xxd -r -p) objdump: Warning: '/proc/self/fd/11' is not an ...
8
votes
2answers
1k views

Why did mv delete a file with mv id_rsa *.old? [duplicate]

I wanted to backup my ~/.ssh/id_rsa to id_rsa.old, and it looks like it got deleted! How is this possible? :) root@localhost:~/.ssh# ls -l total 16 -rw------- 1 root root 3326 Mar 12 11:22 id_rsa ...
1
vote
0answers
35 views

Copy file into all subdirectories that contains a file with certain name

I am trying to copy a features[30,55].R script from my desktop into all the subdirectories that contain a file whose name is DONE. I tried the following command: find . -name "DONE" -exec sh 'cp ...
3
votes
2answers
53 views

How to source `. filename` reliably?

The current POSIX spec does not specify any options for dot . builtin. If I do something like: $ echo 'echo .' > /tmp/-foo $ PATH=/tmp "$shell" -c '. -foo' then the result is varied between ...
0
votes
2answers
52 views

Transforming a list of files separated by new lines into a variable

Goal: I'm trying to find all instances of *.clj or *.cljs files recursively within a directory, store them in a string variable (separated by new lines) and then transform them. So if the following ...
1
vote
2answers
59 views

how to move all files from a pipe into a directory ?

I performed a file-command on all elements in my Desktop directory: ~/Desktop > file * then I grepped all the lines who have the string "image" in the description: ~/Desktop > file * | grep ...
-1
votes
1answer
25 views

Remove pattern from a line in file with Grep/sed/awk combo, pattern is another column

I have two columns (or could separate as two files) in a huge file and i need to remove the duplicate city name in the state/area column. los angeles los angeles ca, usa, west new york ...
11
votes
7answers
2k views

How to create a large file in UNIX?

I found a way in Windows to do such thing echo "This is just a sample line appended to create a big file. " > dummy.txt for /L %i in (1,1,21) do type dummy.txt >> dummy.txt ...
1
vote
2answers
31 views

Wait until gnome-terminal ends

I'm trying to implement a script who runs four terminal window in parallel using this function gnome-terminal -e sh -c "python scraper.py". I would like to know if there's a way to wait until each ...
1
vote
2answers
42 views

getting the owner of the folder with the if command [closed]

i want to be able to prevent people from accidentally deleting critical files of the system in my my script, does anyone know how to use the statement to find if the owner of the folder?
0
votes
2answers
56 views

Can I have a (bash) shell with expect running in the background?

I am trying to write an expect script that once started will watch my terminal and run a command every time that it finds a match. Is this even possible with expect? If so, would expect_background ...
2
votes
4answers
60 views

move a file that matches a pattern in a shell script

I have very little experience in writing shell scripts and need advice on how I can accomplish the following task. I need to move the most recent file in a directory where the filename matches a ...
0
votes
0answers
19 views

How to check the status of the latest aide run after login, and test if it's done less then 24h(green) or more then 48h(red)?

-Green: No changes detected and last AIDE run was less then 24 hours ago -Red: Changes detected or last run was 2 days ago I tried to grep the timestamp from the log file /var/log/aide/aide.log which ...
0
votes
1answer
35 views

Editing the variable PATH

I want to start script just by typing script not the full path of the script for example ~/Desktop/name/script so i tried to edit variable PATH PATH="$PATH:~/Desktop/name" in the name folder i have ...
22
votes
4answers
1k views

What exactly happens when I execute a file in my shell?

So, I thought I had a good understanding of this, but just ran a test (in response to a conversation where I disagreed with someone) and found that my understanding is flawed... In as much detail as ...
2
votes
5answers
69 views

how to cut fields of a directory name?

I have directory named 140905_M01771_0112_000000000-ABBYT. I want to get the third field i.e. 0112. I tried: cut -d _ -f 3 131230_M01771_0032_000000000-A7874 giving me error: cut: ...
4
votes
1answer
49 views

Split file and know how many files were generated

I'm using the following lines to split a file into smaller parts: split --line-bytes=100M -d $input $output/FILENAME echo "$input was split into ??? 100MB files." >> demo.log After that, I ...
0
votes
3answers
112 views

Help with tr command

Assume that the file ft has 25 lines of text. Explain the command: tail -15 ft | tr "a" "A" > ft and tell me how many lines the file ft has after the execution of the command. I understand that ...
1
vote
1answer
53 views

Sed command usage without defining variables in shell script

I have two variables source_repo="fdl_ppe_01_04_repos_svc" target_repo="fdl_ppe_01_10_repos_svc" and I currently do a substitution within an XML file to replace all instances of $source_repo with ...
0
votes
1answer
35 views

Dash print expanded commands

Running xtrace or set -x with Bash will print the expanded command: $ bash -xc 'touch "alfa bravo"' + touch 'alfa bravo' However Dash does not print the command that is actually run: $ dash -xc ...
3
votes
2answers
60 views

Passing a list of two PIDs to xargs only kills the first using ssh

I'm retrieving a list of two PIDs that I want to kill. My pipeline looks something like ps -ef | grep foo | grep -v grep | awk {'print $2'} | xargs kill -9 Both processes are killed when executing ...
1
vote
2answers
61 views

set -u usage not working as expected

I am learning how to efficiently use different set options in my script and came across set -u that appears to be perfect for exiting my script if a variable does not get set properly (ex. deleting ...
5
votes
2answers
572 views

How can I add datetime to an existing file name in Linux?

I want to add date and time to the file name, for example: 08032016out.log.zip This is what I try to do: _now=$(date +"%m_%d_%Y") _file="$_nowout.log" touch $_file.txt # creating new file with the ...
-2
votes
1answer
51 views

CentOS 7 SSH errors

having a bit of an issue with SSH and my CentOS 7 server. Here's a description of my problem. I have open-ssh setup on my server, and am able to ssh in as root (The server is a remote server, and ...
1
vote
2answers
115 views

POSIX print function definition

Bash can print a function defintion: $ bash -c 'y(){ echo z; }; export -f y; export -f' y () { echo z } declare -fx y However this fails under POSIX Bash, /bin/sh and /bin/dash: $ bash --posix ...
2
votes
3answers
99 views

Trying to understand .bashrc, env, and export

Disclaimer: Using bash. I just need some confirmation / correction on my understanding of these things: env is basically displaying the current environmental variables that are accessible to my ...
-3
votes
1answer
43 views

Meaning of this perl command [closed]

I found this command perl -ne 'print $1 if m/\.([^.\/]+)$/' and I'd be very grateful if someone familiar with perl could tell me in a nutshell what exactly all the syntax means, it would save a lot of ...
0
votes
1answer
64 views

-r filename && . filename

i was just looking into a script i find this line. can anyone tell me what this line do. this is the code line. [ -r "$PosConfigDir/posconfig.sh" ] && . "$PosConfigDir/posconfig.sh"
1
vote
2answers
82 views

Is `var=value builtin` the same as `var=value; builtin`?

In my answer here, I used the construct: n=$1 shift Reading Token Recognition spec, I understand that the shell will parse that line into two parts - the variable assignment n=$1 and the builtin ...
0
votes
0answers
20 views

What does echo *? [duplicate]

Recently I was writing a bash-script and added a line: $ echo * and got an output of file names and directory names. What is the context of this list (just out of curiosity)?
3
votes
2answers
45 views

How to pin certain files when using sort?

Normally I am more creative with Unix commands and pipes, but not today. So what I have is this: collage.jpg DCIM001.jpg DCIM002.jpg or this: 001.jpg 002.jpg boston-collage.jpg or sometimes ...
-3
votes
1answer
29 views

How do you disable command “chattr” in debian 8? [closed]

# cat test2 ali is home helo esi how are you? i`m fine.tanks i`m fine.Tank you # chattr +a test2 # vi test2 . . . Press ENTER or type command to continue
1
vote
2answers
73 views

find “corrupt” file, nesting an if inside a find command

I'm trying to find "corrupt" files inside a directory structure, namely files which the file command would interpret as "data". Here is the command I've been trying to run, but fails: $ find . -type ...
4
votes
5answers
201 views

How shrink test -eq expression with more than one var value in /bin/sh

#!/bin/sh if [ $num -eq 9 -o $num -eq 75 -o $num -eq 200 ]; then echo "do this" elif [ $num -eq 40 -o $num -eq 53 -o $num -eq 63]; then echo "do something for this" else echo "for other do ...
1
vote
2answers
60 views

Copy Files Based on Dates in Filename

I am having an issue when attempting to copy a range files from one directory to another based upon a date contained within the filename. The date in the filename is in UTC whereas the created dates ...
2
votes
1answer
51 views

Search bash history for already typed command

When I type ctrl+r and then start typing I can see what commands in the history match which is great. Now is there a way to search the history on commands I have already typed in the terminal? For ...
3
votes
1answer
72 views

Difference between parentheses and braces in terminal? [duplicate]

( du /etc; du /var; ) > tmp.txt { du /etc; du /var; } > tmp.txt Is there a difference between the () and {}? The output of tmp.txt seems exactly the same, and I was wondering whether i'm ...