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)

2
votes
2answers
28 views

sed replace after matching character

I have to change a properties file containing the property: ro.product.firmware=0.0.1 with a new value that is coming from a function called in a different section of my bash script. I cannot get ...
0
votes
4answers
27 views

How to track/log commands executed on a shell?

Can commands be written to a logfile before they were executed in any shells? I know there is a patch for ssh to log all commands from ssh sessions, but i want to log even commands executed from a ...
0
votes
2answers
27 views

sed replace ;“ content with ';”

I have files that contain ;" and I need it replaced with ';" The following sed command does not work: sed -i "s/;"/';"/g" /root/bashy.sh How can I do this? The solution doesn't have to be sed.
1
vote
1answer
25 views

makefile fails when deleting a file [on hold]

I am trying to write makefile and check - if a folder exist - delete it : BINUTILS_TAR_GZ := binutils-2.25.tar.gz BINUTILS_ORIG := binutils-2.25 BINUTILS_CHANGES := binutils_changes . . . clean: ...
2
votes
1answer
36 views

Get all filenames in a directory created before input date

I have a directory containing lots of files. The output of ls command is -rw-r--r-- 1 nobody nogroup 427494 May 26 13:59 14_20150526065238928590_102.txt -rw-r--r-- 1 nobody nogroup 2113592 May ...
6
votes
2answers
312 views

Why does xargs skip first argument when passing to subshell?

Looking for a way to invoke more than one command in a xargs one-liner, I found the recommendation in findutils to invoke the shell from xargs like this: $ find ... | xargs sh -c 'command $@' The ...
3
votes
3answers
69 views

How can I count the number of times a phrase appears in a file, and format it neatly?

I have a log file I am trying to pull data from. It is formatted like so, and lists when certain modules are checked in and out: 19:50:26 (license_manager) OUT: "certain_module" doej@server.domain ...
1
vote
1answer
27 views

Why does bash try to execute strings in a string substitution?

My script is supposed to take input from a pipe and replace newline characters with commas, using the bash's string substitution: #! /bin/bash read -d -r input echo $input $input=${input//\n/,} ...
2
votes
2answers
28 views

Copying a Parent Directory into a Subdirectory Without an Infinite Loop

For application specific reasons, I need to copy an entire parent directory into a subdirectory. E.g., cp -r ../ tmp/ The problem with this is that it gets stuck in an infinite loop, recursively ...
0
votes
0answers
37 views

ssh system calls and path variables [on hold]

I am confused about the behavior of ssh system calls in my C program. I understand according to man pages that a remote command will not be given access to global path variables. I am trying to use ...
2
votes
2answers
33 views

Extra space with counted line number?

I count the number of lines of my file with this command on OSX: nl=$(wc -l < ~/myfile.txt) Say, nl turns out to be 100. Now, I wish to use the result nl in another command, but weirdly, echo ...
2
votes
2answers
49 views

What allows a command to be typed while the previous command is still running in foreground?

Sometimes I have seen when one program (say A) is running in the foreground and printing its output to stdout, I can type another command (say B), and when I press Enter it is run, even though I had ...
-2
votes
1answer
35 views

Move folder from root of Hard Disk to Current Directory [on hold]

I'm trying to figure out how to move a folder that sits in the root of my disk (what do you call that, home?) to a subdirectory. I am not cd'd to the root (again not sure of the terminology). When I ...
0
votes
0answers
23 views

Run Git Pull from a shell start-up script

I have raspberry-pi that loads a shell script on start up. This script runs a python script 'boot_camera.py' which is found in a repository. I Have a server which sends the raspberry-pi a command ...
0
votes
1answer
21 views

Checking the schedule of a cronjob and doing a conditional check on specific parts

Edit: I managed to solve this myself, I actually deleted my original question as I was over complicating the process slightly, but have since answered it in case others find it useful. RegExp is not ...
1
vote
3answers
45 views

Find a file with the extension .csv in a directory matching a pattern

I have a folder in which I have many subfolders. The Root folder name is allCSV and sub foldername is will be like a_date(s), b_date(s), c_date(s) ... I want a file which is in a_date(s) and ends ...
4
votes
4answers
242 views

grep command not working in conditional statement

I've a bash script that's supposed to go over all the filenames and print them only those that contain a certain letter (let's say it's 'o'). What I've done: command=`ls -l` for file in $command do ...
1
vote
1answer
122 views

How can I combine information of three files to create a fourth one?

I have three csv files, each of them containing the information I need to get a fourth one. I'm describing toy files but the actual ones contain much more columns and rows, still on the same models. ...
4
votes
4answers
142 views

Move files by date into different directory using CLI

I have a large number of pictures from an old hard drive that I'm trying to organize. If I run ls -l, I notice all of these files have a creation date of 2012 or before. Ideally, I'd like to move ...
1
vote
1answer
31 views

Aliasing a command with special parameters [duplicate]

I would like to have an alias for the following code:- g++ *.cc -o * `pkg-config gtkmm-3.0 --cflags --libs`; but I want that when I enter the alias it should be followed by the file name *.cc and ...
0
votes
0answers
19 views

File joining script on android device [on hold]

can be deleted posted a new question
0
votes
3answers
85 views

Concat 1000 files within a directory [closed]

I know we can concat files by cat file [file] [[file] ...] > joined-file. I have directory which contains lots of files. I want to concat all of them. I want to concat 1000 files irrespective of ...
1
vote
1answer
69 views

Which one works faster - regular operators (such as <,>,=) or using (-lt, -gt, -eq)? and why?

Which one works faster - regular operators (such as <,>,=) or using (-lt, -gt, -eq)? and why?
3
votes
4answers
118 views

How to show only the last k columns in ls -l?

I like to restrict the columns shown in ls -l command, by eliminating the first 4 columns. ls -lh shows: drwxr-sr-x 20 gamma alpha 4.0K May 22 13:18 Desktop drwxr-sr-x 3 gamma alpha 22 Oct 6 ...
-1
votes
2answers
48 views

Error in file comparison - awk [duplicate]

I have two files file1.txt, file2.txt. I want to select records which are common to both file1.txt and file2.txtbased on column 2 and column 3 and copy them to out.txt with additional column(column 4 ...
3
votes
0answers
43 views

Bash Script — ffmpeg not being invoked as expected

I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it: ffmpeg -i "${file}" -f flac pipe:1 ...
1
vote
2answers
57 views

Copy .txt files in a certain directory

I have an issue in copying my file in my directories. I have .txt and .jpeg files in a lot of directories, and I want to copy only the .txt files according to the directory. For example, I have this: ...
3
votes
2answers
109 views

When should one use $( ) in defining variables

Some shell scripts I have come across use the following syntax when defining variables: file_list_1=$(echo "list.txt") or file_list_2=$(find ./) I would have used: file_list_1="list.txt" and ...
2
votes
1answer
25 views

What is a “checksum” and how do I use it from the shell?

I've seen on a lot of sites "checksum" hashes to verify the integrity of downloaded files. What are them and how do I use them? Ex: I have a downloaded-file.tar on the current working directory and ...
1
vote
2answers
34 views

Url Decoding shell script

How can I store the url-decoded string in a variable using shell script #!/bin/sh alias urldecode='python -c "import sys, urllib as ul;print ul.unquote_plus(sys.argv[1])"' ...
1
vote
0answers
21 views

Is it possible to create aliases that affect services starting?

Currently I have a custom service that executes java in multiple places. I want to be able to add an option to any executions of java this service will spawn (I'm specifying the error log location, ...
7
votes
2answers
94 views

Keeping history per working directory (cf. per shell session)

Is there a way to make a modern shell's history feature be scoped to a path? My working contexts are split up as paths on the file system, and the pattern of shell activity, such as repeatedly issued ...
9
votes
1answer
102 views

Why is nullglob not default?

In most shells nullglob isn't the default. That means, for example, if you run this command ls * in an empty directory, it will expand the *-glob to a literal ' * ', instead to an empty list of ...
2
votes
1answer
42 views

Return code for curl used in a command substitution

I've script as below :- (edited) httpUrl="http://www.nnin.com" rep=$(curl -v -X POST -d "UID=username&PWD=pass" $httpUrl) status=$? if [ "$?" -eq 0 ]; then echo "Success" exit $status ...
6
votes
2answers
265 views

How can I end a here-document that starts with <<\\$fff?

I was asked the following question in a test on shell scripting at my university, which never gave an answer, and google is of little help. Q: What is the line separator that should be used to end ...
14
votes
3answers
382 views

Prepare answers for questions of a command

Let's say I want to write a shell script that executes just one command. But this command is poorly designed. It doesn't offer any command line options; instead it asks some questions and waits for ...
1
vote
0answers
39 views

Shell Script to change user shell

I am writing a script that would be invoked to change user shell. The basic requirement is that once user gets authenticated (e.g: thorough some web application) the script would be invoked to set the ...
0
votes
1answer
22 views

FDs more than 2, more than (stdin/stdout/sterr)

I think this post is not off-topic.We had three traditional file descriptors in Unix contexts: 0 == STDIN 1 == STDOUT 2 == STDERR But in new articles, blogs, posts, answers, or so on, I read more ...
1
vote
2answers
51 views

Compare three files: lines present in one, but not in the other using column comparison

I have three files file1.txt, file2.txt, file3.txt and they are of same format(same number of columns with same data type). I want to select records from file1.txt which are not present in file2.txt, ...
1
vote
2answers
44 views

Accessing fish functions from perl

In bash I can do: foo() { echo bar; } export -f foo perl -e 'system "bash -c foo"' I can also access the function definition: perl -e 'print "foo".$ENV{"BASH_FUNC_foo%%"}' How do I do the same ...
0
votes
1answer
23 views

Percent Signs for Shell Vars to Remove Extension [duplicate]

for file in *.pdf ; do newname=${file%\\.\*} done I don't understand how the %\.* is removing the file extension, can someone walk me through it.
3
votes
3answers
242 views

Extracting unique piece of text from file with awk, sed or grep

From the output of pactl list sink-inputs, I need to grab the sink input number for VLC. Before that, I'm trying to extract the piece that contains the output for only VLC. All the methods that I ...
2
votes
3answers
68 views

Help with String manipulation in shell

I was writing a shell script to generate a string in a particular format so that it can be used as a input in one of the XML I am working with. Given a input file in the format <attribute ...
3
votes
2answers
57 views

Is it possible to exec some commands in a subshell without immediately exiting afterwards?

I use the fish shell and would like to be able to "source" some shell scripts written with sh-compatible syntax, which fish cannot read. For example lots of software expects you to source some shell ...
4
votes
4answers
217 views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
4
votes
4answers
72 views

Searching file in a directory through bash script

I have written the following code to search all the file names in the current working directory that contain the letter 'f'. for i in * do echo $i if [ $i = "*f*" ] then echo "no" else ...
1
vote
2answers
54 views

Run commands “without” terminal [closed]

Months ago I saw a guy running commands from a small, text-box-like window, showing nothing else other than the text-box for you to write the command. Such text-box would popup by pressing some ...
0
votes
4answers
65 views

Hexadecimal number sequence checker in Linux?

I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an ...
0
votes
0answers
45 views

Shell script to send alert if mount point exceeds 75% [duplicate]

How to write shell script to send an alert if any file-system on server exceeds 75%, in one email notification instead of receiving separate alert email notification for each file-system. I am ...
2
votes
1answer
27 views

Generate SFV file, optimizing hard links

I'm currently running cfv -C -rr to generate a SFV file that contains the CRC32 checksums of all files in all subdirectories. The issue is that because there are so many hardlinks, this process is ...