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
3answers
17 views

How to bulk compress different sub-folders?

I have a folder all_folders which contains 5 folders: ./all_folders ./all_folders/folder1 ./all_folders/folder2 ./all_folders/folder3 ./all_folders/folder4 ./all_folders/folder5 Can I compress all ...
2
votes
6answers
176 views

What does pwd return?

Does the command pwd in a shell script return the directory the shell script is in?
0
votes
2answers
25 views

How to read a file into a shell script as a variable?

I need to write a shell script to read a text file in and perform operations on it to count all distinct words in the text file. I have all of the commands needed to do these operations, but how ...
2
votes
1answer
26 views

Is a sub-shell the same thing as a child-shell

There are this two names: a subshell and a child-shell. Yes, a child process will be started by any of this: sh -c 'echo "Hello"' ( echo "hello" ) echo "$(echo "hello") echo "hello" | cat Are all ...
0
votes
1answer
20 views

nohup nice job aborted when disconnected

I've learned that "nohup" command allows the command to keep running if you lose your connection or need to logout. I'm running "nohup nice my command &" in remoter through shh, and after my lap ...
0
votes
1answer
17 views

Comparing 2 directories and copying the different sub-directories to a 3rd directory

I have 2 directories DIR1 and DIR2 DIR1 is base directory, where new changes come often, sometimes new sub-directories as well. DIR2 has older version of files. I want to compare these 2 ...
1
vote
1answer
21 views

Remove forced line breaks from fortune output while preserving them for the author line

Recently I encountered the great fortune command and use it now to send a nightly quote to a persistent chat. Now I wonder how to remove the forced line breaks for the quote part, but preserve them ...
-3
votes
2answers
41 views

How to achieve using ls command [on hold]

I have two files in a directory: abc_160101.txt and abc_a_160101.txt. How to list the first file only with ls command using abc_* or other pattern?
0
votes
1answer
27 views

Print lines not containing a Tab

I have a text file (around 15000 lines) that is supposed to contain two fields separated by a Tab in each line. Is there a way to display the lines that do not contain a Tab separating the two ...
2
votes
3answers
111 views

Does command substitution create a subshell?

Bash manual says: Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except ...
0
votes
1answer
32 views

How do i call the case function

I have the following script to login to the servers. This scripts enables me to login to the host automatically using expect script based on the option i choose. As soon as i logout from the host im ...
1
vote
1answer
35 views

Remove a part of a path from a variable content

In a Bash I have a variable: LOCAL_PATH="/this/is/a/path/" Then I have another variable, which content starts with LOCAL_PATH and it should be removed: LINE="/this/is/a/path/which/is/longer" The ...
-4
votes
1answer
43 views

Simple bash script to print prime numbers from 1 to 1000 [on hold]

How can I make a POSIX script that will print all the prime numbers from 1 to 1000? Lots of thanks
1
vote
1answer
34 views

linux unbuffered compression options

I'm working on a embedded system and due to persistent memory restrictions, I need to compress a log file "on the fly". My objective is to have a one liner inside a script, which would look like ...
-4
votes
3answers
47 views

Write file names in to a file

In a directory I have X.txt,Y.txt,Z.txt files. I want to move these filenames into a single file like below: Out_file.txt X.txt Y.txt Z.txt Any unix command to achieve this?
-1
votes
1answer
50 views

meaning of [ $? -ne '0' ]. (shell script)

could anyone tell me what the following command means? I'm reading a shell script and studying what it does. But at the end of the script, the following commands appeared. I have no idea what it ...
1
vote
1answer
30 views

Comparing original & backup folder, then deleting non-existing files

I'm using Raspbian jessie (ubuntu). I made a .sh that makes a backup .img of everything (excluding mnt, tmp, run, dev, boot, etc.) and let this run once a week with crontab. It checks for modified ...
0
votes
1answer
33 views

Listing files with a certain extension

I'm suppose to write a command that would list all files that end in .tx with an optional t at the end. So far all I got is listing the files that end in .tx which is: ls *.tx Now my problem is ...
1
vote
0answers
32 views

Getting Busybox Cron to work on Qemu ARM VM [on hold]

I created a .sh script, then tried crontab -e and entered * * * * * /etc/cronscript.sh, then tried to start it by typing crond. It looks like its trying to do something once per minute, but not my ...
3
votes
2answers
28 views

Run in background but not discarding the output

I use a Git hosting. So I often run git push. I want to run git push in background, in order that me not to wait when it finishes but do other tasks in my terminal. But I don't want to run git push ...
0
votes
0answers
20 views

meaning of !(something) in shell [duplicate]

While searching for a way to move all files in a dir to one of its sub-folders, i came across mv !(something) something which should do the job - but only in bash. However i could not find why. in ...
1
vote
1answer
26 views

How to get file descriptor number of a output and how to redirect all of them at once

Lets take this command for example $ time ssh ec2 ls www apps real 0m0.554s user 0m0.004s sys 0m0.000s $ time ssh ec2 ls 1>/dev/null real 0m0.554s user 0m0.004s sys 0m0.000s ...
-1
votes
2answers
42 views

how to login a user using shell script [on hold]

In my computer i have two user(tiger,jenk) now i want to create a shell script for login user "jenk" from user "tiger" i m try this code [tiger@pagaltiger mytask]$ echo -e "IncorrectPassword\n" | ...
0
votes
1answer
35 views

Only send email if disk usages exceeds 80%

My script is: abc=$(df -h | sed s/%//g | awk '{ if($5 > 80) print "Alert "$0;}' | awk '{print $2,$6}') \ && echo -e "Dear All, \n\n$abc\n\nABC" \ | mailx -s "Disk partition" ...
0
votes
2answers
39 views

How do I permanently remove an Alias from my Shell

When I was not near my computer some guy got it and set an Alias for ls in my root folder. He set it to 'yes NeverGonnaGiveYouUp'. So now when im in my root folder and type ls I get an infinite loop ...
1
vote
3answers
35 views

Run a command over directories with name recursively

I have the following directory structure in AIX. codeRepo/REPO1/AREA1/objects codeRepo/REPO1/AREA2/SUBAREA1/objects codeRepo/REPO1/AREA2/SUBAREA2/objects From codeRepo I want to run chown myUser * ...
0
votes
3answers
66 views

To calculate average by taking command line argument

The task is that if input numbers: 4 1 2 9 8 Output=(sum of all except first_number_in_series)/first_number in series Then output average should be 1+2+9+8/(first_number_in series)=20/4=5 I have ...
0
votes
1answer
30 views

Kill command also kills other process

I have a very simple script, let's call it foo.sh. It's this: #!/bin/sh sxhkd & panel & where panel is a script (I won't post it here because it's very long and I don't think it would be ...
0
votes
2answers
35 views

Which location does shell assign normal variable?

As you know, bash shell itself is also process. If I use command export a=c, then shell dynamically allocates variable a into location where environment variables are reside.(This environment section ...
1
vote
1answer
47 views

Combining strings command and grep: how to limit results to null-terminated strings

I have a feeling that it is strings which is thwarting my efforts here. The binary files I want to use strings on unfortunately yield several matches per file, even though it is a 100% rule that ...
2
votes
1answer
21 views

Get current memory usage of a tmux session

As the title says. I need a way to the used memory of a current tmux session. I am not sure if that is even possible. I am using tmux to start multiple minecraft servers I'd like to know each servers ...
3
votes
3answers
39 views

Can the Bash shell “Ignore” Excess copy-paste text?

Say, I have a "Quick&Dirty" Perl script in a gui text editor, and I start the Perl interpreter in a terminal window which is running Bash. I can copy-paste the Perl script to the terminal & ...
1
vote
2answers
19 views

bash adding a filename to an alias command [duplicate]

I have an alias to a ffmpeg command to start recording a session like this: alias sreq='ffmpeg -f x11grab -r 24 -s 1024x768 -i :0.0 -qp 0 -c:v libx264 -preset veryslow' I can just type sreq ...
-3
votes
0answers
18 views

Removing intermediate line breaks in muliple columns except the last new line character [closed]

Suppose If I have the data like this Col1|Col2|Col3 <br\> 123|abc\n<br\> xyz\n<br\> |abc\n<br\> def\n<br\> other rows<br\> <br\> In the above newline ...
0
votes
0answers
31 views

How to get curl progress bar in terminal?

I'm using curl to upload files from a bash shell. I know there's the option --progress-bar which is supposed to give an upload progress indicator, but no matter what, I can't get it to show. I do ...
0
votes
1answer
39 views

Unexpected end of file in .bash_profile

When I do source ~/.bash_profile I get this "line 14 syntax error: unexpected end of file" error, I tried to delete the last line for no avail. Thanks # Get the aliases and functions if [ -f ...
0
votes
2answers
100 views

Why does the cd command handle STDIN different than other commands?

Commands like cd cannot have output piped to them in order to change directories--they require command-line arguments. Why does the cd command (and those similar to it, such as mv, cp, & rm) not ...
0
votes
1answer
41 views

Kill a running shell script, and kill all process running within it

I have a shell script running in the background, which runs 5 different jobs. When I run the shell script all 5 jobs start running in order. When I kill this shell, whichever process is running, will ...
1
vote
3answers
30 views

How do I organize and cut this portion of a directory into a file?

I'm new to unix and I'm not sure how to name my title but my main objective is to copy the contents of a directory and send it to a file. Then cut out the directory location to just have the name. ...
1
vote
0answers
50 views

Some commands are no longer responding?

I have a Debian based distribution & lately a problem has been encountered when trying to execute the gcc or man command's (And probably other commands I haven't found yet). When I type them in ...
1
vote
1answer
27 views

Can Bash tell an interactive SSH session from an in-line SSH session?

I have a Bash script that needs to be run from an interactive prompt, due to environment variables and configuration that only seems to be read when actually logged into a session. Examples below: ...
2
votes
1answer
55 views

Something confusing about “su -” and “su” [duplicate]

I am studying the Linux command line. But the book which I'm reading says that su -l(-) username is starting a new shell session and loading the environment of the user I want to change to, but su ...
13
votes
5answers
332 views

How can I find the first missing directory in a long path?

Imagine I have a path that doesn't exist: $ ls /foo/bar/baz/hello/world ls: cannot access /foo/bar/baz/hello/world: No such file or directory But let's say /foo/bar does exist. Is there a quick way ...
3
votes
3answers
323 views

How to sleep until a given date & time?

I want to write a shell where given a date (day-hour-min) e.g. 10:00 AM Sun 2:30 PM Mon ... It sleeps until that exact date & time. I thought one way of doing it is, I could get the current ...
1
vote
1answer
46 views

bash - queue subshells

function _abc { : 1 min task : _check & } function _check { wait for the previous calls of _check to complete : 15 mins task : } function abc loops depending on number of tasks. It is ...
4
votes
1answer
55 views

Are there non-interactive login shells?

I know what the difference between interactive/non-interactive and login/non-login shells are, but it seems like in practice there's never going to be a non-interactive login shell unless you have ...
1
vote
1answer
44 views

generate file names in loop [closed]

DISCLAIMER: I am using Mac OSX. The bash script is in a different directory from the files that require processing. From here my struggle begins… HELP 1: I have multiple files each housed in a ...
1
vote
2answers
51 views

Unable to run a process on background

I need help with a Solaris system. I have used the following command to run the cp.sh script in the background. nohup sh cp.sh < /dev/null & > /dev/null & output: Invalid null ...
-1
votes
2answers
21 views

shell command wrapper for socat

I have used the command socat - foo The text I type is sent directly to address foo. Is there some general-purpose wrapper for stdin (along the lines of ! from ed) that lets one parse a shell ...
1
vote
1answer
25 views

Cron Job Hourly Except Certain Time Frame on Friday

I want my cron job to run every hour, every day except Friday when I don't want it to run at all between the hours of 2am-9am (but hourly outside of this timeframe). Ideally, I'd like to have this in ...