Tag Info

Hot answers tagged

18

Ctrl+4 sends ^\ Terminals send characters (or more precisely bytes), not keys. When a key that represents a printable character is pressed, the terminal sends that character to the application. Most function keys are encoded as escape sequences: sequences of characters that start with the character number 27. Some keychords of the form Ctrl+character, and a ...


6

The glob * can be used to match not only plain files, but also directories, so the command you are looking for is mv ./*/*.avi .


5

To go back by one level of directory based on the directory path rather than the .. link: cd $PWD:h Or the portable method: cd "${PWD%/*}" (quotes optional in zsh; quotes optional in other shells if the directory name doesn't contain whitespace or \[*?) Repeat the :h or /* as many times as desired to go further up in the directory hierarchy. ...


5

The command you ran created a symbolic link in the current directory. Judging by the prompt, the current directory is your home directory. Creating symbolic links to executable programs in your home directory is not particularly useful. When you type the name of a program, the shell looks for it in the directories listed in the PATH environment variable. To ...


4

In addition to Gilles answer let me add, that you can always input non-printable characters in bash with Ctrl-v+key (Ctrl-v+Ctrl+4 in this case) and check the character code with $ printf '^\' | od -An -tu # input ^\ as C-v C-4 28 you get the decimal code of the character, which as you may check in man ascii corresponds to file separator (FS).


4

On a GNU system, you can use this: sed -i '/^#[[:blank:]]Person/{n;s/#root:[[:blank:]]\+marc/root:\tsomeone@something.tld/;}' file It searches for a line beginning with # Person. Then switches to the next line and replaces #root:<blanks>marc with root:<tab> .... The -i flag edits the file inplace. -i, \+ and \t are GNU extensions. The ...


3

Don't use which (unless you're in csh or tcsh variants), it's broken. Using command -v node instead. POSIX offer dirname command to get the directory portion of pathname: cd "$(dirname -- "$(command -v node)")" or using a variable to store the pathname, prevent you from calling dirname: nodepath=$(command -v node) cd "${nodepath%/*}"


3

Do you have to use awk for this? The paste utility was designed exactly for this sort of thing. Assuming array is a shell array: array=(100 200) printf "%s\n" "${array[@]}" | paste -d, input.csv - > output.csv The printf is simply to put each array member on a new line. paste then pastes together input lines from input.csv and - (i.e. the piped ...


3

Assuming PWD is correct, one can back out in ZShell thusly. % cd ~/tmp % mkdir -p a/a/a/a/a/a/a/a/a/a/a % cd !$ cd a/a/a/a/a/a/a/a/a/a/a % rm -rf ~/tmp/a % undir % pwd /Users/jmates/tmp % The custom undir function does the walk-back-out-the-path-chain loop: function undir { local dir dir=$PWD:h while [[ $dir != / ]]; do builtin cd -q $dir ...


2

Assuming: hour=09 Just use that: grep "\.$hour" file With the single quotes in your example, the variable is not interpreted as variable. Therefore the pattern searches for $hour. Also the dot has to be escaped, else it would match any character.


2

-exec indeed can be used as a predicate. find(1): Execute command; true if 0 status is returned. So this example would be: find . -type f -exec sh -c 'file "$0" | grep -q Matroska' '{}' ';' -and -delete Obviously, instead of -delete there can be -ls or -print0 or more predicates.


2

Screen is a full-screen software program that can be used to multiplexes a physical console between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a one single terminal window manager. The screen application is very useful, if you are dealing with multiple programs from a command line ...


2

The simplest way is to run: getconf LONG_BIT which will return 64 or 32 depending on whether it is 32 or 64 bits. eg: dannyw@dannyw-redhat:~$ getconf LONG_BIT 64


1

This should do: #!/bin/bash # this is the crucial setting: replace a glob pattern that matches zero files # with nothing (the default is to *not* replace the pattern at all) shopt -s nullglob destination=/some/directory unique_filename() { local root=${1%_*}_ local files=( "$destination/$root"* ) echo "$destination/${root}${#files}" } cd ...


1

Meanwhile, in ZShell, this requires the quite ugly and awkward construct: cd -- $commands[node]:h This even works when there's directories with spaces in their name (unless for unfathomable reasons you enabled the shwordsplit option).


1

I'm afraid not. Most Linux distributions provide some set of basic utility programs - graphical text editor, image viewer, file manager, window manager, terminal emulator, and so on. While some of these programs' names could be possible to get rather easily, if you are checking this on somebody's system and not a fresh install, you can never be sure, since ...


1

You can use the find command's -exec option: cd Father find Child1 Child2 ... -name '*.avi' -exec mv -n {} . + The command breaks down as follows: find Child1 Child2 ... will find all files and directories under Child1, Child2, etc. The default action is to print their names -name '*.avi' will limit the result to files (or directories) that match the ...


1

I would suggest to use perl: perl -p0e 's/(.*\n)(.*\n)(.*Fail\n)/#\1#\2#\3#/g' file Here is how it works: -p: print program in the loop over all input lines -0: assume null as record separator -e: execute program from the command line s/x/y/g: substitute y for x anywhere in the file (): group together regular expressions .*: any character except newline ...


1

If you want to open a new xterm and run a sequence of commands in that window, you can use the -e option. If you want the xterm to remain open after the command is executed, you can include the -hold option. For example: xterm -hold -e 'pwd; ls'


1

You can create a recursive script. eg in file /tmp/run #!/bin/bash depth=${1:-5} f(){ let depth-- if [ $depth -gt 0 ] then $0 $depth else sleep 10 fi } f then chmod +x /tmp/run and do /tmp/run 10.


1

With zsh, to remove the regular files other than the .bmp, .png, .wav (case insensitively) ones: setopt extendedglob # best in ~/.zshrc rm -- *.^(#i)(png|bmp|wav)(D.) (remove the D above if you want to preserve hidden files regardless of their extension).


1

As mentioned before you can try picocom. The latest release (2.0) can also be used (safely) to set-up a "terminal server" since it does no longer permit shell commands injection. See: https://github.com/npat-efault/picocom/releases



Only top voted, non community-wiki answers of a minimum length are eligible