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)

1
vote
2answers
31 views

How to handle backspace while reading?

How do I handle the backspaces entered, it shows ^? if tried & how read counts the characters, as in 12^?3 already 5 characters were complete(though all of them were not actual input), but after ...
3
votes
2answers
31 views

Find all symlinks to a directory and change target to another directory

I have a bunch of symlinks in /home to files and sub-directories in /foo. I want to target the new directory, /bar. My approach was to look at all invalid symlinks and verify that they were pointing ...
1
vote
3answers
36 views

bash/shell pathname expansion for mkdir, touch etc?

So doing something like this in bash and most other shells won't work to create multiple subdirectories or files within subdirectories... mkdir */test touch */hello.txt There are of course many ...
1
vote
2answers
33 views

Why asterisk in command result in for loop is expanding?

I want to write a script that will run git diff --name-status master..<BRANCH> but when I run this: for i in $(git branch | grep -v master); do echo $i; done I get echo one directory ...
3
votes
6answers
70 views

Use a shell not installed on remote machine

Given the scenario: Remote machine: SSH server; user does not have admin privileges; Local machine: SSH client; user has admin privileges. If user, logging in to remote from local, wishes to ...
8
votes
3answers
574 views

What is the usage of $& in bash?

I was looking into special parameters in bash. I am curious to know what is $& and how it is different from $_. I see the following output when running the commands but could not locate the ...
0
votes
1answer
43 views

`command` vs `type` - Locate program file in user's PATH [duplicate]

I need locate program file in user's PATH. I found few solution, the best are command and type. Which is better, faster, UNIX-like way and why? command -v <application> type -p ...
0
votes
1answer
33 views

Quote escaping struggle with grep and sed

I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
1
vote
0answers
30 views

Edit a command? [duplicate]

I'm using many basic commands of unix/linux. In Mac OS X Mavericks, I type cat for a file, but output was faulty. In example, content of the file named bar: foo bar Then: ...
3
votes
1answer
160 views

How does the colon sign and dollar question mark combine in sh?

The "colon sign" and the "dollar question mark" can be combined to check if a sh script does have an argument and assigns it directly to a variable of interest: cmd=${1:? "Usage: $0 ...
3
votes
1answer
24 views

X commands do not start from my at job

I'm learning about Linux scheduling commands including at, cron, sleep etc. I'm trying to launch gedit after x minutes via the at command. This is what I have: kedar@i5 ~ $ at now + 1 minute at now + ...
4
votes
3answers
93 views

Passing arguments from one command into the next

I'm trying to write a script to unify two separate commands I run by hand into a single bash script I can then cron. The first command is a simple find on files with a certain name and size find ...
1
vote
2answers
88 views

Rename a file dynamically containing spaces [duplicate]

I want to rename a file dynamically based on data which contains spaces Name="Abc DEF" Name1="GHI JKL" mv /sample/pdf/noriginalName.pdf /sample/outputPdf/${NAME}${Name1}".pdf" But it gives me an ...
4
votes
2answers
47 views

Inconsistent redirection behavior ssh interactive vs commands

These work, ssh remote 'echo hi > hi.txt' echo hi | ssh remote 'cat > hi.txt' but this does not work ssh remote sh -c 'echo hi > hi.txt' I expected to produce a file on remote named ...
4
votes
6answers
279 views

want the last line when duplicate awk?

I have the file: key value blah blah blah blah blahblah man1 boy1 blah blah man1 boy2 man1 boy1 I do this to remove duplicate lines: awk '/man1/ { print $1,$2} ' file | awk '!x[$0]++' and the ...
-2
votes
0answers
22 views

Shell script working like rasdial in windows [closed]

I want a shell script that works like rasdial in windows. I dont where to start. Even a lead will do.
-2
votes
0answers
29 views

unexpected end of the file error [duplicate]

APP_FILE="/opt/tomcat/apache-tomcat-6.0.20/webapps/vold1/name_file.txt" IPFILE="/opt/tomcat/apache-tomcat-6.0.20/webapps/vold1/ipaddres_file.txt" ...
1
vote
1answer
16 views

How to delete older files in a folder in unix?

Can anyone help me find the meaning of the below statement? I am new to Unix programming. find /sourcedirectory -mtime +2 -exec mv "{}" /destination/directory/ \;
14
votes
5answers
1k views

Parenthesis in bash arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
-3
votes
2answers
25 views

how to take the file names from folder

i want to write a program for the below logic: Take the names of files in a folder For each file: print file name move the file to another new folder (with the name in dd_mm_yy format)
6
votes
4answers
300 views

Send SIGINT to child process of shell, simulating CTRL+C (Linux)

Given a shell process (e.g. sh) and it's child process (e.g. cat), how to simulate the behavior of CTRL+C using the shell's process ID? This is what I've tried: Running sh and then cat: ...
0
votes
3answers
34 views

store the command output in an array and print one by one

This is my command: cat httpd.conf | grep ^LogFormat | awk -F\" '{print $(NF)}' Output of this: commonsess common or can be any number of values, I need to store these values in an array and ...
0
votes
2answers
33 views

Command substitution in Shell Script

511@ubuntu:~/Unix$ cat pass hellounix file1 #!/usr/bin echo "Enter File Name" read file if [ -f $file ] then echo "File Found with a Name $file\n" echo "File Content as below\n" count=0 ...
5
votes
3answers
220 views

Sorting ls output by time, when there are too many files for a single invocation

I know that I can sort the output of ls by time with the -t option. I know that when I have so many files that they don't fit in a single ls invocation, I can normally use xargs (or find ... -exec ...
0
votes
3answers
90 views

What does running “< ./somefile.txt” in shell do?

So I just executed < ./somefile.txt in a shell, and it doesn't appear to do anything (the text file has valid linux commands). So where are the contents of the text file being redirected to? I'm ...
0
votes
0answers
24 views

How to make the process run after closing the session [duplicate]

I have started a process in Linux without a terminal multiplexer like screen or tmux, without nohup. Now I want to logout from my remote ssh session without interrupting the execution of that process. ...
0
votes
1answer
30 views

Backing up files which were modified after the last backup was run

I am working on a backup script (bash shell - Fedora - VMware) that should compare a file with last modified attribute and current date and should back it up if the last modified date is older than ...
1
vote
1answer
30 views

How to assign words with spaces as a whole name to variable in shell script? [duplicate]

I need to make some directory of Author name. It's easy when doing them alone. I can simply mkdir "Mario Luis Garcia" This will create one directory named "Mario Luis Garcia" But when trying do it ...
2
votes
1answer
71 views

How to check whether a particular port is opened on a machine from a shell script and perform action basis on that?

I am running my below shell script on a machine on which c++ application server is running on port 8080 and in the shell script I am executing an URL and stores the response coming from that URL in ...
4
votes
1answer
112 views

command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory

I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
2
votes
3answers
48 views

Copying all files from one directory to all directories under same parent directory

I have one parent directory /home/test and under that directory I have multiple directories. The names are server{1..10} and one of them server3 has few files which I have copied from remote server. ...
8
votes
4answers
1k views

Why is the 'if [ $1=“1” ]' branch always selected even if $1 is not 1?

I have a shell script named 'teleport.sh' like this: if [ $1="1" ]; then shift mv "$@" ~/lab/Sun elif [ $1="2" ]; then shift mv "$@" ~/lab/Moon elif [ $1="3" ]; ...
1
vote
1answer
27 views

Can you further integrate and present sequential moreutils vipe command output in vim using successive splits etc?

I have used the moreutils suite a few times and I find it makes you think further about base utilities and is insightful(and fun). For instance, vipe allows running an editor - like vim - in the ...
0
votes
2answers
36 views

Getting expr: syntax error on index [duplicate]

Using this OF=$(ps fax | grep 'php-fpm: master process' | awk '{print $1}') IDX=`expr index $OF ' '` I get an error. The results of the $OF variable are: 27797 27495 What is the error here? I ...
3
votes
1answer
27 views

Can I make “less” execute arbitrary commands with a single key sequence?

The crux of my question is stated in the title. Reading the less and lesskeys manpages, I have created a file containing: ^B shell touch ~/testfile and run it through lesskey to generate ...
11
votes
3answers
548 views

How to undo `set -x`?

I typed set -x in terminal. Now the terminal keeps printing the last command run on top of my output so the command ~]$echo "this is what I see" returns + echo 'this is what I see' this is what ...
2
votes
1answer
65 views

Why does `cp -a . /dir` copy contents instead of directory?

I wanted to copy a directory that I was presently in. I tried cp -a . ~/xyz It copied the contents of the directory, yet this worked: cp -a "$(pwd)" ~/xyz [As desired, this copied the directory ...
1
vote
3answers
47 views

Why is ls command slow to interrupt on NFS directory with lots of files?

I noticed in directories with lots of files on NFS if I do ls * then hit Ctrl-C it can take a while ( say 20 seconds ) before ls comes back. Why? Can ls command be fixed to be more responsive?
0
votes
2answers
25 views

moving a process to fg and bg [duplicate]

Suppose I run a process in the background likw ./script &, I can bring it to foreground by running fg. However, is there a way to move it back to background without stopping it (as in ctrl+z) or ...
1
vote
3answers
72 views

How to get a response from any URL?

I have been asked to write a shell script To check if a URL is UP/Working or not for my Project. I tried to find some hints over the internet, but whatever I got is about checking whether the URL ...
3
votes
5answers
232 views

How to use a shell variable inside sed's s command? [duplicate]

we know that we can get the value of a variable using $ sign: x=3 echo $x 3 Is there other ways that we can use to get the value without using $ sign. I'm asking this because $ sign is a special ...
2
votes
5answers
40 views

Append files with bash one-liner?

Currently I use multiple lines to append content into a combined file, e.g. ./myprogram 1.txt > Out.txt # Overwrite for the 1st file ./myprogram 2.txt >> Out.txt ./myprogram 3.txt >> ...
1
vote
1answer
81 views

Canot remove symlinks: after reboot, symlinks re-appear

Using ssh from BusyBox, I cannot remove symlinks: after rebooting the device, symlinks re-appear. ls -la shows that symlinks have been removed, but after rebooting device they re-appear again. Those ...
3
votes
1answer
36 views

Escape closing parentheses from URL with firefox -remote

I have this command (for detailed info see Shortcut to google selected text): sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(xsel),new-tab)"' But when I select a text which ends ...
-3
votes
1answer
38 views

to run script over several folders? [duplicate]

Currently I have a script that can run only in a single folder. #!/bin/bash for file in ls -1 *.jpg|sort -t . -n -k 3 do echo "compute ./scripName $file" ./scriptName $file done Question: I ...
0
votes
2answers
39 views

Determining the exit status of the “return” built-in

I was reading about traps, but only return works for me in my shell script, so was wondering what status or code it returns, so what I tried is, #!/bin/bash seeOutput=`return` echo $seeOutput It's ...
0
votes
0answers
41 views

Cant ssh, connection terminates immediately with exit status 254

The most recent thing I remember is changing the soft and hard memlock ulimit to unlimited. Now I cant ssh into the machine. This is the ssh log. Authenticated to IP ([IP]:22). debug1: channel 0: ...
6
votes
2answers
175 views

How many commands can be queued up with control operators?

I have been reading up on control operators, and I was wondering if there was a limit to how many commands you could line up with control operators, such as ||, && and ;. In addition, is ...
1
vote
1answer
16 views

What standard shell command can evaluate escaped Unicode in a stream?

I'm looking for a pipeable command that will convert substrings in the form of ‘\unnnn’ to the actual characters. For example: $ echo 'co\u00ebfficient' | what_command coëfficient
1
vote
1answer
33 views

Compare file size of multiple files in an array [closed]

Scenario: Ftp site has 100s of files. Once a day, all the .gz files are copied to an AWS site then renamed. Only the date is kept in the file name. Some of the files corrupted during copy. A txt ...