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
1answer
39 views

How to use output from openssl encryption routines in a pipe?

openssl manual claims that openssl enc uses standard output by default. But something is not right with the standard output when decrypting a file. Piping the output to any application such as grep, ...
5
votes
3answers
187 views

How to display commands in a different terminal?

I have a raspberry pi with a screen attached to it. It boots up to a login prompt. I have no keyboard and no mouse attached to it and would like to keep it this way. I proceed to login to it via ssh ...
1
vote
2answers
56 views

Rename file containing spaces and punctuation marks

Someone in our Global Linux 3.0.31-0.9 server has put a file with several spaces, parenthesis, question mark and a colon in its name. And I am at my wit's end to rename or remove it! Sample of the ...
3
votes
3answers
93 views

How to set HOSTNAME in zsh?

In bash, which sets $HOSTNAME for you, I was able to calculate the total length of prompt line simply by using something like: PS1_length=$((${#USER}+${#HOSTNAME}+${#PWDNAME}+12+${#PS1_GIT})) It was ...
0
votes
2answers
44 views

Adding a new directory to PATH vs. a symlink for directory already in PATH

In setting it up so I could execute Sublime Text from bash, I discovered two methods of doing this via different tutorials: Method 1) Create a symlink from /usr/local/bin/subl to Sublime's bin dir: ...
7
votes
4answers
623 views

Why doesn't SIGKILL terminate a stopped program (yes)?

I'm using Ubuntu 14.04 and I'm experiencing this behavior I can't seem to understand: Run the yes command (in the default shell: Bash) Type CtrlZ to stop yes Run jobs. Output: [1]+ Stopped yes ...
-3
votes
1answer
68 views

What command would I issue in order to complete this question?

So I have tried over 10 different attempts and I'm just stumped Here are two inverted-tree diagrams. Issue a command to change the left diagram to the right diagram. Assume that you are in your home ...
1
vote
1answer
58 views

piping commands after a piped xargs

HP-UX ***** B.11.23 U ia64 **** unlimited-user license find . -type d -name *log*|xargs ls -la gives me the directory name(the ones which contain log in the directory name) followed by all files ...
1
vote
4answers
74 views

Unix bash/ksh : Selection of first non space character from file from specific line

I have file file1.txt whose contents are as follows: Date List ----------- Quarter Date Year Date Month Date Now I want to read the non space elements from each row of ...
1
vote
1answer
52 views

Recover deleted commands from history?

If someone were to delete commands from the shells history, is there any way to recover those deleted commands in Linux?
5
votes
8answers
469 views

How do I delete the first n lines and last line of a file using shell commands?

I have a file named Element_query containing the result of a query : SQL> select count (*) from element; [Output of the query which I want to keep in my file] SQL> spool off; I want to ...
0
votes
0answers
19 views

Setting X display giver no protocol error [duplicate]

Here is the command i use DISPLAY=:0.0 sh /var/log/show_report.sh & disown This shell script just invokes the browser and here is error i receive No protocol specified Error: cannot open ...
2
votes
5answers
266 views

Bash script: check if a file is a text file [closed]

I am writing a menu based bash script, one of the menu options is to send an email with a text file attachment. I am having trouble with checking if my file is a text file. Here is what I have: ...
1
vote
1answer
40 views

TTY control characters sent to stdin of sh doesn't work

I tried to develop a remote app that launches sh and resends an incoming data there, and found that some special sequences don't work. So, for testing purposes, I launched on my desktop sh, then ...
0
votes
1answer
29 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?
1
vote
1answer
29 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 ?
1
vote
1answer
31 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 ...
3
votes
4answers
206 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 ...
-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 ...
-2
votes
4answers
57 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
2answers
76 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/) ...
2
votes
3answers
194 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 ...
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 ...
0
votes
4answers
93 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 ...
3
votes
2answers
174 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 ...
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 ...
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 ...
6
votes
5answers
849 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
31 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? ...
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: ...
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
5answers
133 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 ...
2
votes
0answers
48 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 ...
5
votes
3answers
191 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?
0
votes
2answers
42 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 ...
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 ...
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.
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 ...
0
votes
2answers
57 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 ...
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.
0
votes
2answers
59 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-- ...
-2
votes
1answer
21 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
109 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 ...
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 ...
-1
votes
1answer
76 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'; ...
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
3answers
76 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 ...
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
55 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 ...