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] ...


11

The obvious way to go is to launch such applications in background by adding an & sign to the end of the command, like this: firefox & Please note that Firefox is now a child process of your shell and your terminal window. If you exit them, Firefox gets killed if it's still running. To avoid this and make sure it continues running even after ...


10

touch is not able to create directories, you need mkdir for that. However, mkdir has the useful -p/--parents option which creates a full directory structure. From man mkdir: -p, --parents no error if existing, make parent directories as needed So the command you need in your specific situation is: mkdir -p ~/Desktop/a/b/c/d/e/f/g/h/ &&...


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 ...


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 canonical way to resolve symbolic links is to use readlink. To resolve the symbolic link /usr/bin/firefox: readlink /usr/bin/firefox Canonicalizing by following all symbolic links in between: readlink -f /usr/bin/firefox For example: $ readlink /usr/bin/firefox ../lib/firefox/firefox.sh $ readlink -f /usr/bin/firefox /usr/lib/firefox/firefox.sh ...


9

I posted this a while ago on a (now) deleted Q/A. Maybe it is useful to you. A patch to allow (very) long messages The "patch" below will allow you to have notifications as long as it takes on your desktop: In case of (very) long notifications, instead of this: you will see this: The duration of the message is automatically set to the length of ...


8

The binary database used by locate (/var/lib/mlocate/mlocate.db) is updated once daily by cron, so locate will not find new files. You can fix this by first running sudo updatedb sudo updatedb && locate -e bench-repo It's a good idea to use the -e flag so you only find files that still exist. Oh and here's a bonus tip - you can get locate to ...


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

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 ...


7

If making the screen sleep works, then almost certainly the toggle- script below will work: #!/bin/bash # --- set your monitor below monitor=VGA-0 # --- if [ -z "$(xrandr | grep $monitor | grep +)" ]; then xrandr --output $monitor --auto else xrandr --output $monitor --off fi The script toggles on/off a monitor, to be set in the head of the script: # ...


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 ...


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 -...


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

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 ...


5

This is a global VirtualBox property, and can be set with the following command: vboxmanage setproperty machinefolder /path/to/directory/ Be aware that this will not move already created VMs, it will affect only VMs which are created after the machinefolder property has been set.


5

With grep if you know the number of lines you want you can use context option -A to print lines after the pattern grep -A 3 2016-07-13 filename that will give you the line with 2013-07-13 and the next 3 lines with sed you can use the dates to delimit like this sed -n '/2016-07-13/,/2016-07-19/p' filename which will print all lines from the first line ...


5

This is caused by a spelling error in the definition of PARTITION. Because of this, PARTITION is empty (while PARTION contains what you want) and /dev/$PARTITION becomes /dev/. Note that the variable $USER already contains the username, so no need to set it (unless you want to do the mounting from a different user).


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

Two causes two actions In general when you are not able to locate a file or it is because recently created (after the last database update) or because it is not in the paths where updatedb is going to search its entries or matches some pruning rules(see below): In case it is a new file or directory, If you have enough privilege you can force an update: ...


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 ...


4

This simple grep one liner will be enough: grep -E ^2016-07-1[3-9] filename Works nicely here and there is no need for sed :) References: Matching Numeric Ranges with a Regular Expression


4

As I've noted in the comments , notify-osd is not very suitable for extensive messages and one should prefer zenity instead. Simple example of usage would be spawning zenity dialog via subprocess.call([COMMAND,OPTIONS]) import subprocess text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore ...


4

Those commands go into ~/.mysql_history.


4

subprocess.call() expects a list, with first item obviously being a legitimate shell command. Compare this for instance: >>> subprocess.call(['echo hello']) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/subprocess.py", line 523, in call return Popen(*popenargs, **kwargs).wait() ...


4

By default subprocess.call doesn't use a shell to run our commands you so can't shell commands like cd. To use a shell to run your commands use shell=True as parameter. In that case it is recommended to pass your commands as a single string rather than as a list. And as it's run by a shell you can use ~/ in your path, too: subprocess.call("(cd ~/catkin_ws/...


4

Try this: ls -la /usr/bin/firefox This is easy, you can use ls -la on any place and can work on multiple files/folder too.


4

Try: $ file /usr/bin/firefox Which will tell you (among other information) if it is a symlink or not; if yes, to which file. For example: $ file ~/test.txt /home/bharadwaj/test.txt: ASCII text $ file /usr/bin/firefox /usr/bin/firefox: symbolic link to ../lib/firefox/firefox.sh (Note that .. means 'parent directory', i.e /usr/lib/firefox/firefox.sh) ...


3

All the other current answers rely on the fact that the log file entries are sorted chronologically or the fact that the date range can be matched easily with regular expressions. If you want a more generic solutions, we need to do some more programming. I present this Awk script: #!/usr/bin/awk -f BEGIN { starttime = mktime(starttime) endtime = ...



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