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
72 views

Millisecond time in a shell script

How can someone print the entire time ie, for example 12:07:59:393(HH:MM:SS:milliseconds) in milliseconds. I found a lot of posts saying how to print Milliseconds along witht HHMMSS but I want to ...
4
votes
2answers
3k views

Testing a string containing only spaces (tabs, or “ ”)? [duplicate]

My code below doesn't work: stringZ=" " if [[ "$stringZ" == ^[[:blank:]][[:blank:]]*$ ]];then echo string is blank else echo string is not blank fi Result: string is not blank # wrong ...
7
votes
4answers
2k views

How to stop a bunch of processes on unix fast?

How to stop a bunch of processes on unix fast. I can use ps/top, kill. If the number of processes is very large, I use shell script. Are there other ways, only one or two unix commands can do it ...
1
vote
1answer
35 views

Shell is not listed in /etc/shells, when it is

I must be missing something simple here, because I am trying to make a user's default shell "lshell" for limited access. I try to set the shell with the command chsh -s /usr/bin/lshell userbut it ...
0
votes
2answers
66 views

Using regular expression to extract content of file [closed]

I have a link and I would like to return only content between www. and .com e.g www.blablabla.com would return only blablabla How could I do that? When I use grep '\.[a-zA-Z0-9\.-]*\.' it gives me ...
1
vote
1answer
34 views

zsh fails at path completition when command is vim

When I try to autocomplete files (with vim as argument 0): vim ~/.conf <TAB> It shows: _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: function ...
1
vote
1answer
122 views

Evaluation of find ( -exec )

I'm searching for all files that contain one of a set of strings. If they do, I change their access rights. find . -type f -exec grep -q '#!/bin/bash\|#!/usr/bin/grep\|#!/usr/bin/awk' {} \; -exec ...
16
votes
5answers
22k views

How to see how many context switches a process makes?

I want to see if my process makes a lot of context switches. I also want to see how manpulating task groups affects the number of context switches.
34
votes
5answers
33k views

How can I install the `ll` command on Mac OS X?

I'm using Mac OS X. When I SSH into servers I find the ll command useful, but it's not available on my local machine. How can I install it?
4
votes
1answer
77 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 ...
2
votes
1answer
87 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 ...
0
votes
1answer
21 views

Filtering time using last command on Solaris

I'm connected on server using Solaris and need to filter only people who were connected there until 28.4 00:00. How do I do that on Solaris? In bash I have -t option which does what I want.
0
votes
2answers
38 views

Why cant I overwrite a file with processed value?

This question prompted a thought I was not sure I understood well. I know that it is not possible or correct to use pipelines like cat myfile | grep -v mypattern > myfile due to how file handles ...
70
votes
7answers
69k views

How do you move all files (including hidden) from one directory to another?

How do I move all files in a directory (including the hidden ones) to another directory? For example, if I have a folder "Foo" with the files ".hidden" and "notHidden" inside, how do I move both ...
8
votes
2answers
1k views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
1
vote
1answer
32 views

Does gnome-terminal modify PATH when invoking shell

I guess gnome-terminal might have modified PATH environ variable when invoking shell. Specifically, $HOME/.local/bin:$HOME/bin will always be appended to PATH. I did the following experiment to ...
4
votes
1answer
834 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
0
votes
2answers
23 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
3answers
314 views

the difference between '..' and “..” when I use ssh usr@ip 'pscp …'

My Server machine run Window,and it installed Cygwin. My Client machine run linux. In Clinent machine.I do this: [sikaiwei@login-1-2 v1.4]$ bash test.sh CHUN~19900405 ...
5
votes
2answers
31 views

What exactly happens if input and output file is the same?

Let's say that I execute following command: tr a-z A-Z < file > file There are two redirections: < file and > file. Both are processed before tr command and as far as I know, if there ...
2
votes
3answers
2k views

Update process name in shell, is it possible?

In C/C++ it is in general possible to do strcpy(argv[0], "new process name"). It's a hack used in malicous software to hide real process name. Is such operation possible via shell? What I want to do ...
20
votes
3answers
21k views

How can I remove an element from an array completely?

unset array[0] removes the element but still if I do echo ${array[0]} I get a null value moreover there are other ways of doing this but if an element of an array contains spaces like below ...
8
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 ...
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 ...
0
votes
1answer
60 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
2answers
51 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 ...
8
votes
4answers
563 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
49 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
49 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
607 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
101 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
114 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
241 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
243 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
46 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 ...
8
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
383 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
53 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 ...
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 ...
2
votes
1answer
29 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
45 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
63 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
72 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 ...