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)

4
votes
2answers
8k views

How to grep top most frequent error messages in a unix logfile

If I have a file example apache log file How to extract the top most frequent error messages in a unix log file with no timestamps the key is most frequent error message should come on top of the ...
12
votes
5answers
502 views

Find files that contain multiple keywords anywhere in the file

I'm looking for a way to list all files in a directory that contain the full set of keywords I'm seeking, anywhere in the file. So, the keywords need not to appear on the same line. One way to do ...
2
votes
2answers
33 views

Measure execution time of a command including expansion of command substitution

How would I go about measuring the running time of commands that are expanded by the shell? For example: ➜ time sleep $(sleep 3; echo 1) sleep $(sleep 3; echo 1) 0.00s user 0.00s system 0% cpu 1....
-2
votes
1answer
38 views

cmd command gives “command line is too long” [on hold]

I wrote a simple bash script, In that script I just execute a .bat file. That .bat file have only 1 command. This command is also not much long. But while I execute my shell script i got "The command ...
0
votes
0answers
31 views

Run script at startup in linux

I want to run my script at startup of my machine and decided to "echo /opt/script/threshold.sh >> /etc/rc.local".I know there are many other ways to do so,Please suggest which one is better and ...
3
votes
4answers
36k views

Redirecting the content of a file to the command “echo”

I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo? I know I have the commands less, cat, more... but I need to do it with ...
1
vote
1answer
30 views

Initilization script runs twice on SSH

Running Ubuntu 12.04. I have a script that sets up the environment, its run by /etc/bash.bashrc. (It may be set to run by other shell profiles inits, I didn't actually set it up myself) When I Ctr+...
0
votes
0answers
18 views

find lastly zipped file in a directory which has so many zip files [duplicate]

I am trying to make a script in that i need to execute a command which can give me the lastly zipped logfile(ex:my log file is going to be zipped toady so i need to place this file in script.likewise ...
2
votes
0answers
26 views

Umask value isn't reflected after making changes

I changed umask from 002 to 007 in /etc/bashrc and in /etc/profile. After logging as a normal user I run umask, and it displays 0027. It should display 0007, but it doesn't. What should I do? if [ $...
-1
votes
1answer
29 views

issue while running bash script remotely [on hold]

I created below script to take some backup.When i run it locally or by copying it to remote machine it is running fine. But when i ran it like: ssh asuser@isp2876 "bash -s" -- < AdvanceLog.sh ...
2
votes
2answers
1k views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
53
votes
6answers
94k views

How can I test if a variable is empty or contains only spaces?

The following bash syntax verifies if param isn't empty: [[ ! -z $param ]] For example: param="" [[ ! -z $param ]] && echo "I am not zero" No output and its fine. But when param ...
9
votes
5answers
8k views

Check if script is started by cron, rather than invoked manually

Is there any variable that cron set when it's running a program ? If the script is running by cron, I'll skip some parts; otherwise invoke those parts. How can I know if the bash script is started by ...
12
votes
4answers
37k views

sudo over ssh: no tty present and no askpass program specified

I keep getting this error and have tried several ways discussed online to fix this and none are working for me. I have setup SSH keys so when I run 'ssh newton@host.com' it automatically logs me in, I ...
1
vote
1answer
32 views

read the file and assign the values to another file

I want to read the file and assign the values to variables whic is in another file using shell script. For example I have file as "myconf" cli="/opt/Solartis_Monitoring/JON_CLI/bin/rhq-cli.sh" user="...
0
votes
1answer
22 views

how to change colors of my ps1 root terminal permanently [duplicate]

I want to change the colors of root@MyComputer:~#and when i type the ls command show me the result as colors! I write a simple BB code to display what i want: [color=red]root@MyComputer:[/color][...
18
votes
3answers
21k views

Is there a simple command for outputting tab-delimited columns?

E.g. I have a file (produced with echo -e "var1\tvar2\t\var3\tvar4" > foo) that are output as: $ cat foo case elems meshing nlsys uniform 2350 0.076662 2.78 non-conformal 348 ...
23
votes
9answers
21k views

How do I check if a variable exists in an 'if' statement?

I need to check a variable's existence in an if statement. Something to the effect of: if [ -v $somevar ] then echo "Variable somevar exists!" else echo "Variable somevar does not exist!" ...
14
votes
2answers
20k views

How do I unset a variable at the command line?

I have tried the following command to set Proxy on yaourt: export ALL_PROXY=http://proxy.example.com:8080 The question is how to unset the proxy on yaourt? In general, how can I unset the value of ...
11
votes
2answers
33k views

How to alter PATH within a shell script?

I have several projects that require me to change versions of Java/Grails/Maven. I'm trying to handle this with some scripts that would make the changes. For example: #!/bin/sh export JAVA_HOME=/...
28
votes
5answers
37k views

Parenthesis in expr 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?
18
votes
4answers
113k views

how to concatenate string variables into a third?

I need to concatenate two strings in bash, so that: string1=hello string2=world mystring=string1+string2 echo mystring should produce helloworld
10
votes
4answers
370 views

Run command after a certain length of time has elapsed?

If I'm executing a long process, is there any way I can execute some time-based commands? For example, I'm running a really long process which runs for roughly 10 minutes. After 5 minutes, I would ...
1
vote
1answer
167 views

Edit the editor in bash and other shells

Executing the fc builtin causes bash and other shells to fire up $FCEDIT on the last command. Because FCEDIT is a variable, this is inherently customizable. Is it possible to also customize the ...
0
votes
1answer
1k 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 ...
1
vote
1answer
18 views

List names of aliases, functions and variables in zsh

I need a way to list the names (without the body/content/value) of aliases, functions, variables, arrays in zsh. Optimally its behave like compgen: compgen -a # will list all the aliases you could ...
1
vote
1answer
46 views

How do I rename files that have '|' in them?

I am using Fedora 24. I have tried many different ways to do this. I've tried it under a Windows VM with the folder in question as a shared folder. I've tried using the 'rename' command. I've ...
1
vote
1answer
63 views

Why is find not listing matching files when preceded by an asterisk(*)? [duplicate]

On Ubuntu 14.04, 64 bit, I have set /lib/modules/4.2.0-27-generic/kernel/drivers to be my current directory. I intend to search all files having net present as a sub-string. If I search with a regex ...
0
votes
2answers
62 views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
1
vote
0answers
34 views

unable to set GOPATH, but it is set? [on hold]

I cannot set $GOPATH, no matter what! I ran: mkdir ~/HOME/myGOfolder And also copied these two commands to ~/.bashrc and ~/.profile (just in case): export GOPATH="$HOME/myGOfolder" export PATH=$...
2
votes
1answer
43 views

How can I decompress and print the last few lines of a compressed text file?

I have 6 gzipped text files, each of which is ~17G when compressed. I need to see the last few lines (decompressed) of each file to check whether a particular problem is there. The obvious approach is ...
0
votes
2answers
55 views

Why is the default shell on my Ubuntu 14.04 bash?

Some said that Ubuntu 14.04's default shell is dash. Mine is bash. My /bin/sh is dash. I don't remember if I changed the default shell. What is some way to change the default shell? Can I find out ...
3
votes
2answers
68 views

confused with awk and shell variables

I am trying to run a script that uses awk. There is no error it seems, but it doesn't create the file that I want. This is the script: #!/bin/bash echo "Number of domain:" read number echo "Domain ...
-1
votes
1answer
43 views

for loop # usage

I am trying to understand how this piece of code works: for b in `git branch -r`; do git branch --track ${b##upstream/} $b; done In particular, the part where it does ${b##upstream/} I know it ...
2
votes
2answers
145 views

Play subtitles automatically with mpv

Subtitle files come in a variety of formats, from .srt to .sub to .ass and so on and so forth. Is there a way to tell mpv to search for subtitle files alongwith the media files and if it does to start ...
7
votes
4answers
1k views
59
votes
5answers
76k views

What does ` (backquote/backtick) mean in commands?

I came across the following command: sudo chown `id -u` /somedir and I wonder: what is the meaning of the ` symbol. I noticed for instance that while the command above works well, the one below ...
22
votes
1answer
2k views

Is there a way to redirect a program's output and still have it go to stdout?

Okay. If I wanted to redirect the output of a program to a file, I'd do something like this prog > file If I wanted to redirect both stdout and stderr to that file, then I'd do prog > file 2&...
4
votes
5answers
1k views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
2
votes
2answers
53 views

Pass input file through pipe as argument?

I have two issues. I am trying to pass files through a pipe as an argument, and I am trying to use that file as a variable inside the sh function. Here is my command: find . -name 'segment*' | ...
1
vote
1answer
36 views

Formatting issue

I have a small script like below, where output gets highlighted (in red,yellow etc) on screen if there an issue normal=$(tput sgr0) red=$(tput setaf 1) yellow=$(tput setaf 3) df -h >/dev/null 2&...
-1
votes
2answers
35 views

Add another if condition

The following script is working fine. for i in `cat /app/scripts/symantec_scripts/list` do ssh root@$i "uname -n if [ -s /app/Symantec/virusdefs/definfo.dat ]; then cat /app/Symantec/virusdefs/...
0
votes
3answers
96 views

shell script - subtract 1 from hexadecimal mac address and add colons to it

I have mac address as 'C4:B9:83:7F:FF:AC' and I want to subtract 1 from its hex values which is C4B9837FFFAC so it will become C4B9837FFFAB and after this I again want to add colons to make it ...
-2
votes
2answers
9k views

How to delete a file in Arch console?

pacman stopped working and asked me to delete a file if "another package manager isn't working". What is the file for deleting files?
-4
votes
2answers
132 views

z in bash script returns zero [closed]

#[ -z "" ] #echo $? returns 0 #[ -a "" ] #echo $? returns 1 except z all other alphabets throw 1 What might be the reason?
10
votes
2answers
12k views

Printing decimal to ascii character, my command does not output as intended

I wanted to output a string of all the ascii characters with the following command for i in `seq 32 127`; do printf "%c" $i; done The output of the above command is: ...
14
votes
4answers
1k views

Escape sequences in output of script called from ncurses application

I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
-1
votes
1answer
25 views

Is telnet/telnet-server a remote shell?

It is always said to use Secure Shell (SSH) instead of Telnet or rsh/rcp/rlogin, for security reason. SSH and rsh are both remote shells. I wonder if telnet is also a remote shell? If yes, why is it ...
1
vote
1answer
46 views

Better way to apply formula to specific column of inputfile, and pass-through all other columns as-is

I regularly need to apply simple formulas to input data give in textual tabular form. In the beginning, I wrote specific little functions for each use-case. Then I re-factored the "common code" into ...
4
votes
2answers
84 views

How Do I Remove Duplicate Words With Suffixes?

How do I compare a list of unsorted words of variable length and remove duplicate words that have a suffix? Example word list: iron curl curled railroad curler ...