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
5answers
761 views

How to split a file based on information within a column in linux

I would like to separate those rows where the value in second column is smaller than a specific value. example input: id1 19501112 id2 19831207 id3 20001212 id6 20000101 id10 20061213 id11 20081212 ...
1
vote
1answer
54 views

Specify a starting point for unix find and replace, then increment

I'm doing a renumbering of a reference attribute in an xml file. The attribute is, for example, data-seq="1". I can already renumber that attribute in all files by using this: find $DATA_PATH/content/...
3
votes
1answer
163 views

Sending sigaction / sigqueue through shell

I have a c++ program that handles several signals to perform different actions, using signal: signal(SIGHUP, signal_handler); I wanted to extend this signal handling to allow me to send ...
-1
votes
1answer
36 views

What is the effect of a lone backtick at the end of a command line?

I accidentally typed in cd ` into terminal today and terminal didstrange things. It put a "> " signed on the next line followed by my cursor like it wanted some input. No matter what I entered ...
2
votes
3answers
1k views

Get script to run again if input is yes

I am putting together a simple file handling script, its all working nicely except at the end , I want it say do you want to perform another action and if the answer is yes then I want the script to ...
1
vote
1answer
122 views

Block user input on interactive shell using “cat /dev/ttyS0”

I created an update routine for my device. The update process can be started using the serial console, SSH, telnet, a webserver or a REST API. Once the update started, I want to block all user input ...
-2
votes
1answer
79 views

How to solve the defining variables in bash prompt command not found the problem

My Linux distributions centeros7, define variables on the bash prompt command not found [wanghao@localhost ~]$ al = nihao bash: al: command not found... [wanghao@localhost ~]$
0
votes
1answer
62 views

Why is the redirection of loop output dependent on the filename?

I have two files: a.csv and b.csv: echo $'a_header\na1' > a.csv echo $'b_header\nb1' > b.csv Now I want to remove the first line from each, and concatenate them. for file in `ls *.csv`; do ...
18
votes
2answers
2k views

What is the difference between * and *.* while copying?

What is the difference between following 2 commands? cp -rp /dir1/*.* /dir2/ cp -rp /dir1/* /dir2/
1
vote
2answers
273 views

How to start script and put standard input in one command?

I have a console program which uses standard input and output. For example I call : ./program_name and after that I enter input I need to make this two actions in one command like: ./program_name '...
0
votes
1answer
66 views

Why can't I `rm -r .`? [duplicate]

A question I already asked myself a few times is why I can't delete the current working directory using rm -r . The shell does not have a problem with a non-existing directory as working directory, ...
1
vote
1answer
216 views

Storing part of command line arguments into user array

I am able to do this, array=(2 46 7 4 2 1 1 1 23 4 5) store=(${array[*]:5:5}) echo ${store[@]} # print 1 1 1 23 4 5 Now instead of extracting the 5 elements from position 5 from a user array, I ...
2
votes
4answers
216 views

how to delete a header without deleting other rows in linux?

I have a huge data file.txt looks like : calls... 12311 34213 13344 12345 34532 23345 24445 22445 12344 12333 34456 22211 12334 12234 23344 23345 24445 22445 12344 12333 which I want to delete ...
0
votes
4answers
128 views

Append the result of word count to the end of a file

I want to count the number of lines in example.txt and append the result to the end of this file. How can I do this? I tried: wc -l > example.txt
0
votes
1answer
107 views

Automatically enter in bash shell

I just got an VPS in GoDaddy, and when I connect using ssh, it enter in a simple shell, so I need to type "bash" to enter in bash mode. Why this happens? I had another VPS in DigitalOcean and it ...
1
vote
2answers
203 views

Shell's process group ID = foreground job's process group ID?

I decisively conclude that Shell's process group ID = foreground job process group ID from the 2 sources below. When a background job is selected to run in the foreground, is it the shell's process ...
0
votes
1answer
67 views

Check if two lines start with the same character, if so the output average, if not, print actual value [closed]

I'd like to check if two rows start with the same number in the 1st column, if that happens, then the average of the 2nd column should be displayed. File example: 01 21 6 10% 93.3333% 01 ...
0
votes
1answer
26 views

Auto launch a program on login for Raspbian or Debian

I am making a application on the Raspberry Pi, and I want it so if you login to the Pi directly, or through SSH, it will launch this application. This application is made to only work in the ...
27
votes
3answers
1k views

Official list of programs to be included in Linux?

Is there a standard that I can refer to for the list of programs (e.g. cat, ls) that must be included in Linux?
0
votes
2answers
67 views

Grep for string but ignore commented out items with string

I'm looking for the words gmail or outlook in a directory. Although there are some lines commented out with the word gmail and outlook in it. How can I grep for this? I tried a bunch of things but I ...
2
votes
2answers
483 views

Can't run aplay as root!

Not that I need to aplay as root but it came across me and I wondered why it shouldn't work. # aplay /home/bibek/apert.wav XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid ...
1
vote
3answers
80 views

How to undo typo `set -ovi`?

I wanted to execute set -o vi, but instead I did set -ovi. Now when I checking set -o I see extra weird options such as: $ set -o set -o ... update_terminal_cwd; and as result, ...
2
votes
2answers
54 views

Shellcheck complains that I should not to read and write the same file in the same pipeline

ShellCheck show the following error for this line of code: printf '%d' $(($(< "$1") + 1)) > "$1" Make sure not to read and write the same file in the same pipeline Is this really a problem? ...
1
vote
1answer
255 views

notify-send doesn't work from script but works from terminal

I am trying to run this script: test.sh #!/bin/bash BAT_LEVEL=`acpi -b |grep -Eo "[0-9]+%"|grep -Eo "[0-9]+"` CRIT=0 if [ $BAT_LEVEL -gt $...
1
vote
1answer
30 views

How do I access an item of an array in shell?

I am using terminal with MacOSX. I am new to shell and I need to do something with array. I read this entry introducing about unix array. I tried to access an array as its way, but failed: a=(1,2) &...
0
votes
3answers
320 views

How to extract a particular value from log file and transfer it to another file

I have a log file which looks like: ########### mv90_poll.sh started Wed Sep 23 02:36:00 PDT 2015 ############ /usr/mv90/mv90/system/*.di not found list *.HHF files in /usr/mv90/fats -rw------- 1 ...
0
votes
2answers
47 views

Remove leading 10-digit number from filenames

I have thousands of image files that have a 10-digit number appended to the beginning of the filenames. Immediately following each string of 10 numbers is an underscore. They look like this: ...
2
votes
3answers
60 views

Listed Frequency of Different Strings in a Particular Column

So I'm fairly new to linux, and needed help figuring out how to find how many times a particular string shows up in column 4. This is my data: 25 48656721 48656734 FAM132B ENSCAFT00000019683 4 0.51 ...
2
votes
2answers
1k views

pipe stdout-to-file with wc

I'm working on a lab assignment for a class, which exemplifies users | wc -w as displaying the number of users currently logged in. The instructor has asked we write the output of users to a file (...
18
votes
7answers
1k views

Search for a previous command with the prefix I just typed

We can use up and down arrow to navigate in command history. In some IDE, such as matlab, if we input sth and then press the arrow keys, we stroll among only the history commands starting with what ...
1
vote
1answer
30 views

Some confusion about the working mechanism of ~/.bash_history

I'm confusing about the content in ~/.bash_history when I worked on several terminals. How does it work on saving the history in different terminals?
2
votes
1answer
70 views

Check for related file names and delete one of them

I need to write a script that will find files that contain a string in their name. If a file exists that is the same name but without that string, I want to remove the original file. For example, if ...
1
vote
1answer
538 views

Set variable inside heredoc, use variable outside heredoc

I've got the following in a bash script ssh -T -i ${ssh_key} ${ssh_user}@${host} <<- 'EOF' file=`hostname`.tar.gz echo "file: " $file ### prints>> file: some-host-name.tar.gz EOF ...
0
votes
0answers
323 views

Gtk-WARNING **: cannot open display: :0

I'm on a Gnome 3.16 session. If, from gnome-terminal I try to open any GTK+ application, like this for example: $ gedit I get this, and the App won't open: (gedit:29695): Gtk-WARNING **: cannot ...
-1
votes
1answer
51 views

How to print the last X lines that contain the string Y? [closed]

I know how to do these tasks individually using tail and egrep, but confused on how to nest them together
1
vote
2answers
60 views

xargs repl_str doesn't expand second placeholder

I would like to rename some files and exclude others into a directory. I tried find . -mindepth 1 -maxdepth 1 ! -name 000-default.conf ! -name default-ssl.conf -print0 | xargs -0 -I {} sudo mv -- {} $...
1
vote
2answers
340 views

Fish Shell: How to set multiple environment variables from a file using export

Is it possible to set environment variables with export in Fish Shell? I am working on a project that configures variables this way and it does not make sense to maintain a separate configuration ...
2
votes
1answer
272 views

Rsync backup script for multiple servers

I have simple script that backing up data from remote server via ssh using rsync. I have external config file for that. In this config file I have variables: OPTIONS, REMOTE_IP, SOURCE and ...
0
votes
3answers
207 views

find number of files that I can both read and write

How would I count the number of files in a given directory that the current user has read permissions and write permissions on ? I am starting with: echo "whats the directory you want to check ?" ...
2
votes
3answers
253 views

How to find out the process(es) that forks a lot?

Recently I got an load-too-high issue on our server. I watched top for like half an hour to find out that it was Nagios that forked a lot of short-lived processes. After bouncing Nagios, everything ...
1
vote
2answers
71 views

Is it safe to run these instructions as a root user?

I have CentOS and I want install scala by: Installing scala on CentOS. I want to ask if it's safe installing this as root user? The commands are: wget http://www.scala-lang.org/files/archive/scala-...
2
votes
1answer
66 views

Script to mail PDF files [closed]

It's a wrong question..please delete itn
3
votes
3answers
177 views

fish: whitespace in alias

I am trying to alias an executable in a directory with a space in it. For example: alias myfile="/home/ben/test case/myfile" Now, this is not expanded the way I want (it thinks /home/ben/test is ...
0
votes
3answers
43 views

Run several commands together, finish if one of them exits?

I have several commands that I run continuously during development of my website - Django development server, SCSS->CSS compiler in "watch" mode and so on. I want to have a convenient command to run ...
0
votes
1answer
249 views

curl and wget cut off url

I have a web cms that allows so called action IDs which are urls. When you hit those, they perform some code in the cms. So I wanted to perform an action periodically and used cron for that. PROBLEM: ...
2
votes
1answer
146 views

Background vs foreground task and running tasks in parallel

Since I'm new to Linux, apologies if I'm not using the correct terminology. I'm trying to run a number of tasks in parallel (using the background shell operator). However, I need to first run two ...
0
votes
2answers
63 views

Problem with data comparison in if loop

I have 2 variables in bash. Using test i found out that one of them is integer and other one is string. I want to compare them and see if they are equal. I tried the following options. if [ "$a" -eq "...
3
votes
5answers
683 views

Why is Terminal automatically entering my command after pasting text?

This happens whether I use ctrl+shift+v or paste from the right-click menu. How do I make this behavior stop?
3
votes
2answers
70 views

How to format a file while moving?

I have 2 directories. SOURCE and DESTINATION. I am moving the .csv files from source to destination as mv -f SOURCE/*.csv DESTINATION/ While moving, I want to remove the first and last line from ...
0
votes
0answers
15 views

sorting files using header information [duplicate]

I have multiple image files inside a directory having the same extension (.mrc). In the terminal, if I do, header , it gives following output: RO image file on unit 1 : ...