Tag Info

New answers tagged

2

Sorting, scrolling a bunch, manually selecting a range and punching holes in the range is natural in a GUI. One can argue that it is also tedious and error prone. At the CLI (i.e. a unix shell) you have more powerful means. When sorting using the filename as key you can use globbing to select a range, e.g. $ rm someprefix*mid*.[0-9] In a sorted list ...


5

With the zsh shell, that's typically done with globbing qualifiers: mv -- *(.om[1,10]) /dir moves the 10 newest non-hidden regular files to /dir. With the completion system (enabled by running compinstall), you can also tell zsh to expand that list and select which ones to expand using Alt-A.


0

If you need to open web pages from command line (loop), you can just open the browser before starting the script. In this case it doesn't wait for browser to be closed after the first link, but opens them all in new tabs.


-1

This seems to me a short line: atrm $(atq | cut -f1)


1

There are some basic bash shortcuts you should know... Ctrl + A Go to the beginning of the line you are currently typing on Ctrl + E Go to the end of the line you are currently typing on Ctrl + L Clears the Screen. Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line. Ctrl + H Same as ...


5

You can do: sudo !! Another good one is alt ., to insert the last parameter of the previous command


0

Linux Walkthrough of creating a file with dashes and spaces, then removing it. BE CAREFUL! Don't accidentally run a rm -rf / or similar cascade delete command. If your file you are trying to remove includes asterisks or slashes, do not accidentally pump a . or /* or * or some other wildcard which could cascade delete your operating system. Create a ...


0

egrep -v ^'(#|$)' file.txt Strips all comments and empty lines from file.txt


0

awk -F"[:=]" -vRS='+' '{for(i=1; i<=NF; i++) {if($i == "prop1") I=$(i+1); if($i == "prop2") O=$(i+1)}; printf "input: %s -> output: %s\n", I, O}' file


-1

If you want to download a file and save its contents, you can use this function: function __wget() { local URL=$2 local tag="Connection: close" if [ -z "${URL}" ]; then printf "Usage: %s \"URL\" [e.g.: %s http://www.google.com/]" \ "${FUNCNAME[0]}" "${FUNCNAME[0]}" return 1; fi read proto server path <<<$(echo ...


1

If you can install the rlwrap utility, then it is as simple as doing rlwrap ./yourscript.sh This will allow you to use the up and down array keys to browse through history, as well as the right and left arrow keys for editing the current command, for programs that do not support it already.


0

Whenever I have to edit 3-4 text files in VIM, I used to run the command vimdiff test1.txt test2.txt test3.txt ... It will open all four files in parallel. Focus will be on first file by default. To navigate to other files, I use the command ctrl+ww Though vimdiff is basically used to see the difference of files but one can use it to edit multiple files


0

There are a lot of way to do so. The first one, maybe the less convenient, is to call vim with the files you want to edit - create: vim first_file second_file ... It calls the two files in two buffers. To switch from a file to another, please use :n and :N. To list the files you are editing, :args will do the job. :help buffer will help you more on this. ...


1

With all do respect, but I don't think the above code/answer is correct. if [ -d dir] is probably an attempt to if [[ -d "$dir" ]].. or [[ -d "$dir" ]];.. The following code should work and do what you want. vhostdirs=( ./var/www/vhosts/* ) for dir in "$vhostdirs" do cp -r "folder_to_be_copied" "$dir/htdocs/" done Mind also the quotes ...


2

This script may be helpful: for dir in /var/www/vhosts do if [ -d dir] then cp -r DIR_TO_COPY $dir/htdocs fi done


8

You can almost definitely just do: alias >>./bash_aliases


15

Easy trick for alias in $(compgen -a); do type $alias; done


1

SMBNetFS uses Gnome-keyring by default. Any passwords entered and saved in Gnome-keyring while browsing Samba shares in Nautilus should be used automatically. So if storing passwords in Gnome-keyring is OK, SMBNetFS is more convenient. It automatically mounts the entire network neighbourhood. This information is from the sample SMBNetFS config file, but I ...


1

The easiest and safest method would be to use find and tailor the command. E.g: find . -type f -name '*.gz' -exec bash -c 'n=$1; mv -- "$n" "${n%.*}"' _ {} \;


1

Following script might help: for i in $(ls) do mv $i ${i%.gz} 2> /dev/null done Basically it loops the files in directory and renames the files by removing 'gz' from the end.


2

You can use rename (it's designed for that). Just execute this command in the folder where the *.gz file are: rename -n 's/\.gz$//' *.gz This removed the .gz extension from all files that have a .gz extension. Output should look like this: hibernate.queries.hbm.xml.gz renamed as hibernate.queries.hbm.xml jbpm.businesscalendar.cfg.xml.gz renamed as ...


0

The program and the docs deviate from standard practices: If -ugG actually means -u|g|G[modifier] (which apparently it does), then it should be documented that way. The authors didn't seem to think it was worth the effort. However, when the user does the same thing (as Mr. Davis quite reasonably tried): -ru, a legitimate, intuitive assumption, returns an ...


2

Much of the time, and probably in this case, just plain less will do the right thing. This uses the so-called less preprocessor. So, do less file.sql.gz This won't actually write the file in plain text to the filesytem; it is for your viewing pleasure only, but much of the time that is enough. I personally find the less preprocesor quite useful. It saves ...


1

gunzip -c <filename> | less or zcat <filename> | less


2

zcat file.sql.gz will output the file to stdout, which then can be combined with grep or more or less etc.


0

Here's a way: watch -n 1 'date' &>/dev/null & Since you background the process, we can assume you don't need the terminal display and you are fine redirecting to a file. If you do that you will be able to background watch without issue. sleep, as suggested by Michael Mrozek, will slowly lag which can be undesirable. Aside from a convoluted ...


2

When you run a program from a shell (e.g. firefox) it will be executed "in foreground". When the program will finish you will have back the possibility to execute another command. Another way to execute a command is "in background". If you put this symbol & after the command it will be executed asynchronously (in background) and you will have the ...


2

while read -r line; do mkfs.ext4 "$line" done < <(df -k | grep 'media' | cut -d ' ' -f 1) The df command with the grep and cut pipes would give us the list of external hard drive mounts. For instance, the external hard disk will always get mounted automatically to /media in most of the systems. So, I am using df command to check the mounts of the ...


1

id -u somegroupname &>/dev/null || groupadd somegroupname since id -u somegroupname will return non-zero if it doesn't exist.


4

getent group somegroupname || groupadd somegroupname


0

This is similar to a couple of the other answers, but is more portable than this one and much simpler than this one: sh -c 'stat "$0"; file "$0"' filename If you want to do stat filename1 filename2 filename3 …; file filename1 filename2 filename3 … for an arbitrary number of files, do sh -c 'stat "$@"; file "$@"' QuickBrownFoxJumpsOverTheLazyDog ...


2

Here is a starting point: command | tee >(aplay -r 32000 2> /dev/null &); pkill aplay Try it with dmesg or ls -l /usr/bin to test. (Set your volume low first) Tee simply splits output to two places. There is a pkill aplay so that the sound ends when the command exits. Adjust the rate (-r 32000) to make it higher or lower. Note that this is very ...


-1

I have a less complicated answer, and surely not a keylogger. I don't get your point of being server log independent (this means that all the actions need to be taken to the server and all logs are server side logs), and thus I thought that a good idea is to pass to system wide bashrc a prompt command like: PROMPT_COMMAND='history -a >(tee -a ...


0

Take a look at Rainbow Stream - smart/beautiful and written in Python. It provides a rainbow shell which can start by $ rainbowstream and inside the app, updating a status is quite easy with [@yourTwitterName]: t tweeting from #rainbowstream


5

I assume you've inadvertently trimmed the important part of your command lines out here: the URLs in question contain a ? character (or a *). ? and * are special glob matching characters to the shell. ? matches a single character in a filename, and * matches many. When zsh says: zsh: no matches found: http://myvideosite.com?video=123 it's telling you that ...


1

Set up sudo to preserve the HOME environment variable. Run visudo to edit the sudo configuration. Make sure that the option always_set_home is not set, and that HOME is present in the env_keep list. Add the following lines: Defaults !always_set_home Defaults env_keep+="HOME" Remove a line like Defaults always_set_home if there is one.


1

Here’s Gnouc’s awk answer, modified to be space-blind: awk -F, 'FNR==NR{a[$1];next} !(gensub("^ *","",1,$2) in a)' toremove.txt users.csv Since it uses only commas (and not spaces) as delimiters, $1 is "John Lennon", $2 is  90123412 (with a leading space), etc.  So we use gensub to remove any number of leading spaces from $2 before we check whether it ...


6

With grep, you can do: $ grep -vwF -f toremove.txt users.txt username, userid, sidebar_side, sidebar_colour "John Lennon", 90123412, "left", "blue" "George Harrison", 72349482, "left", "green" With awk: $ awk -F'[ ,]' 'FNR==NR{a[$1];next} !($4 in a)' toremove.txt users.txt username, userid, sidebar_side, sidebar_colour "John Lennon", 90123412, "left", ...


3

Use: mimeopen -a 0001.jpg -a will first Ask you to choose, not run it. Please choose an application 1) Wine Internet Explorer (wine-extension-jfif) 2) Wine Internet Explorer (wine-extension-jpe) 3) Firefox Web Browser (firefox) 4) Luminance HDR (luminance-hdr) 5) ImageMagick (display) (display.im6) 6) Image Viewer (eog) 7) Shutter (shutter) 8) ...


9

mimeopen -a 'picture.jpg' This is what you need It will give you output like this Please choose an application 1) Shotwell Viewer (shotwell-viewer) 2) Firefox Web Browser (firefox) 3) Image Viewer (eog)


2

Use sudo -E to preserve your environment: $ export FOO=1 $ sudo -E env | grep FOO FOO=1 That will preserve $HOME and any other environment variables you had, so the same configuration files you started with will be accessed by the programs running as root. You can update sudoers to disable the env_reset setting, which clears out all environment variables ...


3

And then just because @polym's completely over the top answer missed the classic messaging: write <username> [<terminal>] - send a message to another user. Either interactively or as part of a pipe with echo "message" | write username And the complement to write, wall to send a message to all users


-1

Alternatively, it is possible to write a C program that calls the desired command and save it to /usr/bin. #include <stdio.h> #include <string.h> int main () { char command[50]; //notice you can change this to fit your needs int return_val; strcpy( command, "echo \"cd /media/Dan/evolution\" | bash -i" ); return_val = ...


5

You need an interactive shell for alias definitions: bash -i -c "alias"


8

For a standard "box around a message", use boxes: echo 'This is a test' | boxes boxes will look like this (First one. Second one is a custom like cowsay): If you mean an alert box, use notify-send: notify-send 'title' 'message' notify-send looks like this: You also can use zenity for a popup window: zenity --error --text="An error ...


34

Alternative to aliasing gb() { cd /media/Dan/evolution; } This defines shell function gb, which takes no arguments, and performs cd /media/Dan/evolution. As with other suggeststions, this can be added to ~/.bashrc


1

I am probably a little bit too late, but there is another tool worth mentioning: csvkit http://csvkit.readthedocs.org/ It has a lot of command line tools that can: convert to and from csv from various formats (json, sql, xls) cut, grep, sort and others join different csv files!


0

-A "Sample" kind of acts like a Sample* would in bash Not by my reading of man wget: -A acclist --accept acclist -R rejlist --reject rejlist Specify comma-separated lists of file name suffixes or patterns to accept or reject. Note that if any of the wildcard characters, *, ?, [ or ], appear in an element of acclist or ...



Top 50 recent answers are included