Tag Info

New answers tagged

0

There are (more than) two tools to do this: nmap: sudo nmap -sn 192.168.2.0/24 -sn (No port scan) This option tells Nmap not to do a port scan after host discovery, and only print out the available hosts that responded to the host discovery probes. This is often known as a “ping scan”, but you can also request that traceroute and NSE host scripts be ...


1

find . <find arguments> -print0 | xargs -0 grep <pattern>


1

If all your target files are in directories named photos, you could do something like: find . -type d -name photos -exec bash -c 'cd {} && mv *jpg ../' \; That will look for directories names photos, then launch a bash shell that will cd into each of them and move all .jpg files to the parent directory.


0

TL;DR The script can not work because that shortcut will be sent to the active window, and that's not chromium-browser with Streamus This is your reload xdotool command xdotool search --limit 1 --name "^Streamus$" | xargs -I {} xdotool windowactivate --sync {} key ctrl+r The complete command in your case is: /usr/bin/chromium-browser --disable-gpu ...


7

Is there really no colon before the hyphen inside the parameter expansion ${GZIP_BINDIR-'/bin'}? This kind of construct is almost always written with a colon, as in ${GZIP_BINDIR:-'/bin'} which means, "if $GZIP_BINDIR is NULL or unset, set it to '/bin'" However, the syntax you supplied is valid, but rare. ${GZIP_BINDIR-'/bin'} (no colon) means, "if ...


1

Move files from the lowest sub directory up one level The script below searches a directory for the lowest sub directory (= without sub directories) recursively and moves all found files in the folder(s) up one level, as literally asked for in The goals is to move files out of the lowest level folder, back up one directory: #!/usr/bin/env python2 import ...


1

The following will move all .jpg files to their respective parent directories if the .jpg files are only under the directory named photos (there can be multiple directory named photos): find . -type f -path '*/photos/*' -not -path '*/photos/*/*' -name '*.jpg' \ -execdir mv -i {} .. \; -path '*/photos/*' will ensure that the path will contain photos but ...


-2

As described its the previous command, but its better not to use this as its a sloppy short hand. Being more direct is simple and safer. $ vim index.php The program 'vim' is currently not installed. You can install it by typing: sudo apt-get install cowsay $ sudo apt-get install !! # Would be done as sudo apt-get install vim index.php instead of sudo ...


16

${GZIP_BINDIR-'/bin'} is a bash parameter expansion pattern. From man bash: ${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. Immediately prior to this portion man page has (thanks to @jwodder for notifying): Omitting the colon ...


1

This command update the PATH variable. The PATH is an environment variable specifying a set of directories where executable programs are located. PATH="${GZIP_BINDIR-'/bin'}:$PATH"; This add the value of another variable GZIP_BINDIR if exit to the previous PATH else use /bin instead and add it to PATH export PATH export is used to set the PATH ...


4

You can use a for loop, so the command is executed for every file exactly once: for file in *.dat; do sed -i.bak '1,2000d' "$file"; done Notice, -i.bak backs up the original file with .bak ending.


1

writing / formatting. https://docs.python.org/2/library/csv.html http://java.dzone.com/articles/python-101-reading-and-writing Same as #1 really. Once you have the data you insert it accordingly. You define the columns, format, etc. crontab as suggested above would be easiest. crontab -e @hourly /path/to/script.py --arguments


0

The problem is that fuser only works on processes currently using a file which have an opened file descriptor for them in the kernel. While this is true for your C program, this is not true for your bash script: echo $(date) >> log Just opens the file, appends stdout to it and immediately closes it. So the file is never deemed as opened by the ...


1

Your script logtest.sh does only write into log and closes the file-descriptor immediately. So when you call fuser on log.1 there is no process which has an active file-descriptor for this file. You can simulate this by running the while loop inside a list (while true; do echo $(date); sleep 1; done) >> log And both logtest.sh and logtest.c will ...


2

This should do it: #!/bin/bash while IFS= read -r jpg do convert "$jpg""[1024x>]" "$jpg" done < "$1" Save the script above as ~/bin/shrink.sh, make it executable (chmod a+x ~/bin/shrink.sh) and run it, giving the list of files as an argument: shrink.sh /path/to/list This is basically the same as the proposed duplicate, adapted to i) match ...


-1

Try something like this: #!/bin/bash for p in "$@" do w=`identify "$p" | cut -f 3 -d ' ' | sed 's/x.*//'` if [ $w -gt 1024 ] then convert -scale 1024x1024 "$p" "$p" fi done Explanation: The "identify" command produces all sorts of info about the image. The third field is the size, in the format "1024x968". The "cut" command ...


5

Since your command has one argument, it can't be an alias. You should define it as a function instead. function lost { find /home -iname ${1} 2> /dev/null }


0

It seems like the hadoop user does not have the required permissions. Try: sudo chown -R hduser:hadoop /usr/local/hadoop This command will make hduser (part of group hadoop) to be the owner of the directory /usr/local/hadoop. To do that recursively i.e. for all files and directories (and all files and directories within any directory), -R option is used.


0

For use the pip install $ mkdir my_project_folder $ cd my_project_folder $ curl -L -o virtualenv.py https://raw.github.com/pypa/virtualenv/master/virtualenv.py $ python virtualenv.py venv $ source venv/bin/activate In this point, you have you virtualenv ready, if you want install more packages, you can this: $ pip install YOUR_PACKAGE --user So, you ...


35

!! has nothing to do with apt-get. It is a shell keyword that will be expanded to the previous command. This expansion is done by shell before the current command is interpreted. From man bash: !! Refer to the previous command. This is a synonym for `!-1'. For example, if you run a command: echo "foo" Then if you run: sudo apt-get install ...


15

!! : Refer to the previous command. This is a synonym for !-1 (The source). For instance, if i execute: ./test then remember that I need to be Root, then I could simply type: sudo !! it's the same as typing: sudo ./test It's useful when your last command contain a lot of characters.


63

!! is a shortcut in bash that means last command executed. Try this: echo hello !! In this context, the !! will be expanded to another echo hello. I imagine what happened was they tried to run a command and it failed and complained it wasn't installed. So then they typed sudo apt-get install !! because the package name was coincidentally the same as ...


1

I created this from your other question as well. It took me a bit, but this is what I was able to come up with to create the folders based on the zip file name, removing the .zip from the folder name, then extracting the zip file into that folder. #!/bin/bash echo "Start folder create..." find . -type f -name "*.zip" | while read filename do ...


0

Using sed: zip_file="$(<<< "${filename}" sed -r 's/^(.*)\..*/\1/')" zip_file="$( [...] )": assigns the stdout of an invoked subshell to the variable zip_file as a string <<< "${filename}" [...]: redirects the content of the variable ${filename} to the invoked subshell's stdin as a string sed -r 's/^(.*)\./\1/': edits the content of the ...


1

heemayl is still right: example: full_path=/foo/bar/baz.zip file_name="${full_path##*/}" name="${file_name%.*}"


0

If it says permission denied, you probably need sudo. Try this command instead: sudo hadoop namenode -format It may not be needed, but as you are having issues it may help. The tutorial suggests it will be modifying folders in /usr - this could be the issue.


0

You need more quotes: zip_dir="$PWD/$(basename "${zip_file}")"


4

Use bash parameter expansion: zip_file="${filename}" new_name="${zip_file%.*}" new_name will contain the name test if the zip_file has test.zip If the zip_file has test.foo.zip, new_name will have test.foo, if you want only test out of test.foo.zip use: new_name="${zip_file%%.*}"


2

You've got it over multi lines, but have the ;. Your script should look like this: #! /bin/bash echo "Start folder create..." find . -name "*.zip" | while read filename; do foldername="${filename%.*}" mkdir -p "$foldername" mv "$filename" "$foldername" echo "made directory $foldername" done


6

Use a shell glob instead of ls: select option in "Exit" "$1"/* . . . elif [ -n "$option" ]; then ls "$option" else . . .


3

The code snippet you have given requires a modification, you need -print0 instead of print 0. This script will find (find) all the files having extension txt in /home/mike/Duck/, send them to printer (lpr) one at a time and then if that returns a success (&&) then the file will be moved (mv) to /home/mike/Duck/printed/. If you want to print files ...


2

You have to escape ampersands (&) or put the whole URL in quotes since ampersand is one of the special characters that's interpreted by your shell and prevents you from passing the whole URL to youtube-dl. More on this. So just putting it in single quotes will suffice: youtube-dl ...


1

It is possible but you're looking at different issues. Since the server, prior to installing an os, will not have a working TCP/ip stack (I.e. networking ), you won't be able to simply ssh/putty over to it. Unless you have a device that allows you to have keyboard/video/mouse access over the network to a separate device that's then connected to the server, ...


1

When using youtube-dl try to clean up the URL you use. For example, the following URL will work. Thanks for the video ^_~. https://www.facebook.com/video.php?v=10152588878600983 How did you install youtube-dl? If you installed it through apt, I would recommend the following: sudo apt-get remove youtube-dl sudo apt-get install $(apt-cache depends ...


1

In addition there is comm command, which compares two sorted files, and gives output in 3 colums : column 1 for items unique to file #1, column 2 for items unique to file #2, and column 3 for items present in both files. To suppress either column you can use switches -1, -2 , and -3. Using -3 will show the lines that differ. Bellow you can see the ...


1

FWIW, I rather like what I get with side-by-side output from diff diff -y -W 120 File_1.txt File_2.txt would give something like: User1 US User1 US User2 US User2 US User3 US | User3 NG


2

The Ubuntu maintainers of the gnome-terminal package noticed this issue and created a wrapper script (in Ubuntu package gnome-terminal-3.14.2-0ubuntu3) to re-enable the --disable-factory option; however, the wrapper script doesn't work! From the changelog ...


4

I use a method that has some similarities to the answer of terdon (and was created with some help of him - Thank you @terdon for this!), but has a slightly different approach: I create a temp file so that the child terminal can communicate with the parent terminal and tell it the PID of its corresponding bash instance. Then I let the parent terminal read ...


4

You can make a conditional to relaunch the script as root if it's launched as a normal user. To shutdown the computer: #!/bin/bash if [[ $USER == "eka" ]]; then # If the script is ran as "eka": sudo $0 # Relaunch it as "root". exit 0 # Once it finishes, exit gracefully. elif [[ $USER != ...


0

I've been using newer gnome-terminal, and the behavior you've described for gnome-terminal appears to be the same for konsole, lxterm, and rxvt (tried all 3 ). So since OP has not answered any comments so far to clarify what he or she wants , I'm making assumption that OP wants to continue using the parent terminal without waiting for child terminal to ...


3

In their infinite wisdom, the GNOME devs decided to remove that option. Unfortunately, their wisdom did not extend to also updating their man page which still lists it. So, it looks like gnome-terminal will always be run int the background and the parent shell session will be returned to immediately. To get around this, you have a few options: Just use ...


0

The "Host key verification failed" is from the underlying SSH process. See pdcp(1): When using ssh for remote execution, stderr of ssh to be folded in with that of the remote command. When invoked by pdcp, it is not possible for ssh to prompt for confirmation if a host key changes, prompt for passwords if RSA keys are not configured ...


4

Don't use setuid shell scripts, the SUID bit is not honored on shell scripts anyway on current systems. Use sudo instead, as you attempted anyway: eka ALL=NOPASSWD: /home/eka/test/test.sh And then: eka$ sudo ~/test/test.sh With that, test.sh will be executed as "root". No need to use setuid here.


2

You need to store the count somewhere it will persist across multiple runs of the script, since variables are just in memory for that single run. The easiest place is probably in a file. The particular way you store it in a file depends on a few factors including how many times you're counting, and whether you expect concurrent runs. A simple robust way ...


1

I'm still looking for a pure bc answer to how to round just one value within a function, but here's a pure bash answer: #!/bin/bash echo "Insert the price you want to calculate:" read float echo "This is the price without taxes:" embiggen() { local int precision fraction="" if [ "$1" != "${1#*.}" ]; then # there is a decimal point ...


1

It is possible. You could use netstat -a | egrep 'Proto|LISTEN'


7

Use functions, instead. d () { num=${1:-5} dmesg |grep -iw usb|tail -$num } num=${1:-5} uses the first argument, with a default value of 5 if it isn't provided. Then you can do: $ d # prints 5 lines $ d 10 # prints 10 lines Or, if you change the options you used slightly: alias d="dmesg|grep -iw usb|tail -n 5" Then you can pass additional -n ...


1

You need to have a function for this as described in the SO and here. Try the following: foo() { /path/to/command "$@" ;} and call the foo with: foo arg1 arg2 arg3


0

Using grep, to store e.g. WD_MANAGEGOLD_DATETIMESTAMP's value into a wd_managegold_datetimestamp variable and WD_MANAGEGOLD_SUCCESS's value into a wd_managegold_success variable: #!/bin/bash # ... wd_managegold_datetimestamp=$(< savedState.properties grep -Po '^WD_MANAGEGOLD_DATETIMESTAMP=\K.*') wd_managegold_success=$(< savedState.properties grep ...


2

You can export them like this. #!/bin/bash #Specific Set Variables SpecficStatus="Pass" #SetVariable timestamp() { date +"%a %d %b %Y %T %Z"; } SpecficDate=$(timestamp) echo $SpecficStatus echo $SpecficDate #Properties Call file="savedState.properties" #Echo out the file while IFS== read -r VAR1 VAR2 do #echo "VAR1=$VAR1 : VAR2=$VAR2" export ...



Top 50 recent answers are included