Tag Info

Hot answers tagged

12

Run in a terminal: echo $PATH or printf "%s\n" "$PATH" what you see is a list of directories, looking like: /home/jacob/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games If you put an executable in either one of these directories, you do not need to set the path to the executable / script, but you can run ...


10

Ah, there is something built-in: zenity is a graphical dialog program: if zenity --question --text="Is this OK?" --ok-label=Yes --cancel-label=No then # user clicked "Yes" else # user clicked "No" fi In addition to zenity, you can use one of: if dialog --yesno "Is this OK?" 0 0; then ... if whiptail --yesno "Is this OK?" 0 0; then ...


9

That looks fine to me. I would just make it a bit less "do or die": if "Y" then return 0 if "N" then return 1 That way you can do something like: if check_yes_no "Do important stuff? [Y/n] "; then # do the important stuff else # do something else fi # continue with the rest of your script With @muru's select suggestion, the function can be ...


5

I just realized that 7-Zip (command 7z) can do it. 7-Zip is able to extract and compress many types of archives. Here is a quote from man 7z: DESCRIPTION 7-Zip is a file archiver with the highest compression ratio. The pro- gram supports 7z (that implements LZMA compression algorithm), LZMA2, XZ, ZIP, Zip64, CAB, RAR (if the non-free p7zip-rar ...


5

The path names are case sensitive. Therefore, it should be cd Desktop instead of cd desktop


5

It seems quite straightforward. romano@RRyS:~$ size=$(ls -l /var/spool | wc -c) romano@RRyS:~$ echo $size 476 The shell syntax $(command) executes command, and returns the standard output: just save it in a variable. Your command: ls -l /var/spool | wc -c > size will create a file named size in the current directory (containing the number and a ...


4

It's possible, but not elegant: echo 'This sentence contains an ip number 1.2.3.4 and port number 50, i want to print the IP address only.' \ | sed 's/.*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/' [0-9] matches any digit, \{1,3\} means it can be repeated 1 to 3 times. \. matches a dot. The whole IP is captured by the \(...\) ...


3

This is a grep solution: echo "$sentence" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -o print only the matching part -E switches to extended regex the pattern matches every digit ([0-9]) one or more times (+) then a dot (\.) and again digits... Here another solution with perl: echo "$sentence" | perl -l -ne '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ ...


3

http://packages.ubuntu.com/trusty/dtrx intelligently extract multiple archive types To install: sudo apt-get install dtrx Homepage: http://brettcsmith.org/2007/dtrx/


3

The issue here is absolute versus relative paths. An absolute path is /bar/foo/file.txt and a relative path is ./file.txt. When you run ln -s foo.txt /home/ubuntu/central_addcontent/program/, that is equivalent to running ln -s ./foo.txt /home/ubuntu/central_addcontent/program/ This will create a file called foo.txt that is pointing to ./foo.txt in the ...


2

Use this command of grep: grep -Eo '[0-9.]+ ' file Or even better: grep -oP '\d+\.\d+\.\d+\.\d+' file or grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}" file


2

You could do something like k=1; find source/ -type f | while read file; do [[ k++ -le 20 ]] && cp "$file" target/ done That will find all files in the current directory and copy the first 20 it finds to target/. The trick is the $k variable which is initialized to 1. Then, the [[ k++ -le 20 ]] && cp means "If $k plus one is less ...


2

Use a combination of find, sed and xargs: find /path/to/dir -print0 | sed -nz '1~2p' | xargs -0 cp --target-dir=/some/dir sed -n '1~2p' prints every alternate line, thus reducing the count to half. To make it a third, use 1~3p. The -print0, -z and -0 options indicate that we're using the \0 (NULL) character to delimit things. References: how to reduce ...


2

To do a fraction (e.g., ⅓) without knowing the count in advance, k=0; for file in * do if [ $((k++ % 3)) -eq 0 ] then mv "$file" target/ fi done This will grab every third file, by keeping a running counter (k) and acting on each file for which k is a multiple of 3.  Since I started the counter at 0, this will round up; e.g., if ...


2

Adding them to ~/.profile (apply to your user) or a /etc/profile.d/*.sh file (apply to the entire system) is the correct way. In order for the change to apply, you have to log out of your system and log back in, as ~/.profile and /etc/profile.d/*.sh are loaded when you login. To 'reload' ~/.profile in a running terminal, you can use source ~/.profile


1

You don't need to use export; the PATH variable is already exported at that point. Anyway, .profile is read when you log in, so what you've done is correct, but opening a new terminal does not count as logging in.


1

You could try drop down terminals like Tilda or Guake. Personally, I always have 2 drop down terminals running.


1

In case you want your Terminal to look like Elementary OS' terminal, do the following - Go to Edit -> Profile Preferences Go to the Colors tab and uncheck Use Colors from System Theme From the Built-in Schemes drop down menu, select White on Black Go to the Background tab and select Transparent Background Adjust the slider below according to your ...


1

As answered in the linked question, this is substring removal: ${string##substring} Deletes longest match of $substring from front of $string. In this case, it is removing the path and retaining only the basename: $ FILE=/etc/default/google-chrome $ echo ${FILE##*/} google-chrome $ basename $FILE google-chrome Ordinarily, I'd stick to basename, but ...


1

Type: sudo visudo Go to the end of the file and type: <username> ALL=NOPASSWD: ALL Press Ctrl+X to exit, and press Y to save the changes. Now open System Settings->Keyboard in that go to the Shortcut tab. Launch terminal, press Space and Backspace; it will disable it. Now go to Custom Shortcuts and click the plus (+) button at the bottom. ...


1

First, in order to create a custom ls, the easiest way is to proceed as follows: Create a directory $HOME/bin Add $HOME/bin to your PATH. To do this, open the file ~/.bashrc in your favorite text editor, and add the following line to the end: export PATH=$HOME/bin:$PATH Note that it is important that you prepend $HOME/bin to your PATH, so that ...


1

With zsh you just can use the Glob Qualifier (.): ls .*(.) Usually .* matches any file or directory starting with a .. (.) qualifies the * glob to match only plain files. .*(/) would match any directory starting with . and .*(^/) matches any "non-directory" like files and symbolic links (including those pointing to directories). For more information on ...


1

The right command-line tool for this job is find e.g. find -iname '*.mp3' -type f -execdir cp -t /home/dan/Music/ -- {} + The -iname test will match case-insensitively i.e. .MP3 as well as .mp3 - I'm not sure if that's important on NTFS filesystems. You could use -name instead.


1

Try using find with sort: find /sda /sdb /sdc -type f -printf '%f\n' | sort For example: $ tree sd[a-c] sda └── Alfa └── File 1 sdb └── Bravo ├── File 20 └── File 5 sdc └── Delta ├── File 11 └── File 14 $ find sd[a-c] -type f -printf '%f\n' | sort File 1 File 11 File 14 File 20 File 5 Note that this is what is typically meant by ...


1

Assuming the .rvm/scripts/rvm file is at your home. Use the following command in a terminal, echo "source ~/.rvm/scripts/rvm" | tee -a ~/.bashrc It will add the command at the end of your ~/.bashrc which is non-login interactive shell initialization file. when you open a terminal you get a non-login interactive shell. So the command will be executed every ...


1

I prefer the solution offered by Rmano's answer, but if you want to use only redirection: read size < <(ls -l /var/spool | wc -c)


1

$PATH is an file location related environment variable. When one types a command to run, the system looks for it in the directories specified by PATH in the order specified. You can view the directories specified by typing echo $PATH in the terminal. Suppose there is a executable file foobar01.sh present at /home/user/foo1/foo2/foobar01.sh which you want ...


1

You should never run a graphical application (such as nautilus) with sudo. You should use gksu instead if you need to do this. Unfortunately, using a graphical application as sudo creates a lot of problems which you are discovering can be difficult to clean up. The technical explanation behind this is that the program you are executing will be executed ...



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