Tag Info

New answers tagged

0

Looks like it can't create the log file. Check the permissions of /var/log folder. It should be ls -l /var/ drwxrwxr-x 18 root syslog 4096 Mar 6 14:30 log If it doesn't look like the first starting with the drwxrwxr-x, change the permissions to the folder by typing in the following: sudo chmod 775 /var/log Run the cron job again.


0

Similar solution to @heemayl, with tighter code, which works on Python 2.7 and Python 3. #!/usr/bin/python import collections import fileinput import itertools import string count = collections.Counter(itertools.chain(*fileinput.input())) print(',\n'.join('{} - {}'.format(c, count[c] + count[c.upper()]) for c in string.ascii_lowercase)) ...


0

You can get them using gsettings get com.canonical.Unity.Launcher favorites and set them with gsettings set com.canonical.Unity.Launcher favorites VALUE where VALUE has the same format as what you've gotten from gsettings get ...


1

Likely what happened is you concatenated two separate echo commands on a single line, causing the second command (complete with the echo) to get written to the file (instead of the output of the command). Open your ~/.bashrc file in any text editor, and replace the line echo export PATH by plain export PATH It's a list of directories that are searched (in ...


2

Here another solution (in awk)... cat 1.txt | awk ' { for (indx=length($0); indx >= 1; --indx) ++chars[tolower(substr($0, indx, 1))] } END { for (c in chars) print c, chars[c]; } ' | sort It creates an associative array with each character as the index value and the count as the array value. The END action prints ...


3

By default in awk the Field Separator (FS) is space or tab. Since we want to count each character, we will have to redefine the FS to nothing(FS="") to split each character in separate line and save it into an array and at the end insideEND{..} block, print their total occurrences by the following awk command: $ awk '{for (i=1;i<=NF;i++) a[$i]++} END{for ...


3

A bit late, but to complete the set, another python(3) approach, sorted result: #!/usr/bin/env python3 import sys chars = open(sys.argv[1]).read().strip().replace("\n", "") [print(c+" -", chars.count(c)) for c in sorted(set([c for c in chars]))] A - 1 M - 1 O - 1 T - 1 a - 4 c - 1 k - 1 n - 1 o - 4 s - 2 t - 3 w - 2 y - 1 Explanation Read the file, ...


2

The following perl oneliner will do the count. I put the regex in list context (to get the number of matches) and put that into scalar context: $ perl -e '$a=join("",<>);for("a".."z"){$d=()=$a=~/$_/gi;print"$_ - $d,\n"}' 1.txt a - 5, b - 0, c - 1, d - 0, e - 0, f - 0, g - 0, h - 0, i - 0, j - 0, k - 1, l - 0, m - 1, n - 1, o - 5, p - 0, q - 0, r - 0, ...


2

Here is a solution using Python: #!/usr/bin/env python2 import collections, string with open('1.txt') as f: input_string = f.read().replace('\n', '').lower() count_dict = collections.Counter(input_string) for char in string.lowercase: print char + ' - ' + str(count_dict[char]) + ',' Here we have used the collections module's Counter ...


10

You could use this: sed 's/\(.\)/\1\n/g' 1.txt | sort | uniq -ic 4 5 a 1 c 1 k 1 M 1 n 5 o 2 s 4 t 2 w 1 y The sed part places a newline after every character. Then we sort the ouput alphabetically. And at last uniq counts the number of occurences. The -i flag of uniq can be ommited if you don't want case insensitivity.


2

Do a for loop for all the characters you want to count, and use grep -io to get all occurences of the character and ignoring case, and wc -l to count instances, and print the result. Like this: #!/bin/bash filename="1.txt" for char in {a..z} do echo "${char} - `grep -io "${char}" ${filename} | wc -l`," done The script outputs this: a - 5, b - 0, c ...


2

The crontab file is indeed provided by the cron package. This package is installed by default (See the 12.04 Manifest). The crontab command should already be in your $PATH: $ type crontab crontab is /usr/bin/crontab Check the Official documentation to know how to set up your crontab.


0

Command GNU sort has the following option: -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G). To have this option on BSD/OSX, you can install sort from coreutils (via brew) and add the bin folder to your PATH into your rc files. So the command would looks like: du -ah . | sort -rh | head -20


0

To print to STDOUT and insert newlines at the beginning of your log file you'll have to rewrite it completely each time that could be really memory consuming. This is a perl command that should do what you need though: oldscript.sh | perl -ne '$log=$_.`cat my_log.txt`; open(F, ">", "my_log.txt"); print F $log; print' Juts change the path to my_log.txt ...


0

Unless you have a directory named $'2\n' in your current directory, I don't understand it. The syntax *(pattern) is an "extended globbing" pattern (ref) that returns zero or more of the given pattern. Given your pattern (a 2 and a newline) I would expect that to return null. And then calling your function with no arguments should simply cd to your homedir. ...


0

cp cannot copy directories unless it is used with switches like -R , -r or -a. Click here for more info


2

From the GNU info page for cp: By default, 'cp' does not copy directories. However, the '-R', '-a', and '-r' options cause 'cp' to copy recursively by descending into source directories and copying files to corresponding destination directories. https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html#cp-invocation


0

You're just trying to execute android? You probably just need to mark it as executable. chmod +x /home/vinod/android-sdk-linux/tools/android Then execute it as you mentioned.


3

Try help cd: Options: -L force symbolic links to be followed: resolve symbolic links in DIR after processing instances of `..' -P use the physical directory structure without following symbolic links: resolve symbolic links in DIR before processing instances of `..' -e if the -P option is supplied, and the current working ...


4

http://bioconductor.org/biocLite.R is an R file. The command you're using is a R command syntax... But you're currently in a Bash shell. Run R for an R shell, then try it again. From the install page: Install the latest release of R, then get the latest version of Bioconductor by starting R and entering the commands ...


0

Probably that you had a function declared with this name (source), which is also part of bash in-built commands. The bash's source command will execute just local files. To make it work again, declare again your own source function.


3

If this works: ls | grep -i 'book_i_want' Then, so will this gnome-open *book_i_want* To make it case insensitive: shopt -s nocaseglob gnome-open *book_i_want* In fact, both of the above will work better than using ls since they can deal with any file name, including those with whitespace and strange characters, which ls can't.


0

Create a bash script in your /usr/bin folder, it should look something like this #!/bin/bash # Whatever combination of commands you want to run. Name the bash script what you want to type in to the terminal and make it excecutable: chmod +x filename


0

Do you mean that: function my_command { echo "Blah $1 bleh $2" } and then my_command a b ? Of course you must load this function somehow, usually by including from ~/.bashrc. Frequent idiom is putting sth like for i in $HOME/.bash.d/*.sh; do source $i done on the end of your ~/.bashrc, then every file you put into ~/.bash.d/ will be ...


5

To answer the initial question, you would pipe through xargs if you wanted to launch something with STDIN as an argument. ls | ... | xargs gnome-open Or you could treat the output like an argument directly. This is less useful in very long directories as you might hit the argument limit. xargs is almost certainly faster. gnome-open $(ls | ...) But you ...


4

As 'David Foerster' has pointed out hyphen(-) is not treated specially by shell. So as far as your example is concerned you can simply do: mv 12F-XYZ.pdf 13F-XYX_ABX.pdf But if you have a space or literal escape character (backslash) or any other that needs to be escaped, you can escape those with either the escape character i.e. \ or put the whole name ...


5

This should work: loadval=$(sar -u 1 10 | awk '{print 100-$8}')


1

Add this line to your ~/.bash_aliases: alias opn='gnome-open'


6

To find which file defines JAVA_HOME, run: PS4='+ $BASH_SOURCE:$LINENO:' BASH_XTRACEFD=7 bash -xlic "" 7>trace.out This generate debug output for a bash login shell and saves it to the file trace.out. There will be many lines in that file. The lines look like: + /etc/profile:7:PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games + ...


1

You may have seen the $'...' syntax, which causes the shell to interpret backslash sequences: NC=$'\e[0m' # no color or formatting RED=$'\e[1;31m' # color red GRN=$'\e[1;32m' # color green BLU=$'\e[1;34m' # color blue Another way to do this, using tput: NC=$(tput sgr0) # no color or formatting RED=$(tput bold; tput setaf 1) ...


0

use man pages in ubuntu in the terminal type man <command name> eg: man wget it will shows up a detailed description of the command including options.


10

You can define a function in your ~/.bashrc as follows showred(){ export RED='\033[1;49;91m' export NC='\033[0;0;0m' echo -e $RED"$@"$NC } Source ~/.bashrc as . ~/.bashrc or open a new terminal and try. Also you can write in colours while writing something on terminal using echo or printf as following,


4

declare -r RED='\033[0;31m' declare -r GREEN='\033[0;32m' declare -r NC='\033[0m'


2

How about something like this: start vmstat with its output directed to a log file, and background it & [optional] sleep for a few seconds (to get a baseline) && [when sleep exits] start stress e.g. vmstat 1 20 > vmstat.log & sleep 5 && stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s in this case, giving $ cat ...


1

Booting from a live CD is booting nothing else but what is on the CD. We won't be able to control this from our existing installation on our hard drive because our computer will not access it during boot. We may however create a customized live session to include all we need there: How to customize the Ubuntu Live CD? On a live session desktop icons will ...


0

I am not sure why this works..but MACHINE=smarc-samx6i source setup-environment build works alright instead of the given instruction using MACHINE=smarc-samx6i ../setup-environment build.


0

Your alias wasn't working because it wasn't sourced and this is a frequent problem, having been asked before. As you have noted it was only the text of your question that had the extra typo and not the alias you had placed in your .bashrc, but your modification needed to be re-read for the interactive terminal. Placing an alias in .bashrc with the ...


1

The arecord command has the -d argument to time it out with this modification the arecord command will time out but not the FLAC. arecord -q -t wav -d 4 -f S16_LE -r 16000 | flac - -f --best --sample-rate 16000 -s -o "$TEMP_FILE"


-3

I found the answer. I just added the file into the .bash_aliases file instead. NOTE: I didn't ever have a space before the equal sign. That was just a typo.


2

The reason why your code is not working is because you have got an extra space in the wrong place, try changing your code to this, saving, and then launching a new Terminal session and trying again: alias runmc="java -jar /root/.minecraft/launcher.jar" Although it is recommended that instead of declaring aliases in the .bashrc file that you instead create ...


3

You can use on_ac_power to run a script when the power supply is turned on or off. Try the following in a terminal. $ on_ac_power $ echo $? 0 ## Laptop on ac power $ on_ac_power $ echo $? 1 ## Laptop on battery (not on ac power) Based on this you can make your script as, #!/bin/bash while true do if on_ac_power; then ...


1

Wile using HEREDOC delimiter, there should not be any lagging or trailing spaces and the delimiter should be the only word on the line. I this example, I had a space after EOF which was causing all the issue. Script is working as expected after removing that lagging space!! Credit for this answers goes to the user Carlos Campderrós on StackOverflow. Just ...


6

$ sleep 10 & [1] 24446 $ [1]+ Done sleep 10 The [1] 24446 and [1]+ Done ... are printed by the shell. From man bash: When bash starts a job asynchronously (in the background), it prints a line that looks like: [1] 25647 You can disable the Done output by disabling monitor mode: set +m You cannot disable the first ...


0

You are getting the Error: Unable to access jarfile spigot.jar Errormessage because the script are using your bash environment working directory when it is executing. The script is probably executing java -jar spigot.jar where spigot.jar file must reside in the same directory. Since youre scripts environment is pointing at another directory the file ...


0

To get rid of the "./" expression for your script, You must have to set the custom path for your scripts in PATH variable. You can do it either using the export Command ( which will set up the variable under current running environment) or as below (for permanent solution) To do so; Edit the .bashrc file in your home directory with your favorite Editor ...


0

You didn't setup your alias correctly, you should setup it like so: alias minecraft='sh /var/www/owncloud/data/admin/files/Spigot/start.sh'


1

The current (accepted) answer doesn't work if you switch files/buffers within one of your vim sessions. The title won't get updated. The following is enough to have automatically updated titles in gnome-terminal also when you switch files by using :e foo.txt, :b0, :b#, etc. Just place this in your ~/.vimrc file: autocmd BufEnter * let &titlestring = ' ...


2

You missed a space between [[ and $REPLY: while [[$REPLY != 0 ]]; do should be while [[ $REPLY != 0 ]]; do


0

I'm no expert but I think the problem was the open input stream. This code does the trick: ### Actual Work ### if [[ $manual == 0 ]]; then # Read the servers from the config file. while read line; do # Read line by line. arguments="$arguments $line" # Build a string for $arguments out of the ...


0

This can be done using a script crossfade_cat.sh it was answered here http://stackoverflow.com/questions/28652490/cross-fading-several-audio-files-using-sox/28670099#28670099 And using this script to call it crossfade_dur=1 i=0 for file in *.wav do i=$((i+1)) if [ $i -eq 1 ] then cp $file mix.wav else crossfade_cat.sh ...



Top 50 recent answers are included