Tag Info

New answers tagged

0

show-all-if-ambiguous makes pressing tab once (instead of twice) show all completions. It also changes the way globs are completed: $ touch 1.0.{1,2} $ bind 'set show-all-if-ambiguous off' $ open *0* # I pressed tab twice here, and *0* was kept as *0* 1.0.1 1.0.2 $ open *0*^C $ bind 'set show-all-if-ambiguous on' $ open *0* # I pressed tab once here, and ...


2

Try adding this to ~/.inputrc: set show-all-if-ambiguous on show-all-if-ambiguous makes pressing tab once (instead of twice) list all completions. It also makes the first tab press insert shared prefixes of glob expressions. $ touch 1.0.{1,2} $ echo *0* # I pressed tab once here 1.0.1 1.0.2 $ echo 1.0. glob-complete-word (\eg) would also complete *0 ...


0

Another succinct option would be: [ -d .svn ] && { svn command 1; svn command 2; }


3

You want either: insert-completions ALT* for 'insert all completions' With this, a dir containing files name 'aa ab ac ad' ls a* followed by alt + * would complete to ls aa ab ac ad Man page entry on binding: insert-completions (M-*) Insert all completions of the text before point that would have been generated by possible-completions. ...


0

find . -name \*.mp3 -maxdepth 1 -print0 | shuf -z | while IFS= read -d $'\0' -r l; do printf %s\\n "$l"; done -maxdepth, -print0, shuf, read -d, and $'' are not defined by POSIX. On OS X you can install coreutils with brew install coreutils and use gshuf. read strips characters in IFS from the start and end of lines. -r disables interpreting backslashes. ...


1

The Cygwin FAQ mentions "resource temporarily unavailable" as one of the error messages that can occur because of the way Windows handles process creation. The potential solutions it lists are: Restart the process Remove all applications known to conflict with Cygwin Follow the instructions in /usr/share/doc/rebase/README to run rebaseall


7

For reference, in zsh, you can affect the order globs are expanded with the o globbing qualifier. For instance *.mp3(om) sorts by modification time. You can define your own sorting order with functions. With *.mp3(o+foo), the files are sorted, not based on their name but on the value that the foo function returns in the $REPLY variable for a given filename ...


5

You can use the shuf command to shuffle lines for you. Just backtick a list command where you have *.mp3 and pipe it to shuf, such as: #!/bin/bash - SAVEIFS=$IFS IFS=$'\n'; set -f for i in `find . -maxdepth 1 -iname '*.mp3' -type f | shuf` do echo "$i" done IFS=$SAVEIFS; set +f The above assumes GNU find and that file names don't contain newline ...


5

You can change the here-doc operator to <<-. You can then indent both the here-doc and the delimiter with tabs: #! /bin/bash cat <<-EOF indented EOF echo Done Note that you must use tabs, not spaces to indent the here-doc. There can not be any quotes around the first EOF delimiter, else parameter expansion, command substitution, and ...


1

An alternative to sourcing the scripts is simply calling them with arguments. If you've already broken up most of your functionality into shell functions, you're probably quite close to being able to do this already. The following snippet of Bash allows any function declared in a script to be used as a subcommand: if [[ ${1:-} ]] && declare -F | cut ...


2

_lnpxe() { HOSTFILE=/etc/hosts local word COMPREPLY=() if [ 1 -eq "$COMP_CWORD" ]; then pushd /home/tftp/config &>/dev/null || return 1 word="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=($(compgen -f "$word")) popd &>/dev/null fi if [ 2 -eq "$COMP_CWORD" ]; then word="${COMP_WORDS[COMP_CWORD]}" ...


2

chmod -R o-w . Will remove write permissions to others for every file in a safe way. It will however update the ctime of every file including the ones for which others already didn't have write access. With GNU chmod, you can make it show which files needed updated with the -c option: $ chmod -cR o-w . mode of `./a' changed from 0777 (rwxrwxrwx) to 0775 ...


0

To open all index.php in the current working path vim -p `find . -name index.php`


0

Check output of w command. You will see login type (X display) in LOGIN@ field.


0

Use login session startup script ~/.xprofile to create some flag file for you. Be it ~/.xlogin_flag, then in your other script use inotifywatch from package inotify-tools to see it being created, touched or deleted.


1

Your approach is a performance nightmare: You create two processes for every file! One completely uselessly because find already has this information and can easily print it. This is a better solution: find . -perm -o=rwx -printf "%m %p_\0" 2>/dev/null | while read -r -d '' perms path; do path="${path%_}" echo "${perms} '${path}'" >&2 ...


1

Ok, after several tries I sorted this up: rsync -vaiz --delete --exclude=.svn/ --include='*.php' --include='*.js' \ --include='*/' --exclude='*' --prune-empty-dirs \ --filter "protect .svn/" /origin /destination Thank you


1

/007 will show your only files that have no permissions for owner and group, and all permissiosn (rwx) for other. You might have more luck with /o=rwx. That will match only the other permissions for the file. EDIT FOR CORRECTNESS: Apparently, you'll need to use -perm -o=rwx, because the /o is an inclusive filter, and would match files where other has ...


1

1st attempt (didn't work) You need to include the directories in addition to the files: rsync -zavC --delete --include '*/' --include='*.php' --include='*.js' \ --exclude="*" /media/datacod/Test/ /home/lucas/Desktop/rsync/ 2nd attempt rsync -avzC --filter='-rs_*/.svn*' --include="*/" --include='*.js' \ --include='*.php' --exclude="*" --delete ...


2

Generic Colouriser Generic Colouriser could be used for this application. It has the capability to identify via regular expressions bits of text, and then assign a color to any that match. # this is probably a pathname regexp=/[\w/\.]+ colour=green count=more This will match /usr/bin, /usr/local/bin/, /etc/init.d/syslogd and similar strings and paint it ...


2

You might want to have a look at toilet. The following has been incorporated in the banner of one of the servers at my lab: You can install it on Debian based systems with sudo apt-get install toilet TOIlet prints text using large characters made of smaller characters. It is similar in many ways to FIGlet with additional features such as ...


0

@Philomath, unsetting those environment vars does not work for me at all! For me, this causes bash to use its inbuilt defaults (it seems) of truncating .bash_history to about 9KiB. What does work for me is the following in my .bashrc: export HISTSIZE= export HISTFILESIZE= shopt -s histappend


6

TL;DR: Put supporting files in /usr/local/lib/my_app_name and main script in /usr/local/bin. Of course you will get many suggestions for different places to put things, as there is not much standardization for this kind of thing. I prefer to put files of this type in /usr/local/my_app_name/ or /opt/local/my_app_name, depending on where you install ...


8

One thing that hasn't been noted so far is that uniq compares whole line lexically, while sort's -u compares based on the sort specification given on the command line. $ printf '%s\n' 'a b' 'a c' | sort -uk1,1 a b $ printf '%s\n' 'a b' 'a c' | sort -k1,1 | uniq a b a c $ printf '%s\n' 0 -0 +0 00 '' | sort -n | uniq 0 -0 +0 00 $ printf '%s\n' 0 -0 +0 00 '' ...


11

One difference is that uniq has a number of useful additional options, such as skipping fields for comparison and counting the number of repetitions of a value. sort's -u flag only implements the functionality of the unadorned uniq command.


6

As tagged bash, here is a bash 4.0 alternative to choroba's answer, to avoid wc and sed: bash-4.2$ mapfile -t a < file bash-4.2$ (IFS='+'; echo "(${a[*]})/${#a[@]}") | bc -l 1.24886080000000000000


0

term=0 file=input for number in `cat "$file"`; do term="${term}+${number}" done total="$(echo "$term" | bc -l)" average="$(echo "${total}/10" | bc -l)" average="$(echo "$average" | sed -e 's/^\(.*\..*[^0]\)0*/\1/' -e p)" echo "Total: ${total}" echo "Average: ${average}"


8

You may not want to use bc for this. Perhaps awk would work better: awk '{sum+=$1};END{print sum/NR}' /path/to/file


2

I usually use bc for floating point arithmetics: file=1.txt echo '('$(<$file)')/'$(wc -l < $file) | sed 's/ /+/g' | bc -l


1

Edit: OK. Seems like I might have misread the situation. Thought you meant program options as in: $ mplayer_alias -pla<tab><tab> -playing-msg -playlist $ but guess it is file completion. I don't know, but give it a go. As a quick fix this should work: complete -f -o default ee Giving: $ ee<tab><tab> file1 file2 file3 $ as ...


18

sort | uniq existed before sort -u, and is compatible with a wider range of systems, although almost all modern systems do support -u -- it's POSIX. It's mostly a throwback to the days when sort -u didn't exist (and people don't tend to change their methods if the way that they know continues to work, just look at ifconfig vs. ip adoption). The two were ...


2

You can escape the slashes, like sed -e 's/"@base_url = "http:\/\/dmstaffing-stage.herokuapp.com\/"/d'. This jungle of /\/\//\// is a symptom of what is called LTS (Leaning Toothpick Syndrome). The best way around this is to just use another delimiter, like ; in your case, or whatever other non-alphanumeric character tickles your fancy today (and isn't ...


4

As mentioned, use other separator or escape the slashes. Your last try misses escape of last slash. And as pointed out by @StephaneChazelas, escape dot's as well. And, including @terdon if sed is not needed; grep -Fxv, where -F is fixed string, not regex, would be an option. -x makes sure it matches whole lines. -v inverts. A simple (very simple) ...


3

The slashes in the regex are messing up with sed's delimiters. But you can use different delimiters than the slash. For example: sed 's#@base_url = "http://dmstaffing-stage.herokuapp.com/"##' xx


3

Try using another separator: sed 's|@base_url = "http://dmstaffing-stage.herokuapp.com/"||' xx


1

I'm using the Firefox Add-On R-Kiosk in my kiosk systems.


0

Did you try something like this? while read LINE <&4; do printf "%s\n" "$LINE" # just to watch that command is proper comm="$LINE" # asssign command to a variable $comm # execute command done It worked for me using bash.


1

Edit: Sliced it up some more. You might find this useful, from Debian Administration: An introduction to bash completion. Complete script: /some/location/my_ssh_autocomplete_script (only meant as a short starter): #!/bin/bash _get_rsync_file_list() { # For test: #local -a flist=("foo" "bar") #printf "%s " "${flist[@]}" # Or: ls /tmp ...


1

I prefer to use this: curl curlmyip.com It's short and simple to remember.


1

Puppet allows you to define which services should be running on your system. Puppet is IT automation software that helps system administrators manage infrastructure throughout its lifecycle, from provisioning and configuration to patch management and compliance. Using Puppet, you can easily automate repetitive tasks, quickly deploy critical applications, ...


1

Here's an idea using Perl to execute the script for you. You could translate this to your language of choice, or probably even bash. It's really the commands to connect to the wireless that count. Perl is just a means for me to do this quickly, your idea of quick may be different. A note if you're not used to reading Perl everything backticks is a shell ...


0

There's also God. God is an easy to configure, easy to extend monitoring framework written in Ruby. Keeping your server processes and tasks running should be a simple part of your deployment process. God aims to be the simplest, most powerful monitoring application available. Write a simple server, server.rb: loop do puts 'Hello' sleep ...


2

You can use sed to write at a particular line. try this: sed -i '33ianything' textpath or sed -i '33i\anything' textpath It will insert "anything" in line number 33.


0

To keep the first 32 lines and add new text afterwards: head -n 32 oldfile > newfile echo anything >> newfile echo goes >> newfile echo here >> newfile To insert some text after line 32 of a file: sed -e '32s/$/\nanything\ngoes\nhere/' oldfile > newfile


2

In addition to what Chris Down wrote, I would also recommend monit. It can notably check if a port if open (eg 80) and restart the appropriate service (eg httpd) if this port is closed. See this example for sshd : check process sshd with pidfile /var/run/sshd.pid start program "/etc/init.d/sshd start" stop program "/etc/init.d/sshd stop" if failed port 22 ...


5

There are various tools to do this (of which, other than daemontools and perp, I don't have much experience with): daemontools is more or less the "classic" implementation that spurned most of the other modern implementations supervisord minit s6 runit The one we have come to like at my workplace is perp, which was the best featured for our ...


3

That'd be a bug or limitation in bash. Somehow, bash closes the file descriptor 63 which was the reading end of the pipe which echo is writing to before executing fgrep. zsh or ksh93 don't have that limitation. In this very case you don't need the two processes anyway: ff() { fgrep -f "$1" < /etc/group; } In the general case, you can either use ...


0

Your ulimit -u is < 144. Have an admin change that.


4

summary: You should use jobs to list, and use kill %n to kill the n'th backgrounded process, and if your bash supports it : kill %-1 will kill the n-1'th backgrounded process. details: # find / -print >/dev/null 2>/dev/null & [1] 1291234 # find /./ -print >/dev/null 2>/dev/null & [2] 2162424 # find /././ -print >/dev/null ...


2

Take a look at the command line tool rhythmbox-client. Looking at the options there's a --seek switch which should do what you want. rhytmbox-client --seek=+60 There are reports that this should work but doesn't. Might be a bug? As an alternative method you can fire the commands directly yourself using dbus: # seek forward 60 sec dbus-send --print-reply ...



Top 50 recent answers are included