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)

15
votes
4answers
472 views

Why is 'ls' suddenly surrounding items with spaces in single quotes?

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them ...
1
vote
2answers
34 views

Apache access.log getting updates after renamed

I have a file on my Ubuntu system called access.log that file get all my errors on my website. The problem is that file its to big right now so I renamed for access-old.log and create a new file ...
2
votes
2answers
18 views

Two input pipes through file descriptor shuffling and /dev/fd

I want to pipe two programs into one. If my shell supports it, I can use Process substitution. For example, to list the common lines of two files in indifferent order, I can use comm -12 <(sort a) ...
12
votes
5answers
3k views

How to cd automatically after git clone?

I want to automatically cd to the directory created by the clone command after I git cloned something. Important: I don't want to alter the syntax for the command (e.g. use an alias/function) because ...
0
votes
1answer
24 views

Bash script not working with crontab

I own a raspberry pi that runs raspbian jessie. I'm using this raspberry with motioneye as a system surveillance. Motioneye records files to a sd card but i want to delete older files in folder ...
0
votes
1answer
34 views

Delayed Expansion

I wanna make a quine .sh script, and this is what I've made so far: quine.sh: #!/bin/sh q="#!/bin/sh\nq=$q;echo \$q";echo $q Focus on this line: q="#!/bin/sh\nq=$q;echo \$q";echo $q At the first ...
9
votes
2answers
949 views

Cannot expand asterisk without proper permission

Can someone explain to me the following? $ ls -ld /temp/sit/build/ dr-xr-s--- 3 asdf qwer 4096 Jan 31 2012 /temp/sit/build/ $ ls -ld /temp/sit/build/* ls: /temp/sit/build/*: Permission denied So ...
1
vote
1answer
12 views

Comparing ping times in FreeBSD sh

How can I strip the time from a ping return? For example: 64 bytes from 10.3.0.1: icmp_seq=0 ttl=63 time=2.610 ms I want to grab the value after time= and pass it to a test like: if time>=50.0; ...
2
votes
1answer
25 views

How to set environment variables on server/client?

On some workstations (Debian & Ubuntu) and on a server (CentOS) I need environment variables for some scripts and jobs. What I did was altering ~/.profile: SOMEVARIABLE=/some/custom/path ... Is ...
3
votes
5answers
2k views

What does pwd output?

Does the command pwd in a shell script output the directory the shell script is in?
8
votes
7answers
2k views

List all binaries from $PATH

Is there one-liner that will list all executables from $PATH in bash.
1
vote
3answers
37 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 ...
2
votes
3answers
141 views

Why are non-environment variables passed to the subshell invoqued by command substitution?

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 ...
12
votes
2answers
67k views

How to change from csh to bash as default shell

I have csh as my default shell, as shown by echo $SHELL. I want to switch to bash as my default shell. I tried the following approaches to no avail: chsh. I get: chsh: can only change local ...
3
votes
4answers
39 views

Provide default value if command returns with non-zero exit code

I have some configuration in file config and would like to cat that file. However, sometimes config doesn't exist. In this case, I would like to have my command output a default value. Perhaps ...
0
votes
1answer
21 views

how to concatenate Login, pwd and @server variables?

how to concatenate Login, pwd and @server variables ?? ex: export Login_va="Login" export pwd_va="pwd" export server_var="@server" echo whenever sqlerror exit | sqlplus ...
1
vote
1answer
31 views

Bash: Iterating 2 lists using single For In loop

Suppose I have 2 seperate loops for file1 in `ls Dir1/` ; do echo $file1 done for file2 in `ls Dir2/` ; do echo $file2 done I want Single loop to iterate both Directories pseudocode for ...
23
votes
4answers
18k views

How to Execute multiple command using nohup

I need to execute multiple commands using nohup. Each command should be executed after the previous command. I used this command as an example: nohup wget $url && wget $url2 > /dev/null ...
2
votes
2answers
59 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
31 views

How to hide Login/Pwd into shell?

I've a Shell script(.run) that let me to connect into Oracle sql : echo whenever sqlerror exit | sqlplus Login/Passwd@SERVER @"TABLE1.sql" echo 'return code : ' $? I'd like to hide ...
1
vote
4answers
111 views

Split comma separated list ignoring commas within matching {}

I want to split a csv, but ignore any commas within matching curly brace groups, and loop through each of the list members. The code below works great but does not consider commas within curly brace ...
0
votes
3answers
22 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 ...
234
votes
2answers
63k views

Difference between nohup, disown and &

What is the difference between $ nohup foo and $ foo & and $ foo & $ disown
0
votes
2answers
28 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 ...
0
votes
1answer
23 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
20 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 ...
36
votes
5answers
65k views

Script to monitor folder for new files?

How do I detect new files in a folder with a bash script? I would like to process the files as soon as they are created in the folder. Is this possible to do so or do I have to schedule a script with ...
-3
votes
2answers
46 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?
16
votes
4answers
29k views

Pass shell variable as a /pattern/ to awk

Having the following in one of my shell functions: function _process () { awk -v l="$line" ' BEGIN {p=0} /'"$1"'/ {p=1} END{ if(p) print l >> "outfile.txt" } ' } , so when called as ...
1
vote
1answer
36 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 ...
0
votes
1answer
29 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 ...
0
votes
2answers
50 views

command not found error after giving permission to access file using chmod

I've been trying to run a script using chmod. Here's how I tried to execute the script: $ chmod u+x tester $ ./tester ./tester: Command not found. I always get the Command not found error and I'm ...
30
votes
4answers
35k views

How to attach terminal to detached process?

I have detached a process from my terminal, like this: $ process & That terminal is now long closed, but process is still running and I want to send some commands to that process's stdin. Is ...
20
votes
7answers
1k views

How could I remember how to use redirection?

I know what program > /dev/null 2>&1 does. It redirects the output to /dev/null and 2>&1 means to redirect the error output in the same place where the output is sent. My ...
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 ...
-4
votes
1answer
44 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
votes
1answer
51 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 ...
59
votes
11answers
66k views

How do I convert an epoch timestamp to a human readable format on the cli?

How do I convert an epoch timestamp to a human readable format on the cli? I think there's a way to do it with date but the syntax eludes me (other ways welcome).
16
votes
9answers
29k views

Generate random numbers in specific range

After googling a bit I couldn't find a simple way to use a shell command to generate a random decimal integer number included in a specific range, that is between a minimum and a maximum. I read ...
1
vote
1answer
962 views

Shell Script Help - Automatically assign users to group

Recently, I have just started to learn linux and I am currently trying to make a shell script that can automate the task of creating user accounts, assigning them passwords and then assigning them to ...
1
vote
1answer
39 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
49 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
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 ...
1
vote
0answers
34 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
1answer
52 views

How to create an alias for two Git commands that use a parameter? [duplicate]

I regularly have to delete a local and remote Git branch. Therefore, I run the following commands: $ git branch -d feature-branch $ git push --delete origin feature-branch Since I mostly execute ...
0
votes
1answer
34 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
2answers
643 views

How to rename multiple files using find

I want to rename multiple files (file1 ... filen to file1_renamed ... filen_renamed) using command find command: find . -type f -name 'file*' -exec mv filename='{}' $(basename $filename)_renamed ';' ...
88
votes
4answers
77k views

How to get the pid of the last executed command in shell script?

I want to have a shell script like this: my-app & echo $my-app-pid But I do not know how the get the pid of the just executed command. I know I can just use the jobs -p my-app command to grep ...
1
vote
1answer
27 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 ...
13
votes
3answers
3k views

How can I redirect `time` output and command output to the same pipe?

Suppose I have a binary called foo. If I want to redirect the output of foo to some other process bar, I could write ./foo | bar. On the other hand, if I wanted to time foo, and redirect the output ...