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)

83
votes
13answers
34k views

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
3
votes
2answers
118 views

Multi-month view in calendar (cal) in OS X

I am hoping to run some of the commands listed in this article, e.g.: cal -3 which is supposed to show me the last month, this month, and next month. This command does not work in OS X. $ cal -3 ...
-2
votes
1answer
26 views

Copying all same files to one location and changing the file name to subdirectory_filename

I have conf.yml files in different folders as below. /var/loyalty-badge/conf/conf.yml /var/loyalty-level/conf/conf.yml /var/promotion/conf/conf.yml /var/featured/conf/conf.yml Now I want all the ...
0
votes
1answer
28 views

How to capture the output of the strings command? [duplicate]

How do I capture the output of the strings command into a .txt file from the command line?
3
votes
4answers
205 views

Extract paragraph separated with *** using AWK

I have a file like below: blablabla blablabla *** thingsIwantToRead1 thingsIwantToRead2 thingsIwantToRead3 blablabla blablabla I want to extract the paragraph with thingsIwantToRead. When I had to ...
1
vote
1answer
28 views

Upload from shell to HTTP Server

I use scp command to upload file from my local computer to my ftp server is there any tools to do the same thing with http server (like Apache server ) like scp do ?
6
votes
5answers
835 views

Deleting files with spaces in their names

I am trying to delete all the files with a space in their names. I am using following command. But it is giving me an error Command : ls | egrep '. ' | xargs rm Here if I am using only ls | egrep '. ...
1
vote
1answer
29 views

Sorting in reverse numeric order on subfield in a multi-field sort

I'm trying to use GNU sort on a directory/file listing, eg (subset of much longer listing): exams2008/Zoology/Summer/ZY4019Sum08.pdf exams2009/Zoology/Summer/ZY4019.pdf ...
20
votes
9answers
2k views

Find files whose name is 4 characters long

I would like to find files whose name has only 4 characters. Example, there are three files under /tmp: $ ls /tmp txt file linux Output should only show file because it only has 4 characters.
3
votes
4answers
136 views

Touching issue: Creating a filename from 2 variables

I am trying to create a filename from 2 variables. This is the error msg: touch: cannot touch `/root/tinstalls/2--06/06/15': No such file or directory 2--06/06/15 19:54 This is the code: ...
-2
votes
4answers
56 views

How to print last few contents in a line?

I have a file that has lines shown below, ta=/*92/*39/*1/*649/*12 ta=/*92/*12/*4/*342/*90 ta=/*92/*33/*9/*455/*3 ta=/*92/*12/*3/*649/*25 ta=/*92/*99/*7/*649/*7 and so on. I want a file that will ...
2
votes
3answers
193 views

Using sed command to find the first occurrence of the pattern and append

Say there is a text file as below: Hello world types="" Mario types="Game" All I want to do is find the first occurrence of type="" and append with word program My desired output: Hello world ...
2
votes
2answers
73 views

Check if conditional with awk for matches in logfile

I want to check the auth.log file for accepted sshd connections and execute an action if any are found. Here is my code: tail -f /var/log/auth.log | awk '{ if($0 ~ /sshd/ && $0 ~ /Accepted/) ...
0
votes
4answers
91 views

Get process elapsed time in seconds

Similar to How to check how long a process has been running?, I am trying to get the elapsed time for a process in seconds in an embedded Linux system using BusyBox and sh (not bash). The difference ...
15
votes
3answers
784 views

Issue an error when using empty shell variables

Sometimes I use, $PROJECT_HOME/* to delete all files in the project. When the environment variable, PROJECT_HOME is not set (because I did su and the new user doesn't have this environment variable ...
16
votes
15answers
1k views

How to find line with least characters

I am writing a shell script, using any general UNIX commands. I have to retrieve the line that has the least characters (whitespace included). There can be up to around 20 lines. I know I can use ...
3
votes
2answers
172 views

Substitute for loop variable in a string pattern

I am trying to iterate over an array of file names and substitute the file name inside an absolute path. The code is, #!/bin/bash jsArray=(moment.js datatable.js jquery.js jquery.tmpl.js dt_jq_ui.js ...
2
votes
3answers
861 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
18
votes
6answers
4k views

find searching in parent directories instead of subdirectories

I'm nested deep in a file tree, and I'd like to find which parent directory contains a file. E.g. I'm in a set of nested Git repositories and want to find the .git directory controlling the files I'm ...
0
votes
0answers
17 views

Unable to execute root commands using client-connect option openvpn

I'm using the openvpn option client-connect to run a script when a client connects. The scrit works fine when I use simple commands but when I add commands that need root privileges it doesn't work ...
6
votes
1answer
274 views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
0
votes
3answers
167 views

Can a command be executed without a shell?

I am developing a binary executable program command to execute programs and return the output into a text field. The parameters to the command involve the command itself as it would be typed on the ...
1
vote
0answers
32 views

Is there any reason to prefer [[ over [ in bash? [duplicate]

I used to think [ would spawn /usr/bin/test and [[ was a builtin, but apparently, it doesn't: $ strace bash -c " [ -z "$FOO" ] && echo yes " 2>&1 | grep test and $ type [ [ is a ...
13
votes
6answers
3k views

How do I recursively check permissions in reverse?

There's a command, I think it comes with apache, or is somehow related to it, that checks permissions, all the way down. So if I have /home/foo/bar/baz it will tell me what the permissions are for ...
5
votes
3answers
185 views

Assigning exit code to a shell local variable

#!/bin/bash function0() { local t1=$(exit 1) echo $t1 } function0 echo prints empty value. I expected: 1 Why doesn't t1 variable get assigned the exit command's return value - 1?
3
votes
3answers
55 views

Output to stdout works, fails when redirected to a file or a fifo

I have a Wifi antenna and I want to optimise it's position. For that propose I'd like to visualise the current latency in real time. I wrote a one-line script to output the ping latency: lat.sh: ...
5
votes
3answers
14k views

bash: /home/user/.ssh/authorized_keys: No such file or directory

Create a ssh key: $ ssh-keygen -t rsa –P "" Moving the key to authorized key: $ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys bash: /home/user/.ssh/authorized_keys: No such file ...
1
vote
1answer
28 views

Activate PHP commands on login

Everytime I login into my centOS box. I need to run source /opt/rh/php54/enable to be able to run php commands. What do I need to do to my installation for this to work without running this command? ...
0
votes
1answer
586 views

openSuse, not running the cron job

I have created a cron job in the /etc/cron.d/dispatchingEmail_I the permissions of dispatchingEmail_I are the following: -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I content of ...
2
votes
5answers
131 views

Get Comma Delimited List of Initials of Items in Directory?

How can I generate a comma-delimited, case-insensitive list of the first characters of the names of the files and directories in a directory, excluding initial "." items, without duplicates? I don't ...
0
votes
2answers
41 views

sponge from moreutils - what's the difference to shell redirect? useful examples?

> brew install moreutils ==> Downloading https://homebrew.bintray.com/bottles/moreutils-0.55.yosemite.bottle.tar.gz ...
0
votes
1answer
2k views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
2
votes
3answers
35 views

Local `set -e` for functions

Is there such a feature or can it be emulated reasonably easily? I want the same behavior except it should return where set -e would have caused a call to exit.
2
votes
0answers
47 views

Debian 8: Shell “service” command works quietly [closed]

I reinstalled Debian 8 Jessie on my vserver recently. I noticed an anomaly to previous versions: The service command shows no confirmation message anymore. If I want to restart e.g. the ssh service ...
54
votes
6answers
50k views

How do you move all files (including hidden) from one directory to another?

How do I move all files in a directory (including the hidden ones) to another directory? For example, if I have a folder "Foo" with the files ".hidden" and "notHidden" inside, how do I move both ...
1
vote
1answer
983 views

Adding multiple user with shell script on Ubuntu [closed]

Can someone help me in providing me the shell script for creating multiple users on Ubuntu. Password needs to be different for each user. Thanks in advance
3
votes
3answers
37 views

printing a series of characters

My ultimate goal here is to generate a block of text that can be used to test out various fonts at a terminal. I want to generate the file as basically an ascii chart. A series of characters from 1 ...
0
votes
3answers
47 views

Extract value from one file and insert it into another file replacing some other value

I have two files, whose line numbers are not same. But in file1 I want to replace lines taking reference from file2 using sed command. In file1: tid.infno := 72 tid.setnr := 120 (This number 120 is ...
0
votes
0answers
57 views

(noob) script works from root ssh <-> php shell_exec() does not

A nooby2death question: In a vpn project, I generate keys automatically for clients. I do this with a script file containing : pkitool clientNameForKey This line : - does work if I execute the ...
-7
votes
1answer
100 views

UNIX homework question regarding piping output, I don't understand what it's asking?

Basically, I need to come up with a command that sends the contents of a file xxx into a program yyy, then the output is piped to the input of another program zzz, where the output is appended to a ...
2
votes
5answers
9k views

Carriage return issue

I have this in a bash script DAY2="20130605"<Cr> echo "This is yesterday date:"$DAY2"end" Why is the output the following? It seems as though there is a carriage return in DAY2 but where is ...
2
votes
2answers
101 views

passing tmux variable into shell-command in tmux.conf

I'm trying to edit my bottom left status section of tmux. I would like it to show Session: #{session_name} The current maximum length for this string is set at 20 using this setting ...
0
votes
2answers
56 views

What are the exact powers of a superuser? [closed]

What are the exact powers for a super user? Would the have privileges to disable a standard users ls command? For example: If I ran the command: ls And the output I received was: This is a fake ...
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
53 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 ...