Tag Info

New answers tagged

3

I don't know what all your echo stuff is about but if you just want to check if a particular process is running, you can use pgrep on your schedule. This will return 0 if if finds a process that matches. I'm assuming you're downloading with wget but you can just change that to whatever process you'd expect to see alive (use htop to inspect the system while ...


1

either put all or partial path in single or double quote or escape space with backslash. Eg: cd /path\ to\ folder cd '/path to folder'


5

Either quote the entire name: cd "/path/path/path/A Folder/file" or escape just the strange characters (space, in this case) using a backslash. cd /path/path/path/A\ Folder/file Another thing to try, is using tab completion: cd /home/user/Desktop/Bas Then press the TAB key, this should complete it to: cd /home/user/Desktop/Bash\ Programming/ Then ...


10

You can enclose the whole path by double-quotes ("), single-quote (') or escape the space character using a backslash (\) : cd "/path/path/path/A Folder/file" cd '/path/path/path/A Folder/file' cd /path/path/path/A\ Folder/file


3

Have you tried this? cd Bash\ Programming Or /path/path/path/A\ Folder/file


0

You can run your java command in a gnome-terminal this way: gnome-terminal -x bash -c "java -version; bash" Or to take your example: gnome-terminal -x bash -c "java -jar example.jar; bash" You could even specify where to run your command: gnome-terminal --working-directory=WORKING_DIR -x bash -c "java -jar example.jar; bash" Running a bash command ...


0

Instead of using the script, try running directly from a terminal java -jar example.jar and see what happens. If the same output is received, this might mean that's just the way the app run. Also consider checking this answer How do I run a .JAR file via the terminal


0

To open a bash file for editing (something with an .sh suffix) you can use a text editor like nano. nano filename.sh If you want to run a bash script you can do it in several ways. ./filename.sh or sh filename.sh Best, Lev


0

Make it executable using chmod +x filename and run it in terminal using ./filename Or You simply bash filename


0

Give it permission to run chmod +x /path/to/yourscript.sh And run your script: /path/to/yourscript.sh


3

To edit: Use any editor you like: gedit some_file.sh nano some_file.sh vim some_file.sh # ... To run: Either make it executable and run it giving the path: chmod +x some_file.sh ./some_file.sh Or tell bash to run it: bash some_file.sh Also see: How can I run this sh script without typing the full path?


1

I believe this is exactly doing what you describe. The script below seems a bit verbose, but a great part of it is taken by the necessary information the user has to give in this somewhat complicated construction. How to use As always, copy the script below, enter the appropriate paths, in this case quite a few, the appropriate identifying strings, and ...


0

The main reason we do not recommend running old unsupported releases is that they will not automatically get security fixes. For bash releases 10.04 LTS, 12.04 LTS, and 14.04 LTS only will get a security update und upgrading. Adding a random ppa to an old release may introduce even more severe security issues in case you do not know the maintainers of this ...


4

OK, first of I think this is what you need: tput command . Basically it allows user to redraw the screen without closing the session. Look at the screen capture of my terminal window: Basically, I executed command ls *.c just to fill the screen with something. Then I execute command tput cup 4 0; echo "THIS LINE WILL BE COVERED WITH THIS ALL CAPS TEXT :)" ...


-1

First make sure you close all terminal windows and shell sessions. Then open file ~/.bash_history in gedit ( or anoter GUI editor) and delete the lines you do not want.


1

Create a simple file copyFile.sh as follow: #!/bin/bash kodeFile=$(basename $1 | sed -e 's/_code_c/_kode_c/') modeFile=$(basename $1 | sed -e 's/_code_c/_mode_m/') find FolderB -name "$modeFile" -exec cp {} FolderC/$modeFile \; find FolderB -name "$kodeFile" -exec cp {} folderD/$kodeFile \; save it, for example in /home/yourUser/bin. Change permission to ...


1

Let's say you're in your $HOME, and you have four directories -- folderA and folderB, as in your question; folderK, where you want to move the 'kode' files to; and folderM, where you want to move your 'mode' folders to. The following should accomplish that: shopt -s globstar cd /path/to/folderA for f in *_code_c*; do mv ...


2

With a loop and some bash string manipulations while read -rd $'\0' f; do d="${f%/*}"; p="${d/\//_}"; echo mv -- "$f" "${d}/${p}_${f##*/}" done < <(find -type f -name '*.jpeg' -printf '%P\0') (remove the echo once you've confirmed it matches the files correctly) With the perl-based rename command and bash globstar shopt -s globstar rename -nv ...


1

Create a simple file changeName.sh as follow: #!/bin/bash fileName=$(basename $1) filepath=$(dirname $1) secondDir=$(basename $filepath) firstDir=$(basename $(dirname $filepath)) parentDir=$(basename $(dirname $(dirname $filepath))) mv $1 $filepath/${parentDir}_${firstDir}_${secondDir}_$fileName save it, for example in ...


0

I'm using Natty 11.04, which is EOL (and I have updated /etc/apt/sources.list to use old-releases.ubuntu.com), so I have to build from source. I wanted to build a .deb, so at least the package manage is "aware" the bash version is not the default one. I am not 100% succesful - however, the package is registered as "newer" and the bash binary ends up fixed, ...


1

In unpatched version of bash it stores exported function definitions as environment variables. Store a function x as, $ x() { bar; } $ export -f x And check its definition as, $ env | grep -A1 x x=() { bar } So one could exploit this by defining his own environment variables, and interprets them as function definitions. For example env x='() { :;}' ...


16

Let me explain: env x='() { :;}; echo OOPS' bash -c : This will print “OOPS” on a vulnerable system, but exit silently if bash has been patched. env x='() { :;}; echo OOPS' bash -c "echo this is a test" This will print “OOPS” on a vulnerable system, but print “this is a test” if bash has been patched. And you’ve probably heard that it has something to ...


0

If you want to keep the aliases, why not just do: alias ..='cd ..' alias ...='cd ../../' alias ....='cd ../../../' Or, if you need to go way back: alias .3='cd ../../../' alias .4='cd ../../../../' alias .5='cd ../../../../../' # how far back do you need to go on a normal basis..? No idea how well that helps you keep mentally in sync with ...


3

"You can't use slashes in an alias or function name"? That's news to me. I've been using the following shell function for years on Linux and OS X bash, and never had any trouble: function ../.. { cd ../..; echo "$PWD"; } Naturally, cd../.. is a fine function name as well. A slash can be used in a shell function name. As for the backslash version, you ...


5

/ and \ are among the characters which cannot appear in a Bash alias name. From man bash: The characters /, $, `, and = and any of the shell metacharacters or quoting characters listed above may not appear in an alias name. As a workaround, you can switch to Zsh, which allows both: % grep 'alias.*cd' .zshrc alias cd../..='cd ../..' alias cd..\\..='cd ...


8

You can't use slashes in an alias name. Bash allows them in function names, however, so you can make that a function: cd../.. () { cd ../..; } You can't use backslashes in an alias or function name. The backslash character quotes the next character, so cd..\.. is parsed as cd...., well before that string is looked up as a command name. If you want to call ...


1

There have been several Bash updates in Ubuntu in the past couple days. Run sudo apt-get update && sudo apt-get upgrade again, and the problem should disappear (I don't have it on my own 14.04 server). EDIT: For reference, the latest version of the bash package in 14.04 as of right now is 4.3-7ubuntu1.4.


0

Something was wrong with the sources in /etc/apt/sources.list. Replacing them with the sample list from http://ubuntuguide.org/wiki/Ubuntu_Trusty_Packages_and_Repositories and updating again fixed the issue.


0

You might need to update package metadata. Run apt-get update && apt-get upgrade. That should install all currently available security updates.


2

According to this Fedora Magazine post: env x='() { :;}; echo OOPS' bash -c : This will print “OOPS” on a vulnerable system, but exit silently if bash has been patched. This is the behaviour seen on: Debian squeeze (bash package 4.1-3+deb6u2) CentOS 6.5 (bash package 0:4.1.2-15.el6_5.2) Arch Linux (bash package 4.3.026-1) I speculate that this ...


6

Assuming you know or can guess the end of the range, you could use brace expansions: rm a_{000750..000850} The above will delete the 100 files between a_000750 and a_000850 inclusive. If you have too many files for that, use find: find . -name 'a_*' | while read file; do [ "${file#./a_}" -gt 000749 ] && rm -v "$file" done Here, the find ...


2

You could do something like this: find . -regextype posix-extended -iregex './a_[0-9]{6}' -execdir bash -c '[[ ${1##./a_} > 000750 ]] && echo $1' "removing: " {} \; Or: find . -regextype posix-extended -iregex './a_[0-9]{6}' | sort | sed '0,/000750/d' | xargs echo The first method assumes a fixed prefix, strips it off and checks the value. ...


1

Yes, it is correct. To verify that you're using a patched version of bash, test using the package management tools (or using the sample test command): $ apt-cache policy bash bash: Installed: 4.3-7ubuntu1.3 Candidate: 4.3-7ubuntu1.3 The bash version string remains unchanged as the patches were applied by the package maintainers, and not by upstream.


2

numberoflines=$(sed -n '$=' /tmp/lines.txt)


5

To extend Sylvain's answer, some helper functions: bold() { ansi 1 "$@"; } italic() { ansi 3 "$@"; } underline() { ansi 4 "$@"; } strikethrough() { ansi 9 "$@"; } red() { ansi 31 "$@"; } ansi() { echo -e "\e[${1}m${*:2}\e[0m"; } Then


8

The ANSI/VT100 terminals and terminal emulators are not just able to display black and white text; they can display colors and formatted texts thanks to escape sequences. Those sequences are composed of the Escape character (often represented by "^[" or "Esc") followed by some other characters: "Esc[FormatCodem". In Bash, the character can be ...


1

Recommended solution: Copy the following python script to a file called internal_block_device_resource: #!/usr/bin/env python3 import os import re from glob import glob rootdir_pattern = re.compile('^.*?/devices') internal_devices = [] def device_state(name): """ Follow pmount policy to determine whether a device is removable or internal. ...


0

Use lsblk: $ lsblk -o NAME -nl sda sda1 sda2 sda4 sda5 sda6 sdb sdb1 sdb2 sdb5 sdb6 sr0 This will include anything worth including. You can use the -I option along with the device types to do the filtering.


1

This works for me: echo DRIVES=\'`cd /dev; ls sd?; cd`\' It simply goes into the /dev-directory and outputs everything with sd and one more character. After that, it returns to home.


1

You can use the tee command: sort -u filename | tee filename > /dev/null The tee command reads from standard input and writes to standard output and files.


5

You don't need any extra command like cat and uniq and also without using rm command and mv command to removing and renaming the filename. just use simple command. sort -u filename -o filename -u, --unique with -c, check for strict ordering; without -c, output only the first of an equal run -o, --output=FILE write result to ...


0

Your suggested example (below) doesn't work because you'd actually be reading from and writing to the same file simultaneously. $ cat filename | sort | uniq > filename The idea with a pipe or redirect is that the command on the left and right hand side of each pipe or redirect run simultaneously, in parallel. The command on the right processes ...


6

You can use moreutils sponge: sort -u filename | sponge filename You also don't need pipe to uniq, since when sort has -u option to unique lines when sorting.


4

Sure. The mechanism of exploitation can work on multiple vectors as highlighted today. You just need something that eats a environment variable, goes on to run bash, and is running as root. Will I give you an example? No.


0

You can use /proc/net/dev to monitor network activity, something like this: packets() { # Get the number of packets of eth0 device cat /proc/net/dev | grep eth0 | cut -f5 -d' '; } LAST=$(packets) while [ true ]; do sleep 1; PACKS=$(packets) DIFF=$(($PACKS-$LAST)); # I consider idle less than 10 packets per second if [ $DIFF -le ...


-1

The ShockShell vulnerability affects many systems. Is my system affected? If you want to check if your system is affected, run the following command inside a terminal window running bash. Ubuntu's gnome-terminal runs bash by default (to see if you are running bash, then run echo $SHELL, and if it echoes bash then you run bash) : env x='() { :;}; echo ...


0

The bug occurs when bash gets executed with a specially crafted environment variable. Remote exploitation over SSH is only possible when bash is executed. When the ForceCommand SSH option is in use, that command always gets executed using the login shell of the authenticated user (see the manual page of sshd_config). Vulnerable configurations include ...


1

You cannot circumvent authentication by exploiting this bug. But SSH allows you to restrict what commands a user can run, e.g. by using ForceCommand in sshd_config. By exploiting this bug a user can circumvent this restriction and run any command she/he wants.


7

Note: The Security Patch for CVE-2014-7169 has been released as a standard security update. There is no need to add additional ppa's to receive this patch. Only the following is needed. sudo apt-get update sudo apt-get upgrade To ensure you have patched bash correctly, run the following command dpkg -s bash | grep Version If you are on 14.04 LTS, you ...


0

If you are on 11.04: use below steps (it worked for me) cd ~/ mkdir bash wget https://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz for i in $(seq -f "%03g" 0 25); do wget https://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i; done if it is not downloaded required patche then install ftp package apt-get install ftp for i in $(seq -f "%03g" 0 25); do wget ...



Top 50 recent answers are included