Tag Info

Hot answers tagged

7

Use functions, instead. d () { num=${1:-5} dmesg |grep -iw usb|tail -$num } num=${1:-5} uses the first argument, with a default value of 5 if it isn't provided. Then you can do: $ d # prints 5 lines $ d 10 # prints 10 lines Or, if you change the options you used slightly: alias d="dmesg|grep -iw usb|tail -n 5" Then you can pass additional -n ...


5

Use [1-2] to indicate the files, this uses bash's range expansion feature : cp ~/Desktop/dir/dir/dir/dir/file[1-2].txt . Here the range [1-2] will expand so file[1-2].txt will expand to file1.txt and file2.txt. Note that if you have multiple files like this with various number of numeric digits among their names : file1.txt file12.txt file980.txt ...


4

Use rename : rename 's/^joob/job/' joob_* This will change the file names starting with joob to job. Test : $ ls joob_1_1 joob_1_2 joob_2_1 joob_2_5 $ rename 's/^joob/job/' joob_* $ ls job_1_1 job_1_2 job_2_1 job_2_5


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

I use a method that has some similarities to the answer of terdon (and was created with some help of him - Thank you @terdon for this!), but has a slightly different approach: I create a temp file so that the child terminal can communicate with the parent terminal and tell it the PID of its corresponding bash instance. Then I let the parent terminal read ...


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


3

In their infinite wisdom, the GNOME devs decided to remove that option. Unfortunately, their wisdom did not extend to also updating their man page which still lists it. So, it looks like gnome-terminal will always be run int the background and the parent shell session will be returned to immediately. To get around this, you have a few options: Just use ...


3

Use this: grep -rn "\$\('\|\"\)" /path/to/directory Your problem is actually two-fold : From grep's perspective, You are using the Extended Regex syntaces i.e. (, |, ) without escaping them (to treat them special) inside your Basic Regex pattern. To overcome this either escape all those to treat them special or use the -E option of grep. Another problem ...


3

I would use brace expansion for this kind of thing cp -t ./ ~/Desktop/dir/dir/dir/dir/file{1..5}.txt cp -t ./ ~/Desktop/dir/dir/dir/dir/{xx.x,yy.y}


2

I've found in the past that stringing the commands together in that manner causes issues if one of them have a "hiccup". For example, if your command is similar to this: sudo apt-get install 1 2 3 4 then, if there's an error on program 3, 4 will not install. Keeping them separate on each line fixes this issue. if there's an error, the script continues ...


2

Open the terminal and type: sudo newusers /tmp/userlist.txt In the userlist.txt file, each line should contain user data in the following syntax: username:password:User ID:Group ID:Comments:Userhome directory:User shell Since the userlist.txt file contains users' passwords, it should not be stored in a human readable form after you have ...


2

You can export them like this. #!/bin/bash #Specific Set Variables SpecficStatus="Pass" #SetVariable timestamp() { date +"%a %d %b %Y %T %Z"; } SpecficDate=$(timestamp) echo $SpecficStatus echo $SpecficDate #Properties Call file="savedState.properties" #Echo out the file while IFS== read -r VAR1 VAR2 do #echo "VAR1=$VAR1 : VAR2=$VAR2" export ...


2

No idea what you're doing wrong, as I am not so good with grep, but you should be doing this grep "\$'\|\$\"", basically search for $' or $", and notice that those expressions are all escaped Here's an example:


2

You need to store the count somewhere it will persist across multiple runs of the script, since variables are just in memory for that single run. The easiest place is probably in a file. The particular way you store it in a file depends on a few factors including how many times you're counting, and whether you expect concurrent runs. A simple robust way ...


2

The Ubuntu maintainers of the gnome-terminal package noticed this issue and created a wrapper script (in Ubuntu package gnome-terminal-3.14.2-0ubuntu3) to re-enable the --disable-factory option; however, the wrapper script doesn't work! From the changelog ...


1

It is possible but you're looking at different issues. Since the server, prior to installing an os, will not have a working TCP/ip stack (I.e. networking ), you won't be able to simply ssh/putty over to it. Unless you have a device that allows you to have keybiard/video/mouse access over the network to a separate device that's then connected to the server, ...


1

You need to have a function for this as described in the SO and here. Try the following: foo() { /path/to/command "$@" ;} and call the foo with: foo arg1 arg2 arg3


1

It is possible. You could use netstat -a | egrep 'Proto|LISTEN'


1

For your case: ls -l /usr/local/Wolfram/Mathematica/10.1 gives ls: cannot access /usr/local/Wolfram/Mathematica/10.1: No such file or directory This leads to conclusion that some error happen and you don't really install it. so rerun the script again as mentioned here sudo bash installer.sh and follow instructions carefully and its better to keep ...


1

If you want to do it the gui way, here is an alternative to the very good suggestion of heemayl. You can try krename: sudo apt-get install krename this is as powerful as rename (with the exception that it can't be piped to in a script).


1

FWIW, I rather like what I get with side-by-side output from diff diff -y -W 120 File_1.txt File_2.txt would give something like: User1 US User1 US User2 US User2 US User3 US | User3 NG


1

In addition there is comm command, which compares two sorted files, and gives output in 3 colums : column 1 for items unique to file #1, column 2 for items unique to file #2, and column 3 for items present in both files. To suppress either column you can use switches -1, -2 , and -3. Using -3 will show the lines that differ. Bellow you can see the ...


1

What can I say? Simply run: split -l 20000 -d "job1" "job1" That's all. Or: file="job1"; split -l 20000 -d "$file" "$file" The command read reads the entries in file.list.txt and executes split -l 20000 -d "$file" "$file" for each of them. In your case: split -l 20000 -d "job1" "job1" split -l 20000 -d "job2" "job2"


1

I'm using History Expansion with Word Designators a lot. !$ will designate the last argument of the preceding command. In most cases I take a look into that folder with ls first before coping. $ ls ~/Desktop/dir/dir/dir/dir file1.txt file2.txt $ cp !$/file1.txt !$/file2.txt . cp ~/Desktop/dir/dir/dir/dir/file1.txt ~/Desktop/dir/dir/dir/dir/file2.txt . ...


1

Question asked can be solved by using the following command too. cp ~/Desktop/dir/dir/dir/dir/file*.txt . it will copy any files with the naming style file(something in between).txt


1

${parameter:offset:length} is "Substring Expansion". (See Parameter Expansion in man bash). set, among other things, can set positional parameters: The remaining n ARGs are positional parameters and are assigned, in order, to $1, $2, .. $n. So, the expression prepends mongod to the positional arguments.



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