Tag Info

Hot answers tagged

65

!! is a shortcut in bash that means last command executed. Try this: echo hello !! In this context, the !! will be expanded to another echo hello. I imagine what happened was they tried to run a command and it failed and complained it wasn't installed. So then they typed sudo apt-get install !! because the package name was coincidentally the same as ...


37

!! has nothing to do with apt-get. It is a shell keyword that will be expanded to the previous command. This expansion is done by shell before the current command is interpreted. From man bash: !! Refer to the previous command. This is a synonym for `!-1'. For example, if you run a command: echo "foo" Then if you run: sudo apt-get install ...


16

!! : Refer to the previous command. This is a synonym for !-1 (The source). For instance, if i execute: ./test then remember that I need to be Root, then I could simply type: sudo !! it's the same as typing: sudo ./test It's useful when your last command contain a lot of characters.


15

The easiest way would be to use grep with PCRE: $ ifconfig -a | grep -Po 'HWaddr \K.*$' 74:d4:35:84:34:13 grep -P will enable us to use perl compatible Regex grep -o will only take the matched portion of the line We have matched HWaddr before our desired match (MAC addresses) and then discard HWaddr by \K to print only the MAC addresses. @Helio has ...


15

You can access the address file for each device on the /sys virtual filesystem. The MAC address should be in /sys/class/net/<device-name>/address: $ cat /sys/class/net/enp1s0/address 34:17:eb:5d:88:7c For all devices: $ cat /sys/class/net/*/address 34:17:eb:5d:88:7c 00:00:00:00:00:00 64:5a:04:69:50:45


9

Always when you have such a question in mind, ie, you don't know the name of the tool to invoke it in command line, find it from the terminal itself: man -k <keyword> It will search manpages for the keyword you specified and prints the titles. In your case, it would be: man -k calculator As an illustration, if you want to invoke the webcam tool ...


6

Use a shell glob instead of ls: select option in "Exit" "$1"/* . . . elif [ -n "$option" ]; then ls "$option" else . . .


6

Here are a few ways: grep. There are various regular expressions that will pick these up. Here, I am looking for 5 repetitions of 2 letters or numbers followed by a colon, then any two characters. The -i makes the match case insensitive and the -o makes grep print only the matched portion. -E enables extended regular expressions. The same regex also works ...


4

You can use a for loop, so the command is executed for every file exactly once: for file in *.dat; do sed -i.bak '1,2000d' "$file"; done Notice, -i.bak backs up the original file with .bak ending.


4

You can do this using a single rename command (i.e. you don't need a bash script for this, or you can use this command within your bash script in place of the for loop): rename -n 's/(^| )([^ ]{1,2})[^ ]*/$2/g; s/$/.mp4/' *.mp4 This will just mimic the behavior of echo mv [...], so that you can see the result without actually renaming anything. If the ...


4

Don't use setuid shell scripts, the SUID bit is not honored on shell scripts anyway on current systems. Use sudo instead, as you attempted anyway: eka ALL=NOPASSWD: /home/eka/test/test.sh And then: eka$ sudo ~/test/test.sh With that, test.sh will be executed as "root". No need to use setuid here.


4

You can make a conditional to relaunch the script as root if it's launched as a normal user. To shutdown the computer: #!/bin/bash if [[ $USER == "eka" ]]; then # If the script is ran as "eka": sudo $0 # Relaunch it as "root". exit 0 # Once it finishes, exit gracefully. elif [[ $USER != ...


4

You need to give the increment as negative number i.e. in your case -1. For example: $ seq 1 5 && seq 5 -1 1 1 2 3 4 5 5 4 3 2 1 Here seq 5 -1 1 takes the format seq FIRST INCREMENT LAST. Furthermore, if you want every alternate numbers from 10 to 0: $ seq 10 -2 0 10 8 6 4 2 0 Check man seq to get more idea.


3

Try to type: gnome-calculator Or for Older version (Ubuntu 12.04 and before): gcalctool


3

The code snippet you have given requires a modification, you need -print0 instead of print 0. This script will find (find) all the files having extension txt in /home/mike/Duck/, send them to printer (lpr) one at a time and then if that returns a success (&&) then the file will be moved (mv) to /home/mike/Duck/printed/. If you want to print files ...


2

ifconfig -a | grep HWaddr | awk '{print $5}' If your system output is non-English in this command, then it makes sense to run it this way. LANG=C ifconfig -a | grep HWaddr | awk '{print $5}' This is applicable to all solutions.


2

Neither of these suggestions may work for you, but here's what I would try first: Regarding the first issue, there's a hidden file in your home folder called .bashrc. Open a terminal and type ls -a which means "list files -all of them" and you should see the file. The contents of this file are executed every time you open your terminal, and I suspect that ...


2

You can use the GLOBIGNORE variable of bash: GLOBIGNORE=ComixCursors-0.8.2.tar.bz2 Now run: mv ComixCursors* /usr/share/icons/ Also note that when you are done with the operation it is good to unset the variable to avoid unwanted scenarios: unset GLOBIGNORE Or GLOBIGNORE=


2

You can create a hex-dump of your file with xxd which is part of the vim-common package. xxd file.csv | less Then check the line endings: 0a => \n 0d => \r 0d0a => \r\n


2

The command is gnome-calculator


2

You need to use the -R flag, which will recurse into every subdirectory. For example, running sudo chown -R my_username:my_username .hidden will make .hidden and all subdirectories owned by you. The * glob doesn't match any hidden directories (directories starting with a .).


2

Under Edit -> Profile preferences is where it should be. Maybe you didn't notice the checkbox? Untick the Use the system fixed width font and you can change the size:


2

You could easily solve this by adding /sbin to $PATH. The more important point is that, you should not have /sbin in the path by default. See this page for a description of why: /sbin directory definition /sbin contains system utilities that should be run by root or using sudo authority. So if you want to see your network configuration simply type: sudo ...


1

To remove then change a single field we can use this command: root@kurawa:~# exiftool -Copyright= IMG_3357.jpg root@kurawa:~# exiftool -Copyright=LinuxSlaves IMG_3357.jpg Reference: http://www.linuxslaves.com/2015/05/view-and-manipulate-exif-metadata-image.html


1

The following command works for me: qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause


1

Use the -f option of tree. From man tree: -f Prints the full path prefix for each file. So your command will be: tree -f ~/ | grep 'ActionListeener' Note that this will match ActionListeener anywhere in a line, so be precise in choosing in which directory you will run this.


1

Use tree's pattern matching (-P) in combination with --prune: $ tree . ├── archlinux-simplyblack │   ├── angle-down.png │   ├── archlinux.png # snip ├── reboot.png ├── shutdown.png └── theme.conf 8 directories, 78 files $ tree -P 'reboot*' --prune . ├── maui │   └── reboot.png └── maui-dark └── reboot.png 2 directories, 2 files ...


1

Nautilus does not have a command line option to open a new tab, however, you can "fake" it with the help of a script, using xdotool and wmctrl. How to use Install (if necessary) both wmctrl and xdotool: sudo apt-get install xdotool wmctrl Copy the script below into an empty file, save it as nautilus_tab (no extension) in ~/bin, and make it executable. ...


1

Here is a script that will check to see if it is after 17:00 then perform a task of turning the backlight on. #!/bin/bash time=$(date +%k%M) if [[ "$time" -ge 1700 ]];then echo "Backlight on" xset led 3 else echo "Backlight off" xset -led 3 fi On a 24 hour clock, midnight 0:00 would be less than 17:00 so it would then become false and not ...


1

Use: bash -x /path/to/a/script |& more bash xtrace output is written to the STDERR, while piping | you are just giving the STDOUT of bash -x /path/to/a/script to more or any other command on the right side of |. |& will pipe both the STDOUT and STDERR to more so you can use them both with more. Alternately if you are just concerned with piping ...



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