Hot answers tagged

29

[co] isn't a parameter to the rm command - it's a shell glob that matches a pattern equal to a single character from the set [co] - in other words, it matches either a c or an o a the end of the filename. From man bash: [...] Matches any one of the enclosed characters To match both foo.coffee and foo.js, since the suffixes don't contain any common ...


17

It is not a parameter but a collection of letters (or a "shell glob"). This is the same: rm -rf /tmp/hello.py[co] is the same as rm -rf /tmp/hello.pyc rm -rf /tmp/hello.pyo Similar ... rm -rf /tmp/hello.py[c-o] would delete anything from /tmp/hello.pyc up to and including /tmp/hello.pyo following ASCII ordering. rm -rf /tmp/hello.py[ab][cd] ...


10

/ is a directory separator, file and directory names can't contain it. Check Reserved characters and words at Wikipedia. Using / alone points to the topmost directory which, as you were told, already exists.


10

The command that lists the last executed command is fc -nl -1 . Using output substitution , we can add more parameters to the same content $> ls /etc/passwd /etc/passwd $> $(fc -nl -1) /etc/group /etc/group /etc/passwd $> Quoting , however, may be an issue with this approach A very nice ...


8

You can't use !! but ... From the manual: A useful alias to use with the fc command is r='fc -s', so that typing ‘r cc’ runs the last command beginning with cc and typing ‘r’ re-executes the last command.


7

Using grep ifconfig | grep -oP '(?<=inet addr:)[\d.]+' This uses grep's Perl-style regular expressions to select the IP address that follows the string inet. So, to save that in a variable, just put both commands inside the $(): output=$(ifconfig | grep -oP '(?<=inet addr:)[\d.]+') The above will save the IP addresses for all active interfaces ...


7

If you want to move or copy all of the files to the same directory, you can use the -t option of cp or mv, but this will mean that you have to type/supply each filename as an argument. It works in the following manner, with as many files as arguments as you like: cp -t /destination/directory/ file1 file2 file3 or mv -t /destination/directory/ file1 file2 ...


6

This is certainly possible using ANSI escape codes: <?php echo "\033[31m some colored text \033[0m some white text \n"; ?> will output "some colored text" in red and "some white text" in white (unless you chose different default colours for your terminal). The characters \033 indicate the start of an escape code. [31m is the colour red. [0m ...


6

As the root directory (/) is already created when setting up the filesystem hierarchy in *nix (first time you install the system), you are getting the mentioned error saying the directory already exists. As a side note, if you want to create a file/directory named foo/bar, you won't be able to because / is the separator used to distinguish between ...


6

If you insist on using the !! history expansion syntax instead of fc (mentioned already), there is a way. By default, history expansion is disabled for non-interactive shell sessions e.g. in scripts. To enable history expansion in scripts enable the relevant shell options first: set -o history set -o histexpand set -o histexpand can be written as set -...


5

You can use sed: sed 's/ //' file > newfile or, if you want the changes to be made directly to the original file, you can use the -i command line flag - either along with a backup file sed -i.bak 's/ //' file or without creating a backup if you prefer sed -i 's/ //' file


4

Making many changes all at once Take the original file and save it as sshd_config.orig. Edit sshd_config to your heart's content. Run diff sshd_config.orig sshd_config >config.patch Keep the config.patch file somewhere safe. Now, anytime that you have a new and unedited version of sshd_config and you want to apply the same edits, run: patch ...


4

If you are not opposing bash solutions, here's a script that does what you outlined. It can be added to /etc/rc.local to run on every boot. Just call it like bash /path/to/script & from within /etc/rc.local #!/bin/bash while true do screen ./run.sh arg1 arg2 "arg3" & # start in background CMDPID=$! # get pid of that command TIME=$( date ...


3

If HISTSIZE environment variable is not set in any startup configuration file of bash, it will be set to 500. From man bash: The shell sets the default value to 500 after reading any startup files. The HISTFILESIZE follows HISTSIZE, if not set. Now, you are getting the value of HISTSIZE as 500 because Ubuntu by default sets the HISTSIZE (and ...


3

ifconfig might disappear in the future, it is deprecated in some linux (maybe some ubuntu versions, but read on). ip from the iproute2 package (should be installed by default) gives ip addr list and can be abbreviated to ip a and combined with ip a | grep -o -P '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(?=/)' to filter on all IPv4 look alike ...


3

Instead of hard-coded sequences, you should use a library such as PHP Ncurses which will be more likely to work on more terminal types The example from ncurses_color_set: <?php ncurses_init(); // If the terminal supports colors, initialize and set active color if (ncurses_has_colors()) { ncurses_start_color(); ncurses_init_pair(1, ...


3

The problem in your approach is that you use exec. $ help exec exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...] Replace the shell with the given command. Execute COMMAND, replacing this shell with the specified program. ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified, any redirections take ...


3

Basically, you want this structure if grep -q "un-clean" /path/to/log_file.log ; then # put some command in case we find result is unclean else # if the output is ok, do something else fi All it does is to silently (without printing to screen) check if there is a match of string "unclean" in the file . If there is we do the if part, otherwise - ...


3

Although , watch doesn't have command history, shell history can use used for that purpose. fc -nl -1 allows listing previous commands executed by shell. One can do PCMD=`fc -nl -1`; watch -n 5 $PCMD Or even shorter watch -n 5 $(fc -nl -1) Example, $> stat /etc/passwd ...


2

Here's a script that selects a random set of files/directories to be copied. It can deal with arbitrary file names, even those containing newlines and spaces. Save the script as ~/bin/randomCopy.sh, make it executable (chmod a+x ~/bin/randomCopy.sh) and then run it, giving it the source directory as the first argument, the target directory as the second and ...


2

Your first question can be addressed easily enough: find . -iname '*.jpg' -exec convert '{}' -format webp '{}'.webp \; This will: Recursively find all .jpg files, as in your example Convert each .jpg file to webp using convert rather than mogrify Use the naming convention you were after: 'filename.jpg.webp' Tested nicely on my system... References: ...


2

spawn is expect specific command i.e. you need to interpret spawn using expect. Most of the time you would use a expect script and use spawn inside it to start a new process. For example: #!/usr/bin/expect -f spawn ssh host expect .... From terminal directly: % expect -c 'spawn whoami' spawn whoami By default spawn echoes the command hence the output ...


2

Now you can use 24-bit true color in terminal in Ubuntu 16.04 The foreground escape sequence is ^[38;2;<red>;<green>;<blue>m The background escape sequence is ^[48;2;<red>;<green>;<blue>m <red> <green> <blue> range from 0 to 255 inclusive. The escape sequence ^[0m returns output to default. See RGB ...


2

The rhash manual states (emphasis mine): -u, --update Update hash files specified by command line. The program calculates and appends hashes to the updated hash file in the format specified by formating options. Hashes are calculated for those files from the same directory as the hash file, which ...


2

C shell (e.g. csh, tcsh) and Bourne shell (e.g. sh, bash) are two shell families. These two have differences in syntaxes and implementation of various operations. The examples you have shown are how these two family handle redirection of file descriptors. Both commands are redirecting STDERR (file descriptor 2) to STDOUT (file descriptor 1), sending STDOUT ...


2

In this case, it seem that spawn refers to the spawn extension to the hosts.allow syntax, as described in the RUNNING OTHER COMMANDS section of the hosts_options (5) man page (man hosts_options): RUNNING OTHER COMMANDS aclexec shell_command Execute, in a child process, the specified shell command, after performing the %<...


1

You can do one of two solutions: Edit your PATH variable in /etc/environment and add the :/opt/file/base/bin/linux-x86_64 to the end of it. (this builds the PATH statically, meaning that whatever shows up here is the "base" for the PATH variable, and any additions, like in the profile, will be added to this) Edit your bash profile in /etc/profile and ...


1

Using facter: facter ipaddress


1

Simple way to print only the IP address regardless of interface using Grep; since that was the question ifconfig |grep -o -P '(?<=addr:).*(?= Bcast:)' addr: is the start string Bcast is the end string Anything in between those two strings gets printed using .*


1

Although selecting fields from the output of dpkg -l certainly works, the more fundamental dpkg-query command allows the output fields and format to be customized without resorting to additional text processing tools. As it happens, plain dpkg-query -W with no explicit format string gives exactly a tab-separated list of package names and versions (...



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