Hot answers tagged

54

That's because bash remembered your command location, store it in a hash table. After you uninstalled node, the hash table isn't cleared, bash still thinks node is at /usr/local/bin/node, skipping the PATH lookup, and calling /usr/local/bin/node directly, using execve(). Since when node isn't there anymore, execve() returns ENOENT error, means no such file ...


8

Using awk: awk '$1 ~ /\./' input-file-here The period in the awk expression has to be escaped with a backslash so that it's not treated as a regular expression syntax.


7

You can use grep to grab all files within foo that end with .a. foo | grep "\.a$" | xargs -d'\n' -r bar


7

You can use a combination of few utilities: stat -c '%s %n' pre_* | sort -k1,1rn | tail -n +2 | cut -d' ' -f2 | xargs rm Assuming GNU system and no unusual filenames. stat gets the filesize and name separated by space for all pre_* files sort sorts the file according to the file size, with highest sized one goes to top tail -n +2 gets the rest of the ...


7

With zsh: rm -f pre*(OL[2,-1]) OL: reverse order by size [2,-1]: second to last only The equivalent with bash and GNU utilities would be something like: eval "files=($(LC_ALL=C ls --quoting-style=shell-always -dS ./pre*))" rm -f "${files[@]:1}" You may want to limit it to regular files, as the size for non-regular files has generally not much ...


6

Better would be to make a function to do it like updateSubProject() { pushd "$1" svn checkout "$svnUrl" "$checkoutDir" --username "$username" --password "$password" --non-interactive --depth immediates --no-auth-cache popd } updateSubProject project-dir updateSubProject path/to/another-project this way you aren't trying to store code in a ...


6

grep -E '\b6\b' \b is a "word boundary" Edit: After pointing @nobar in the right direction, he found/pointed_out the shortcut-option -w (word-regexp) in the manpage, which simplifies the above to: grep -w 6 If used a lot, you could use a function similar to wgrp(){ grep -w "$1" "$2"; } Note (to @glenn-jackman): If you don't quote "$2" here, you can ...


5

Using grep to match . in the first field: grep '^[^[:blank:]]*\.' file.txt Example: $ cat file.txt Dolibarr techpubl http://techpublications.org/erp tekstilworks.com WordPress tekstilw wbq.dandydesigns.co WordPress cbeqte WordPress cbeqte http://wbq.dandydesigns.co ...


5

This is a very simple use of grep with regular expressions. This will do it: grep -E '^[g0-9]' file.txt I'm not sure what part you need help with, but I recommend you read man grep and learn about regular expressions. Note that you must use -E to enable "real" regular expressions (which are all you need to worry about), and protect your regexp with ...


5

curl wont "wait" to interpret your Javascript because curl does not understand JavaScript; JavaScript is always done on the client side, and usually browsers have JavaScript engines/know how to run JavaScript. So curl will see it only as block as text, and leave it as it is. Please do note this behaviour is not unique to curl e.g. in the Linux command line,...


5

This appears to do the trick: cd "$(dirname "$(whereis node_modules)")" If, as per your comment, you want to go into the target if it is a directory: location=$(whereis node_modules) if [[ -d "$location" ]]; then cd "$location" else cd "$(dirname "$location" )" fi The above could easily be made into a function in your .bash_profile.


5

You can use !!:* to refer to all the words but the zeroth of the last command line. !! refers to the previous command, : separates the event specification from the word designator, * refers to all the words but the zeroth. This is from the HISTORY EXPANSION section of bash(1). wieland@host in ~» cat foo | grep bar bar wieland@host in ~» tail -f !!:* tail -...


5

apt-get install whois Requires a network connection that can see the kali repo at http://http.kali.org/


5

Never known about the command intel_gpu_time interesting, thank you. This command is part of the package intel-gpu-tools (apt-get install intel-gpu-tools) under Ubuntu and by the look of it the package under RedHat (CentOS) is called exactly the same. So, give yum install intel-gpu-tools a try.


5

Yes, you can. Using grep with PCRE(-P): ip addr | grep -Po '^\d+:\s+\K[^:]+' ^\d+:\s+ matched the portion before interface name at the start, \K discards the match [^:]+ gets the portion upto the next : i.e. the interface name Similar logic using sed: ip addr | sed -nE 's/^[[:digit:]]+:[[:blank:]]+([^:]+).*/\1/p' On my system: % ip addr | grep -Po ...


4

This is impossible in general. Once an application has emitted some output, the only place where this output is stored is in the memory of the terminal. To give an extreme example, if this is the 1970s the terminal is a hardcopy printer, the output isn't getting back into the computer without somebody typing it in. If the output is still in the scrolling ...


4

There's no link from a file to symlinks that point to it, so there's no direct way of considering example and finding link_example which links to it. So deleting symlinks pointing to a file along with the file involves finding all the symlinks first. You don't specify what system you're using, but if you have GNU find, you can delete a file and its links ...


4

Just using -x option: sudo gem uninstall -a -x


4

Firstly, you need to feed display RGB:- raw bytes, not an encoded hex string like you're building with that hexdump | sed | tr pipeline. Secondly, you aren't giving it enough bytes: you need 3 bytes per pixel, one for each colour channel. This does what you want: mx=320;my=256;head -c "$((3*mx*my))" /dev/urandom | display -depth 8 -size "${mx}x${my}" RGB:-...


4

You can do that with, cd "`which node_modules`" With dirname to get the directory: cd "$(dirname "$(which node_modules)" )" as you have mentioned in the comment I am expecting to do this in one step & assuming nod_module is a directory, so you can do that with the following command: cd $(whereis node_modules | cut -d ' ' -f2) (Note that the ...


4

I was able to put the answer together with help from this question. The program "wc" program counts newlines, words and byte counts. The "-l" option specifies that the number of lines is desired. For my application, the following worked nicely to count the number of instances of "somePattern": $grep -r "somePattern" | wc -l


4

Two changes to your current script: don't parse ls; instead rely on the shell's globbing because the files are in a subdirectory, either cd there first and run the loop, or use basename and dirname to pull out the directory and filename portions of the file before adding the prefix. (Note: I also changed your "/Path" to "./Path" as I didn't want to ...


4

You can use history expansion $ echo test !#:^ echo test test test test $ echo a/b/test.py proj_copy/!#:^ echo a/b/test.py proj_copy/a/b/test.py a/b/test.py proj_copy/a/b/test.py !# The entire command line typed so far. :^ The first argument You could also use brace expansion $echo test{,} test test $echo {,proj_copy}/a/b/test.py /a/b/...


3

For the question, where file1.pgm and file2.pgm are files whose contents you want sent to a.out as input: cat file1.pgm file2.pgm | ./a.out If file1.pgm and file2.pgm are executables that produce output for a.out: (file1.pgm; file2.pgm) | ./a.out


3

You can also use chsh -l This will print the list of shells. Example :- [anurag@focused ~]$ chsh -l /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin


3

Your application may need you to wait for it to get focus before it accepts button events. If possible, use windowactivate to get the window focused first, or if not, do a short sleep .2 say, after the mousemove and before the click.


3

Assuming you just wanted to delete all string starting with "Perro", you can use: sed 's/Perro[^ ]*//g' *-a.log If you wanna edit file in place, you can use -i option with sed, like sed -i sed 's/Perro[^ ]*//g' *-a.log Update If you don't wanna have more spaces, you can use: sed -i sed 's/Perro[^ ]*//g' *-a.log | tr -s " " sample data, rahul@rahul:...


3

If you're running su as root, you can use -s to specify a different shell (running as root is necessary here since your tomcat user doesn't have a valid shell), and -c to specify the command to run: su -s /bin/sh -c "$CATALINA_HOME/bin/catalina.sh run" tomcat You might find start-stop-daemon useful; it has a whole slew of options to specify the user and ...


3

The -s switch for su command is to change the shell of the specified user. The command you want to run must be preceded by -c switch. So the command you are looking for is something like this: su -s /bin/bash -c "$CATALINA_HOME/bin/catalina.sh run" tomcat


3

Adding a d to the end of each number in the line number file turns it into a sed script that deletes the specified lines from its input. Then it's easy: $ sed -f lines_to_delete.sed file_with_lines.txt The sed script may be created like this: $ sed -e 's/$/d/' file_with_numbers.txt >lines_to_delete.sed



Only top voted, non community-wiki answers of a minimum length are eligible