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
0answers
11 views

In UNIX, how do I send a file back to it's original location after outputting it somewhere else?

If I send a file into a directory using an output, is there a way to bring that file back to it's original location using a shell script?
7
votes
6answers
2k views

Serialize shell variable in bash or zsh

Is there any way to serialize a shell variable? Suppose I have a variable $VAR, and I want to be able to save it to a file or whatever, and then read it back later to get the same value back? Is ...
0
votes
0answers
19 views

Run sh script at system startup - Red Hat 7.2

I searched in the internet but there are too much diferent opinions about this issue. I have two scripts to run. One to run at system startup (not at system reboot as I read in some posts) and other ...
0
votes
1answer
45 views

What is the meaning of xargs show limits output

You can use xargs to discover limits about the commandline you're using: $ xargs --show-limits Your environment variables take up 1901 bytes POSIX upper limit on argument length (this system): ...
2
votes
1answer
9 views

possible for mpv to find subtitle files by itself, something in config files?

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 ...
5
votes
7answers
9k views

Sort the files in the directory recursively based on last modified date

Sort the files in the directory recursively based on last modified date I have modified a lot of files in my directory want to know what are those files by sorting them by the last modified date ...
2
votes
2answers
42 views

Delete directories that contain a certain file

I want to find all directories that contain a certain file and then delete those directories. With find . -name thatcertainfile -execdir pwd \; I get a list of all the directories I want to delete, ...
7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
25
votes
13answers
10k views

Remove duplicate $PATH entries with awk command

I am trying to write a bash shell function that will allow me to remove duplicate copies of directories from my path environment. I was told that it is possible to achieve this with a one line ...
0
votes
0answers
9 views

Delay in writing hexdump data to a file

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from my serial port and the data is received with a delay of 3 minutes. ...
8
votes
4answers
524 views

Bash program not executed if redirection would fail

In bash, I notice that if a command using redirection would fail, any programs which run prior to that are not run. For example, this program opens the file "a" and writes 50 bytes to file "a". ...
-1
votes
4answers
45 views

How to filter the table names from .txt file [duplicate]

select * from emp; select * from dept; selection end; I want to obtain this output: select * from emp; select * from dept; I tried by using: awk '/select/{a=1} a; /;/{a=0}' ...
0
votes
2answers
48 views

What's the difference between using shell command (e.g. foo) directly and using $(foo)?

I get confused about using command directly and using $(foo). I'm using Mac, I try to list apps which is install by brew cask(a package manager), and echo each app. I have two short Shell scripts, ...
2
votes
3answers
565 views

Remove BS and ESC from Log files

Whenever I use the script command to record the keys I type or when I activate the logging mode in screen, all BS (Backspace) and ESC (Escape) key presses are also included in the file. e.g: cd ...
2
votes
4answers
92 views

How to delete a tilde (~) folder? [duplicate]

I need to delete a "~" folder in my home directory. I realize now that rm -R ~ is a bad choice. Can I safely use rm -R "~"?
8
votes
4answers
9k views

Why doesn't grep using pipe work here?

I have the following command: find / -name libGL.so.1 Which returns lots of lines with "Permission denied". I want to exclude such lines, so I added the following: find / -name libGL.so.1 | grep ...
1
vote
1answer
111 views

check if genisoimage is succesful

I use a script to convert all VIDEO_TS directories to .ISO. How can I check if genisoimage is actually converting it instead of it failling and converting the next folder? After conversion I have a ...
4
votes
2answers
226 views

Is there a way to have a function in my bash script auto run on any command error?

I'm writing a shell script that needs to do a bunch of commands and every command depends on every previous command. If any command fails the entire script should fail and I call an exit function. I ...
2
votes
1answer
1k views

broken pipe error with popen and JS ffi

I am using a ffi for nodejs which for the most part has nothing to do with this question which is really about understanding pipes better, but does offer some context function exec(cmd) { var ...
2
votes
2answers
237 views

Error message on terminal despite using 2> symbol

Why does this command show error message despite using 2> symbol? cat < foo 2>bar bash : cannot open foo : No such file or directory
1
vote
4answers
3k views

How do I suppress error messages from cp?

I am currently looking ways to suppress error command in Linux, in particular, the command cp. I do: root@ubuntu:~$ cp /srv/ftp/201*/wha*/*.jj ~/. cp: cannot stat `/srv/ftp/201*/wha*/*.jj': No ...
1
vote
3answers
35 views

Elegant way of counting how many times patterns from a file occur in another file

Imagine that we have two for example files. The first file is filled with unique names of employees created by combining the first two characters of the first name and the last 2 characters of the ...
7
votes
2answers
4k views

How to trigger error using Trap command

I am using Ubuntu 12.04.2. I am trying to use "trap" command to capture abnormal or error in my shell script but I am also trying to manually trigger "Error" exit. I have tried exit 1, but it won't ...
2
votes
2answers
343 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 ...
3
votes
1answer
52 views

Shell script - Couldn't find 'fi' for this 'if'

I have found this error alongside couple more. I believe that the nesting is not quite all right or the for is not correctly indented or without some semicolon. Either way I have tried for quite some ...
0
votes
0answers
18 views

redirect all errors of my script into errors.txt [duplicate]

I need to redirect all errors into other file which called errors.txt. This is my script shell : data_in=$1 fichier=$2 cd $data_in #Purge des fichiers rm -f Split/INIT_ENC.dat rm -f ...
14
votes
6answers
2k views

Why there is such a difference in execution time of echo and cat?

Answering this question caused me to ask another question: I thought the following scripts do the same thing and the second one should be much faster, because the first one uses cat that needs to open ...
79
votes
1answer
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
16
votes
12answers
3k views

“Bookmarks” for bash

Navigating several layers of nested directories is often a pain. On Firefox, it is easy because they have bookmarks. So what I'd like to do to bookmarks a file is to type: $ go --add classes ...
0
votes
0answers
16 views

Script generating dummy file with same content of my script while running my script [on hold]

I have a script (bit huge, so I could not post here). When I run the script: sh /home/user1/myscript.sh It generates a file named 1 (or sometimes ?). If I open the file with: vi /home/user1/1 # or ...
2
votes
1answer
19 views

Unable to redirect stdout/stderr to log file [duplicate]

I have a script tmp.sh #!/bin/bash echo hello sleep 3 echo 3 I want to log the script running time (as well as script stdout) to a log file. user$ time ./tmp.sh >& log.tmp real ...
1
vote
2answers
43 views

cd to original location when recording session with “script” command

I have script log.txt in my bash profile; that creates a new sub process and records my entire session to log.txt. When I press cmd+t to open a new terminal usually this will open one in the same ...
0
votes
1answer
59 views

grep with variable in a variable

I want to filter the svlog file by date and split the result by the space, so when i enter the date, it didn't work for me, please refer to the script that I wrote below, the problem was in this ...
1
vote
3answers
69 views

Is it safe to disable shell access to all users listed in /etc/passwd?

I have just read about how to disable shell access for users in Ubuntu in this post for security reasons. Is it safe to disable shell access to all users listed in /etc/passwd except the root:x:0:0 ...
4
votes
2answers
176 views

Running several times the same command with several arguments after a pipe

I have a key (of random binary data) that gets generated by get_key. And with this key, I can do several things with my encrypted files. For example, I can decrypt them. get_key | tee >(decrypt ...
70
votes
8answers
74k views

What's the difference between /sbin/nologin and /bin/false

Technically, unless pam is set up to check your shell with pam_shells neither of these can actually prevent your login, if you're not on the shell. On my system they are even different sizes, so I ...
0
votes
2answers
42 views

How to convert indentation style in a project directory

First of all I am not sure that this is the place to ask this question. I am a web developer working on a medium sized team. We follow the same coding style using Lint/Hint tools. It happens ...
0
votes
1answer
39 views

How to find the parent of a file by inode

I want to use ntfsundelete to maintain the directory structure of the recovered files. The output of ntfsundelete is like this: Inode Flags %age Date Size Filename 191321 FN.. ...
17
votes
6answers
56k views

How to append date to backup file

I need to make a backup of a file, and I would like to have a timestamp as part of the name to make it easier to differentiate. How would you inject the current date into a copy command? ...
15
votes
5answers
59k views

Appending current date to filename

I'm trying to append the current date to the end of a file name like this: TheFile.log.2012-02-11 Here is what I have so far: set today = 'date +%Y' mkdir -p The_Logs & find . -name The_Logs ...
-1
votes
0answers
40 views

backup script for apache [on hold]

I got Apache installed on my CentOS and I'm trying to do the following as a routine checkup every time I run the script, which I will set up with cron. How can I fix the bash script? Task: 1st ...
-1
votes
1answer
34 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 ...
0
votes
1answer
26 views

Why does Grave operator changes output format of the command? [duplicate]

Hello i want to ask why when i write ls -l there is new line after every row but when i assign it to a variable myVariable=`ls -l` and than echo that variable echo $myVariable i get ...
1
vote
1answer
43 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
2answers
25 views

Having trouble deleting specific directories within a specific parent directory

I’m using Amazon Linux, bash shell. I’m trying to write a statement that will delete all child directories named “target” within a specific master directory. I would like to write things such that ...
0
votes
0answers
27 views

What is the meaning of :- in unix? [duplicate]

Trying to understand the existing script where they have assigned ${3:-} to variable. Script : partition_parameter=${3:-} if [ -z $partition_parameter ]; then readonly drop_partition=false ...
0
votes
1answer
40 views

How do you put date and time in a file name?

I'm trying to execute a command and would like to put the date and time in the output file name. Here is a sample command I'd like to run. md5sum /etc/mtab > 2016_4_25_10_30_AM.log The date time ...
1
vote
2answers
54 views

Use of \$ at end of variable name passed to grep

I was going through one of the shell scripts and found a line: ls $dir | grep -c "$NAME.${var}\$" I understand that $ would expand the variables NAME and var, but is it required to put \$ at the ...
0
votes
2answers
21 views

Command Playlist like music.

So that idea has been in my head for a while, I often find myself launching a command and then wanting to launch another one after the one in progress finishes. The issue is that I have to monitor ...
1
vote
1answer
32 views

Save cursor position and restore it in terminal

I am playing with some terminal capabilities to create async prompt output on bash. I want to get something like this: while outputting string in PROMPT_COMMAND, save terminal cursor position, print ...