Tag Info

New answers tagged

0

I have two problems with your question. ps -A|grep bash|wc -l and the same command in ssh localhost 'csh -l' give the same number. So it does not seem that a bash is run before 'csh -l'. On the other hand csh does not use etc/profile. strace -eopen csh -l does not show any entry of /etc/profile*. So I am not sure the problem you have is in ...


0

You could start by timestamping the data as you receive it into a logfile: awk '{print strftime("%Y.%m.%d.%H%M%S ") $0}' </tty/USB0 >>logfile You can choose a format that is easy to parse. Of course, the data may already have a timestamp. The above gives lines with fixed width date and time beginning eg: 2015.07.07.093953 In a script you can ...


7

shift $((OPTIND-1)) (note OPTIND is upper case) is normally found immediately after a getopts while loop. $OPTIND is the number of options found by getopts. shift n removes n strings from the positional parameters list. Thus shift $((OPTIND-1)) removes all the options that have been parsed by getopts from the parameters list, and so after that point, $1 ...


2

$((...)) just calculates stuff. In your case it takes the value of $optint and substracts 1. shift removes positional parameters. In your case it removes optint-1 parameters. For more information have a look at help getopts, help shift, look at man bash for "Arithmetic Expansion", and especially google for getopts.


0

That first line starting with #! is (on Linux) interpreted by the Linux kernel inside the implementation of execve(2) system call (which is invoked, after fork, by your shell for most commands - those that are not functions and not shell builtins). You could mention the absolute path of other executables (such as /usr/bin/env, see env(1)). As a silly ...


1

The first Line tells the computer which interpreter to use while executing the file Let's say you write a script using python, and while running this script you will use the python interpreter and how would computer know which interpreter to use, it will know through this line which is also called the Shebang, for python #!/usr/bin/env python print "Hello ...


-2

Forces the script to run using the bash shell, rather than the current shell being used.


3

Have a look here Wikipedia/Shebang.


3

ps aux = list all processes sort -rk 3,3 = sort by third field, in reverse order head -n 5 = show first 5 lines So when piped together line this, simply shows the top 4 processes in terms of current CPU usage. (only 4, not 5, as one line will be a header title line)


2

You have an extra backslash in your symbolic link. The actual path is /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl but you created a symbolic link to /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl When you use the text of the symbolic link in the shell, the backslash is interpreted as an escape character, so you get ...


3

On Ubuntu and Linux Mint, most ways to start a GUI session, including I believe the default one, cause /etc/profile and ~/.profile to be read by /bin/sh, not by bash. /bin/sh is dash, a shell that is faster and uses less memory than bash, but lacks some of its features such as function export. Your ~/.xsession-errors must contain lines like .profile: 42: ...


0

This happens because something in your configuration is loading /etc/profile multiple times. You need to locate it and fix it. The file /etc/profile is read by a login shell. It's also read when logging in to a graphical session on many platforms (but it depends on the display manager, on the session manager, and on how your distribution set them up). One ...


-1

Try ssh -t username@hostname /bin/sh --noprofile.


1

Does sftp also fail ? If doesn't, you could make use of that to place a good /etc/profile.d file there.


-1

Traditionally bash functions are placed in ~/.bashrc as this is read by interactive bashes. ~/.profile is only read by login bashes. New windows usually dont run login bashes.


0

Here's the fix: replace your file /etc/profile.d/php.sh contents with: pathmunge /usr/local/php/bin after and similarly for the file /etc/profile.d/mysql.sh: pathmunge /usr/local/mysql/bin after The explanation is that the files in /etc/profile.d/*.sh are sourced by /etc/profile (which is itself sourced by a login bash shell). Because the files are ...


0

Use this: text=[your text];echo $text>file;echo $text Example: This: tx=My text;echo $tx>logfile;echo $tx Will result in this standard output: My text and the contents of logfile will be: My text If you want a shorter solution, make this file (copy and paste): #!/bin/sh if [ $# = 3 ];then echo $1>$2 echo $1 else echo You must specify 2 arguments ...


9

From man ksh on a system with a ksh93 installed... Name Spaces Commands and functions that are executed as part of the list of a namespace command that modify variables or create new ones, create a new variable whose name is the name of the name space as given by identifier preceded by .. When a variable whose name is name is referenced, it is ...


8

Looks like you might be looking for chroot. Note that while something like ../../../../../.. will not escape the restricted root directory, there are other ways to escape indirectly, by leveraging other processes. If you're concerned about a malicious application, run it as a user who doesn't run any process outside the chroot. For a more ...


6

The pipe will immediately get closed on nc's end. When omxplayer dies nc will receive SIGPIPE on writing to the fifo, not to the pipe. It might be better to just run nc in the background so that you could keep control over omxplayer via stdin. mkfifo tcp.stream nc -l -p 1234 > tcp.stream & omxplayer --live tcp.stream However, using | instead of ...


9

Use script(1) to log everything sent to the terminal: $ script Script started, file is typescript $ # do your work ... $ # then exit with ^D $ exit Script done, file is typescript You can later look at the output with less: $ less -r typescript Beware that the logs will contain all control characters sent to the terminal, such as ANSI colours or ...


2

The command Forward=*R1*.at.fastq sets the variable Forward to the string *R1*.at.fastq (star, capital R, digit 1, star, dot, lowercase A, etc.). Wildcards are only expanded in contexts that allow multiple words; the right-hand size of a variable assignment expects a single word, so no wildcard expansion occurs. In a command like cat $Forward, the wildcards ...


13

The answer from @ubaid-ashraf is almost there. The way to specify file with no extension, in ksh would be: cp -- !(*.*) /new/path/ so that any file with dot in file name is skipped. For that to work in bash, you need to enable the extglob option (shopt -s extglob) and the kshglob option in zsh (set -o kshglob).


1

You can use find+grep to get only files that have no extension find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." So your copy command will be cp ` find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." ` destination_folder


5

You can do something like: cp -- !(*.txt) /path/to/directory The above code will copy all the files without .txt extension. You can also give multiple extension via pipe character. For example: cp -- !(*.txt|*.c|*.py) /path/to/directory


3

The $PATH is getting expanded prior to running on the remote server. Example #1 Say I run these commands from a system called skinner.bubba.net. [root@skinner ~]# ssh mulder 'bash -s' <<EOL > echo $HOSTNAME > hostname > EOL skinner.bubba.net mulder.bubba.net By moving the single quote so that the echo $HOSTNAME is inside it, you can ...


16

Here-Document is a kind of shell redirection, so the shell will perform it as normal redirection, from beginning to the end (or from left to right, or order of appearance). This's defined by POSIX: If more than one redirection operator is specified with a command, the order of evaluation is from beginning to end. In your command, cat will perform ...


-1

When bash creates the process to run cat, it opens conf for write on file descriptor 1 and opens a temporary file (for the here-document) for read on file descriptor 0, before execing the program. In this case, it doesn't really matter in which order those actions happen. Order does become significant when file descriptors are reassigned, e.g. with ...


12

Well, let's find out: unset file cat >"$file" <<EOF this is not in ${file=./myfile} EOF bash: : No such file or directory Dang. I guess it must be doing the >"$file" part first then. But what if...? unset file <<EOF cat >"$file" this is in ${file=./myfile} EOF ...no error...? cat ./myfile this is in ./myfile As it ...


3

Running each command in a different terminal will work; you can also start them in a single terminal with & at the end of the first to put it in the background (see Run script and not lose access to prompt / terminal): sudo ptpd -c -g -b eth1 -h -D & sudo tcpdump -nni eth1 -e icmp[icmptype] == 8 -w capmasv6.pcap


4

Okay, let's break this down. A subshell executes its contents in a chain (i.e., it groups them). This actually makes intuitive sense as a subshell is created simply by surrounding the chain of commands with (). But, aside from the contents of the subshell being grouped together in execution, you can still use a subshell as if it were a single command. That ...


1

subshell (command) will execute command in subshell, this is usefull, if you have more then one command. (ls) | wc will pipe ls to wc, obviously you can write ls | wc (ls ; date) | wc will pipe the result of both ls and date to wc. using ls ; date | wc will result in only date being piped to wc. substitution $(command) will execute command and ...


4

Use od, hexdump, xxd, or similar to print binary data in human-readable form. For example: $ tput setaf 1 | od -c 0000000 033 [ 3 1 m 0000005


5

Sounds like you want the opposite of printing them literally, you want those escape characters converted to a printable descriptive form like \E or \033, ^[... If it's just the ESC (0x1b) character you want to convert to \E, then with ksh93, zsh or bash (typically, the same ones that also support that non-standard %q), you can do: printf '%s\n' ...


0

You can use printf directly, eg printf "\033[31mfail"


0

I could make a possible work-around (Thanks @mikeserv for providing me the idea of array): array=('1 2' '3 4' '5 6' '7 8') for x in "${array[@]}" do A=`echo $x | awk '{print $1}'` B=`echo $x | awk '{print $2}'` echo A=$A B=$B C=$(($A+$B)) echo Sum,C = $C done Suggest if further simplification is possible.


2

set 1 2 3 4 5 6 7 8 while [ "$#" -gt 0 ] do C="$(($1+$2))" shift 2 done for doesn't allow for two simultaneous assignments in that way. So get an array and shift it away at your desired interval. If you use the standard shell $@ array as I do above, then you'll always be working with your first two positionals $1 and $2. If you use some kind of ...


4

I would use while read A B do echo A=$A B=$B C=$(( $A + $B )) echo Sum,C = $C done<<EOF 1 2 3 4 5 6 7 8 EOF For more complex operations dc is your friend (polish reverse notation!) C=$(echo "$A $B +pq"|dc)


1

There's something odd going on with the command line - whether it is a file-system problem or something more elementary (like unprintable characters in a directory name). The error message "Unable to find a suitable output format for pipe:1" is due to the previous "-f flac" being ignored. I have tried renaming an mp3 to your stated problem filename, and ...


0

Execute echo $0 to know what shell you're using when you run ./extract.sh $ echo $0 /bin/bash Put the shebang at the very first line #!/bin/bash mboxutil -l > n.txt sed 's/^.*user//' n.txt > n1.txt cat n1.txt | sed 's/^.//' > n2.txt sed 's/\/.*//' n2.txt > dss_list.txt rm -f n.txt rm -f n1.txt rm -f n2.txt sed -e '/^$/d' -e '1d' dss_list.txt ...


0

For a more general approach to killing processes... This command should show the process pgrep -f runcommand.sh Then either cut and paste the process ID kill PROCESSID or, if you're a little braver using pipes pgrep -f runcommand.sh | xargs -I{} kill {} If you don't have pgrep (for some reason), then you can replace the pgrep command with this ...


0

Give a try to killall runcommand.sh EDIT: |─lightdm─┬─Xorg───2*[{Xorg}] │ ├─lightdm─┬─init─┬─at-spi-bus-laun─┬─dbus-daemon │ │ │ │ └─3*[{at-spi-bus-laun}] │ │ │ ├─at-spi2-registr───{at-spi2-registr} │ │ │ ├─bamfdaemon───3*[{bamfdaemon}] │ │ │ ...


0

Try sudo killall --process-group emulationstation


0

You should be able to group find patterns with -or and -and to select different patterns. I don't use such options but its $ find . \( -name foo -or -name bar -or -name buz \) -and -path '*/G/*'|9 mc ./G/buz ./G/bar ./G/foo where G = common_directory. I tested this against a file structure $ find . -name foo -or -name bar -or -name buz|9 mc ./G/buz ...


2

One way is to look for one of the file names (pick the rarest one if you know which one it is) then filter the matches to retain only those where the other file exists. find . -name foo -exec sh -c '[ -e "${0%/*}/bar" ] && [ -e "${0%/*}/buz" ] && echo "${0%/*}"' {} \; You can use the shell snippet's return code if you want to use a find ...


2

You can run it in the shell, for example like: $ for i in $(find /etc -type f); do wc -l $i; done This runs through /etc and gives out the line count of each file. Added according your comment: $ if [ "hi" == "hi" ]; then echo "this is true"; fi


0

I am unaware of any find option that can do it all by itself. Using greps you can achieve that - put all the file names that you want to find in a separate file , say /tmp/files_to_find, with the following pattern In your case files_to_find would be \/foo$ \/bar$ \/buz$ Then issue the following command find root_dir_to_search_in | grep -f ...


1

From cp man page: cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... You are giving parameters to cp in wrong order. Source should come before destination. Correct command is : find / -type f -perm a+r -exec cp {} /home/student/abc \; Also note that you should end -exec parameter with ;


2

Try this, fixes the cp parameter order and limits to just root filesystem rather than trying to traverse /proc and the like. find / -xdev -type f -perm a+r -exec cp {} /home/student/abc \;


24

A minus sign before the command name is a convention that login programs use to start login shells. A login program is a program where you typically type your password and that starts a session for you, such as login, sudo -i, su -, sshd, etc. A login shell is the initial shell of a text mode session. Conventionally, when a program invokes another program, ...



Top 50 recent answers are included