Tag Info

New answers tagged

0

This is the one-liner that you need. No other config needed: mkdir longtitleproject && cd $_ "$_" is the last argument of the previous command.


2

With bash-4.2 or above: printf '%(%F %T)T\n' 1234567890 (where %F %T is the strftime()-type format) That syntax is inspired from ksh93. In ksh93 however, the argument is taken as a date expression where various and hardly documented formats are supported. For a Unix epoch time, the syntax in ksh93 is: printf '%(%F %T)T\n' '#1234567890' ksh93 however ...


2

With zsh you could use the strftime builtin: strftime format epochtime Output the date denoted by epochtime in the format specified. e.g. zmodload zsh/datetime strftime '%A, %d %b %Y' 1234567890 Saturday, 14 Feb 2009


2

You are assuming that the output of who | grep jeevansai will be a single line, which is wrong. ++ who ++ grep jeevansai ++ cut -c 32-34 + ld='31 31 ' This is telling you that the command ld=`who | grep "jeevansai" | cut -c 32-34` set the variable ld to "31 31", rather than to a single number as you were expecting. Later, you try to do math on it ...


0

You can use this function :). Copy that code into file with name SendMessage.sh #!/bin/bash SendMessage() { com=`tty` set `who am i` who | grep -v "$1" >filef.txt exec < filef.txt array="" while read line do set $line echo $1 array+=($1) done rm filef.txt exec <$com echo ...


4

In bash, this will delete everything in the current working directory which has the prefix ._: rm ._* If what you actually wanted to do was change their names to a form without the prefix, you can run: ls ._* | while read line do mv -- "$line" "${line:2}" done


0

First check if your assumption is true. Set loglevel to "verbose" and restart mpd. The logs will tell you. Set the log to "syslog" and follow the syslog with tail this will give you a glance on the interaction with pulse/alsa and more flexibility in troubleshooting. Possible reasons: Auto scan is not set. Update the database from within ncmpcpp. MPD has ...


0

It easy can be done by adding less command to special variable LESS: LESS=+/-T man ls where /-T is less command /find -Tpattern


3

While chaos's answer is good to be used in interactive shells, this one can be used as a POSIX script, for example if you need to do this periodically and/or do it on another computers. #!/bin/sh i=0 while test "$((i+=1))" -lt 366 ; do for j in 00 06 12 18 ; do file="GLDAS_NOAH025SUBP_3H.A2003$(printf '%03d' ...


2

You can do that piping man though less and using the -p flag: -ppattern or --pattern=pattern The -p option on the command line is equivalent to specifying +/pattern; that is, it tells less to start at the first occurrence of pattern in the file. Examples: man ls | less -p -T man git-log | less -p -S Since you'll land ...


5

A variation on @chaos solution (bash 4.0 or above or zsh 4.3.11 and above): for a in GL.....2003{001..365}.{00..18..6}00.001.2015210044609.pss.grb do [[ -f $a ]] || echo "$a" done or for a in {001..365}.{00..18..6} do [[ -f "GL.....2003${a}00.001.2015210044609.pss.grb" ]] || echo "$a" done to print only the missing day+hour


10

With zsh or bash4, you can use brace expansion for that: ls -d GLDAS_NOAH025SUBP_3H.A2003{001..006}.{0000,0600,1200,1800}.001.2015210044609.pss.grb >/dev/null Notice the brackets: {001..006} means expand to 001, 002, ... 006 {0000,0600,1200,1800} to every one of the above add 0000, 0600, 1200 and 1800. >/dev/null is to avoid the standard output of ...


2

Build the file names in a loop and then test for non-existence of a file: for day in `seq -f "%03g" 1 30` do for hour in 0000 0600 1200 1800 do filename="GLDAS_NOAH025SUBP_3H.A2003${day}.${hour}.001.2015210044609.pss.grb" if [[ ! -e $filename ]] then echo "File missing: $filename" fi done done Note: I do not guarantee this ...


2

Here comes a memo to resize an NTFS partition using commandline with ntfsresize (from the ntfs-3g / ntfsprogs package) and fdisk, that should work for Windows XP-to-8 versions. Note that GParted does all the following for MBR/DOS as well as for EFI/GPT drives if ntfs-3g / ntfsprogs is installed. My references are at the end. OK in this scenario I have a ...


0

To change the hostname on a SUSE system you need to change the following files: /etc/HOSTNAME /etc/hosts You may also have other configuration files where it's stored (e.g., postfix configuration files), so a grep -R for the old hostname in /etc is probably a good idea: grep -R <oldhostname> /etc where <oldhostname> is the old hostname).


2

I suspect that you're looking for set -o notify, available in ksh, bash, zsh, and even POSIX sh, which causes job completion notifications to be printed immediately, even if you're at typing a prompt or if some other job is in the foreground. (If that's not what you're looking for, please clarify your question, maybe with an example of how it would look ...


0

You can create a shell function : myjobwatch() { while true; do jobs; sleep 2; clear; done; } Then just execute myjobwatch


1

Here's a quick script I wrote further to my comment, that in the SIMPLE case of aliases will work. For anything with arguments/etc., though, it will fail miserably. cmd="$1" type=aliased while [ "$type" = "aliased" ]; do output="$(type "$cmd")" type="$(cut -d ' ' -f 3 <<< "$output")" cmd="$(cut -d '`' -f 2 <<< "$output" | tr -d ...


5

You can use the DEBUG trap to do this. In this trap, $BASH_COMMAND contains the command last executed. trap 'echo "you tried to call the command [$BASH_COMMAND]"' DEBUG Note that, if you are executing commands as part of your prompt or $PROMPT_COMMAND, the trap will run on these as well. You can add checks to see if $BASH_COMMAND is the same as ...


2

The role of an X11 window manager is quite complex. First, learn more about X core protocol and X architecture. Then read EWMH if you need to understand the conventional roles of WMs (also known and respected by X11 toolkits like GTK, Qt, etc...). Even single-application but multiple-windows (e.g. popups) programs practically need some WM Then you could ...


1

You could use shuf: shuf -zn8 -e *.jpg | xargs -0 cp -vt target/ shuf shuffles the list of *.jpg files in the current directory. -z is to zero-terminate each line, so that files with special characters are treated correctly. -n8 exits shuf after 8 files. xargs -0 reads the input delimited by a null character (from shuf -z) and runs cp. -v is to print ...


1

You could retrieve files in this way: files=(/tmp/*.jpg) n=${#files[@]} file_to_retrieve="${files[RANDOM % n]}" cp $file_to_retrieve <destination> make a loop 8 times. Hope it helps


0

An alternative way, which is more readable, is to define a separate function which contains all your other commands and then call that function with xargs in a sub-shell. Hence, for example: myfunc(){ [ "$1" -ge 95 ] && echo "No Space on disk $1% full -- remove old backups please" echo "Another command echoing $1" } export -f myfunc echo 95 ...


0

There is a better solution. In /etc/xdg/xfce4/xfconf/ you find the default config tree for all users. It has the same style as the tree in ~/.config/xfce4/xfconf, so you can just copy the settings you want as default in this place. Or you provide just a part of it (make sure every single file is valid XML).


1

You can use FancyAudio gem for this. It can add album art to mp3 files. Documentation is available here. features add album art to single mp3 file add album art to multiple mp3 files. Below screen shot shows the output of fancy_audio when run in a folder containing an image and multiple mp3 files Below screen shot shows the output of fancy_audio when ...


0

So, to (finally) answer your actual question ... for 1.6 (or later) see the excellent answer noted (http://unix.stackexchange.com/a/79411/22565), else ... you're already doing as best as can be done - there is no "don't delete my file" option, except, as you noted, via -c. In my case I have to do gzip -dc {file} | tar xvz. Don't ask me ... (alias ...


0

Don't assign variables with a dollar sign. Dollar signs are only used to read variables. ShellCheck and ExplainShell are wonderful for debugging shell commands.


3

You're on Ubuntu, so I'll assume you're using bash. When you define a variable, you do it like this: you@ubuntu:~$ a="hello" No spaces. No dollar sign. It won't work otherwise. You use the dollar sign whenever you want to use that variable you defined: you@ubuntu:~$ echo $a hello Your third command should output the literal letter 'a': you@ubuntu:~$ ...


1

The following bash one-liner will do approximately what you describe, putting each directory into its own tarball. for d in dir/*/; do { tar -cj "$d" > "${d%/}.tar.bz2" ; } & done ; while [ "$(jobs)" ] ; do fg &>/dev/null ; done ; echo done


-1

I got solution for it: grep -A 2 -f 'INPUT.txt' *.* >> RESULT.txt


0

Enter telnet command mode (press current escape character, C-] by default) while connected to remote host, and run send dont echo command, then exit command mode.


1

PATH Variables needed to be added. cd ~ vi .profile Append: :/home/user/.local/lib/aws/bin/ Behind: PATH=":$HOME/bin # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH:/home/user/.local/lib/aws/bin/" fi aws --version


2

I don't think it's a bad idea to harden your system by protecting accounts as good as possible as you can. In many situations it will introduce extra hurdles during authentication, but if you're willing to cope with that it's all fine. An important thing to take into account, though, is the risk of actually introducing more flaws by increasing the complexity ...


5

I'm not sure why you would want to do that. If you're concerned about security, if someone discovers your password on 1 July, they'll know it on 31 July or 15 September... To answer your question, if you want to ensure that the password update is done either at a scheduled time or when the system restarts, you want to install anacron. It can do periodic ...


2

There's no standard definition for “fully start”. If you come up with a definition, there may or may not be a way to detect it. If your definition of “fully start” is “wait until the application becomes idle, waiting for user input”, then you can trace its system calls and look how long it takes to start reading user input. strace -o myapp.strace -tt myapp ...


0

memory.presure_level is for receiving events, not for showing the level. You can get idea about current memory pressure by comparing memory.usage_in_bytes with memory.limit_in_bytes and memory.soft_limit_in_bytes. For looking for what happens in actual memory.presure_level I have developed a simple tool: https://gist.github.com/vi/46f921db3cc24430f8d4. It ...


0

sh -c 'echo "\"left'"'"'right\""' OR sh -c 'echo "\"left'\''right\""' will work. Either of the above will pass echo "\"left'right\"" after -c. When you're inside a single quoted string there is no escaping other than closing that string. To pass a single quote, you can either use "'" or \' . The shell will concatenate adjacent ...


0

sudo -u chris sh -c 'echo "\"left'\''right\""'


1

This is the reason why it fails on my build: checking for the kernel version... unsupported (3.14.13-c9) configure: error: Valgrind works on kernels 2.4, 2.6


0

At first guess (you'll have to dig its source code for confirmation) less is a user interface tool: it changes the terminal behaviour. You can see less like a lightweight shell (it has internal commands such as / for searching). What you see may not be redirected. Literally: it has no [standard] output. The proper tool for the job you require is nl, like ...


7

less is the wrong tool for the job. You can use cat for that: cat -n file1 >file2 Or nl: nl -ba file1 >file2 Or pr: pr -n -t -T file1 >file2 Or sed: sed '/./=' file1 | sed '/./N; s/\n/\t/' >file2 Or grep: grep -n . file1 | sed 's/:/\t/' >file2 Or awk: awk '{ $0 = NR "\t" $0 } 1' file1 >file2 Or again awk: awk '{ sub(/^/, ...


2

Perhaps this suits. Makes use of the grep -A (after-context) option, to output the matching line and the 3 subsequent lines. find . -name file\* -exec grep -A 3 ABC {} \; > result-filename NOTE: You shouldn't place result-filename in directoryname. (See: grep: input file 'X' is also the output). To cover multiple patterns: find . -name ...


1

The following will search all not-dot files in the current directory: sed '/string/{ $!N;$!N;$!N;$!N w ./new_out_file }' ./* To do multiple -Fixed-string matches with grep -A w/o find and w/o the filenames prepended to each match, you just first need a single stream. cat ./* | grep -A2 -Ff pattern_file >outfile


0

What do you mean by "app"? A GUI app? And which app? And what do you mean by "start up"? All programs pretty much start instantly — the delay is in the receiving the output.


2

There are commands that are similar to the double-click: see and open. They may not be on every distro, but they are there on my Ubuntu 12.04 server. It would be good to point out that extensions are actually kind of arbitrary. There are so many esoteric extensions out there; no program, including the "double-click" can possibly know how to interpret every ...


0

You could combine all files into one by feeding two commands into find: output first the file name (or a preprocessed version thereof) and then the contents: find /home/ -maxdepth 2 -iname ".bash_history" -type f \ -exec sh -c "echo {} >> combined.txt && cat {} >> combined.txt" \;


0

Something like this can be done: #Assuming there are N folders folder1,folder2...folderN for folder in folder* do cd $folder for file in * do #if file with .xmp extension exists in ~/A folder [[ -f $file ]] && [[ -f ~/A/$file.xmp ]] && mv ~/A/$file.xmp . done cd .. done


1

for dir in folder*/ do for f in "$dir"* do base=${f#$dir} [ -f "A/$base.xmp" ] && mv "A/$base.xmp" "$dir" done done


0

First extract the video frame you desire into an image + then crop the image. To extract a frame where you know the timecode of the exact frame... ffmpeg -i my_clip_1280_720s.yuv -ss $frame -r 1 -f image2 image.jpeg To extract all frames so you can review each one + pick a frame... mkdir work ffmpeg -i my_clip_1280_720s.yuv -ss $frame -r 1 -f image2 ...


1

shw@shw:/tmp $ ls testdir/!(*/) & pidls=$! [1] 18453 shw@shw:/tmp $ shw@shw:/tmp $ cat /proc/18453/cmdline bashshw@shw:/tmp $ shw@shw:/tmp $ shw@shw:/tmp $ kill -9 18453 shw@shw:/tmp $ [1]+ Killed ls --color=auto testdir/!(*/) shw@shw:/tmp $



Top 50 recent answers are included