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, …).
0
votes
1answer
544 views
Converting update-rc.d redis_6379 defaults to chkconfig command
I'm trying to run the commmand below to Centos and of course I get command not found. How do I then convert it to chkconfig ?
update-rc.d redis_6379 defaults
2
votes
2answers
27 views
Get the last minute dated lines from list
If I have an input file with a list of users and their dates they were last signed in, how can I select with a sort | awk function the last minute lines?
The dates are written in a +%H:%M:%S format.
...
2
votes
1answer
234 views
ctrl c vs. ctrl z with foreground job
Ctrl+Z stops the job whereas Ctrl+C kills the job.
Why is that? Wouldn't the other way make more sense?
z@z-lap:~$ sleep 100&
[1] 4458
z@z-lap:~$ sleep 200&
[2] 4459
z@z-lap:~$ jobs
[1]- ...
8
votes
1answer
54 views
Weird SSH issue, ssh works with -t but freezes without it
I've been a sysadmin for 15 years, but this ssh issue foxes me, and I'd be grateful for help.
What is happening
When I ssh into one of my servers, it seems to log in, but then hangs before giving me ...
0
votes
2answers
132 views
How to read the file line by line and to print the previous line where the file contains a single token
For example my file is like:
59 6 18 2014 169 7 14 2 7671912 7849744 201 4
60 6 19 2014 170 5 49 2 7671912 7849744 201 5
61 6 20 2014 171 6 8 2 7671912 7849744 201 6
62 6 23 2014 174 5 3 2 7671912 ...
1
vote
5answers
65 views
How to copy a file from a remote network to the local desktop
So I used SSH to remotely login to another computer on a network. I have many files that I would like to copy over to my local desktop.
I am trying to follow this How-to :
However, I think one ...
4
votes
1answer
59 views
Launch background processes in one group and later kill them all
The other day I tried writing a script that would kill a PID and all its children processes, but after spending some time on it, I decided it wasn't trustworthy, because sometimes some of the children ...
2
votes
1answer
372 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
...
3
votes
4answers
158 views
Removing duplicate lines
Say, I have two commands that return some text. For example:
$ ./c1
/usr/bin/foo
/usr/bin/bar
/usr/bin/baz
$ ./c2
/usr/bin/foo
/usr/bin/qux
/usr/bin/buzz
/usr/bin/bar
I want to remove the duplicate ...
2
votes
3answers
34 views
Reuse similar flags for multiple commands
Let's say I want to execute several commands with similar flags such as:
du -sh / --exclude=/dir1 --exclude=/dir2 --exclude=/dir3/dir4
tar cvf archive / --exclude=dir1 --exclude=dir2 ...
15
votes
1answer
597 views
Tilde (~) inside working unix directory
So, Im working in a UNIX environment and I noticed that inside my working directory, which is miles miles away from my UNIX home, there is a ~.
Now, once in the past, I did rm -rf ~ from my working ...
0
votes
2answers
23 views
Simple server that triggers script and responds
I need to have a very simple server running that can:
Take rest call. It triggers a script when a call is made
The script checks if database is running or not.
If running then reply back to client ...
7
votes
6answers
666 views
How to read first and last line from cat output?
I have text file. Task - get first and last line from file after
$ cat file | grep -E "1|2|3|4" | commandtoprint
$ cat file
1
2
3
4
5
Need this without cat output (only 1 and 5).
~$ cat file | ...
0
votes
1answer
43 views
ksh, perform action when reaching loop maximal value
I am looking to write a small korn shell script doing 5 tests (by waiting some time before each one) and then, if they all fail, performing an action.
I was looking at doing something like :
for ...
2
votes
1answer
33 views
Is there a single '03 registered UNIX which can't do rm — -foo at this point?
I'm trying to dispel this uncertainty I have about the use of the double-dash (two hyphens, --) as an end of options delimiter(as opposed to a long option prefix). It's possible some confusion arose ...
2
votes
1answer
38 views
Run wc and display only the word count
I have been trying to create a file called ~/dictwords.txt, which contains the number of words found in the file /usr/share/dict/words.
I already created the file then I removed it because I did it ...
1
vote
3answers
29 views
List files in a directory with a certain extension
I created a file called ~/usrlibs.txt, which contains the number of files that begin with lib and end .a found in the /usr/lib directory.
I tried:
ls -l /usr/lib/lib .a | wc -w > ~/usrlibs.txt
...
0
votes
2answers
29 views
list files and store it in variables
im new with shell programming.
my goal is to give the user a selection which file should be run.
i catch all available scripts in one var with:
var=$(find script*)
so far so good.. this is the ...
6
votes
1answer
34 views
How do I use colors in the MOTD?
I edited the default /etc/update-motd.d/00-header, adding some color to make it easier to read:
printf "Welcome to \e[1;34m%s\e[0m \e[2m(%s %s %s)\e[0m\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" ...
3
votes
3answers
2k views
Check whether files in a file list exist in a certain directory
The runtime arguments are as follows: $1 is the path to the file containing the list of files
$2 is the path to the directory containing the files
What I want to do is check that each file listed in ...
8
votes
2answers
303 views
disable CTRL-D window close in terminator (terminal emulator)
I am often logged in through multiple SSH sessions. To logout from my sessions, I press CTRL+d, until I am back on my local machine.
However, sometimes I press once too many, and my terminal exits.
...
1
vote
2answers
31 views
How to get text at start up of terminal
How to get text at start up of terminal as shown in this image.It should show whenever i open terminal.
4
votes
4answers
116 views
Help with “/usr/bin/stat: Argument list too long” error
I need to get the list of files(.log/.lst) present in a directory($logfolder) whose creation date is in a specific $year and $month
stat --format='%y %n' $logfolder/* |
grep "$year-$month-"|
...
21
votes
4answers
1k views
Is the shell permitted to optimize out useless terminating commands?
If a shell is asked to perform a probably useless (or partially useless) command known to terminate, such as cat hugeregularfile.txt > /dev/null, can it skip that command's execution (or execute a ...
19
votes
4answers
1k views
difference between function foo() {} and foo() {}
I can define bash functions using or omitting the function keyword. Is there any difference?
#!/bin/bash
function foo() {
echo "foo"
}
bar() {
echo "bar"
}
foo
bar
Both calls to functions ...
12
votes
1answer
246 views
3
votes
4answers
131 views
How to cut everthing until a specific word / after a find in a script
Hello I try to get the output of files from today wich contains ERROR.
I use this to find the files I want:
find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\
-daystart -mtime ...
4
votes
2answers
150 views
if statement in .bashrc not working correctly
I set up .bashrc to show a long prompt if the terminal is at least 80 characters wide. Otherwise it shows a degraded, smaller prompt.
I use an if statement to achieve this:
dp_smaller_than=80
if [ ...
63
votes
8answers
9k views
Why *not* parse `ls`?
I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons:
It seems the information in that link has been accepted wholesale with ...
2
votes
1answer
27 views
How to simulate user interaction when running another script
I am new to shell scripting. When I want to run a bunch of Linux commands I do fine, but how do I give user input when another script is called and asks for input while it runs. Here is the situation ...
5
votes
3answers
303 views
Is there any harm in using variables that aren't set?
Say I have the following code:
# Check if the color prompt is enabled and supported on this system
if [ -n "$force_color_prompt" ] && [ -x /usr/bin/tput ] && tput setaf 1 ...
2
votes
4answers
99 views
How do I pass a variable from my local server to a remote server?
I am trying to pass a variable from my local server (location1) to a remote server (location2). The purpose of the code is to copy a file from the remote server from a predefined location. In simpler ...
1
vote
3answers
30 views
How to run executable program with filter
I want to run a shell script. This script have a long name. So I want to use filter for file.
ex: ls | grep myfile | ./
Is it possible to execute a file with filter.
2
votes
5answers
66 views
How to copy 5 newest files from one directory to another and delete the old copies
How can I copy the 5 newest files from a directory to another in a "new to old" order.
2
votes
4answers
85 views
How to initialize an array using awk and bash?
I am trying to store values of the first line of a text file into an array. Here is what I have so far:
arr_values=()
awk '
NR==1 {
for (i=0; i<=NF; i++)
...
2
votes
2answers
283 views
See extended attributes with coreutils ls on Mac
I have coreutils installed via MacPorts on my Mac running OS X 10.8.4. I have ls set to use the coreutils version of ls [(GNU coreutils) 8.21] when available:
if [ -e /opt/local/libexec/gnubin ]; ...
7
votes
2answers
194 views
Cannot sum numbers received from stdin using bc
I'm trying to calculate the average entropy of files contained in a folder using:
{ echo '('; find . -type f -exec entropy {} \; | grep -Eo '[0-9.]+$' | sed -r 's/$/+/g'; echo '0)/'; find . -type f | ...
0
votes
1answer
417 views
Why alias does not work in AIX (korn shell, .profile)?
I have these files in my home directory:
drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 .
drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 ..
-rw------- 1 meuser staff ...
1
vote
2answers
21 views
Start several fish shells in different directories?
In order to be able to launch my work environment with a single command, I want to start several urxvt windows running fish shell in different folders. However, I found no obvious way of having fish ...
1
vote
4answers
122 views
Write program output to log file containing PID in its name
How can I start a program and write its output to a log file, where the log file contains the PID in its name? I tried
program_a > log_$!
which doesn't work since $! is the PID of the last ...
1
vote
1answer
25 views
Kill all queued jobs
I need to kill all the queued and running jobs on my ID. I have tried
at -l | awk '{print $1}'| at -r {}
But I keep getting
{} does not exist
Which leads me to believe that I am parsing ...
5
votes
1answer
58 views
Why does `bash -c somecommand` sometimes not leave a bash process?
On an Ubuntu 12.04, with GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu),
I tried the following command:
$ bash -c 'pstree -s $$'
init───sshd───sshd───sshd───bash───pstree
$ bash -c 'pstree ...
25
votes
4answers
3k views
What is the correct name for the “>” command
I was trying to find how to pass some text to a file without overwriting what's there already using the > command and I realised I don't know what it's called. Searching for right arrow or right ...
8
votes
3answers
6k 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.
6
votes
3answers
52 views
Can we configure different shells for different users on a single Linux/Unix distribution?
Well, this is not something that I want to do but I ask this question to know more about Shell configuration in Unix/Linux systems. So, the situation that I want an answer to is the following -:
As ...
-16
votes
3answers
104 views
Which amongst the given option is TRUE about login shell?
Which amongst the given option is TRUE about the login shell?
The login shell varies every time the user logs in. The kernel decides on the availability of the shell during login.
The login shell ...
-11
votes
2answers
162 views
Count the number of executable programs in a directory [closed]
How can I count the number of executable regular files in the current directory in a shell script?
0
votes
1answer
46 views
Bash Script : Passing a variable to a bash script that contains quotes, single quotes. etc [closed]
lets assume this is the string:
'a',"b"
it contains both single and double quotes.
how would you pass this to a bash script as a single string ?
this is the bash script:
#!/bin/bash
echo $1
...
2
votes
2answers
86 views
“cat” command: how to automatically escape everything that might be a violation?
If you copy the contents of
httpd.conf
and then paste it into a cat command.. such as this one..
#!/bin/bash
cat > /test << EOF
pasted here..
EOF
you run into this error:
-bash: ...
1
vote
3answers
52 views
Can I chain pgrep with kill?
I have noticed that | is used to send results of first command to the another. I would like to kill all processes that match a name.
This is what pgrep normally does:
$ pgrep name
5089
5105
And ...