Tag Info

New answers tagged

1

My error was a logic error with -mtime. I thought my script was checking the names but -mtime checks for the date when the file was created. So my final code: DAYS_TO_KEEP=2 find $BACKUP_DIR -maxdepth 1 -mtime +"$DAYS_TO_KEEP" -exec rm -rf {} \; I just had to do a sudo touch -d "3 days ago" /filepath/folderToRemove to make -mname find the folder and make ...


1

I'm a bit late with this response, but the sensible way would be to do a ssh-keyscan on the new machine before you run the uptime gathering. ssh-keyscan <newhost> >> ~/.ssh/known_hosts Disabling the sanity check for convenience sake sounds like a bad plan, even if you think you're totally in control of the environment.


1

I don't know why, but this sounds like a XY-Problem... What is your real intention? Why don't you just link the first folder to the second one? What do you need the folder for if you don't want anything inside it? If you really want to move these files, you could e.g. create a cronjob, which regularly moves all files of the first folder to the second ...


2

You can use find's -not or ! expressions: -not expr Same as ! expr, but not POSIX compliant. ! expr True if expr is false. This character will also usually need protection from interpretation by the shell. So, to move foobar.jpg but not the other two, you could use: find . -mindepth 3 -type f -regex ...


2

Use this script: #! /bin/bash # for i in $(cat /etc/passwd | cut -d: -f1); do echo -n $i ": " grep $i /etc/group | cut -d: -f1 | tr "\n" " " echo done It will list all users in the system (included system) and print the list of groups near them. With a trivial modification you can print the numeric id too.


0

I have finally found out the answer. Add a backslash to all spaces: SEARCH='te*/my files/more' SEARCH=${SEARCH// /\\ } At this point, SEARCH contains te*/my\ files/more. Then, use eval. eval find ${SEARCH} -print It's that simple! Using eval bypasses the interpretation that ${SEARCH} is from a variable.


4

The exact same command should work fine in a script: #!/usr/bin/env bash find te*/my\ files/ -print If you need to have it as a variable, it gets a bit more complex: #!/usr/bin/env bash search='te*/my\ files/' eval find "$search" -print WARNING: Using eval like that is not safe and can result in executing arbitrary and possibly harmful code if your ...


1

How about arrays? $ tree Desktop/ Documents/ Desktop/ └── my folder └── more └── file Documents/ └── my folder ├── folder └── more 5 directories, 1 file $ SEARCH=(D*/my\ folder) $ find "${SEARCH[@]}" Desktop/my folder Desktop/my folder/more Desktop/my folder/more/file Documents/my folder Documents/my folder/more Documents/my ...


0

You can use any version of Ubuntu as a Live USB. Use UNetbootin to make the USB bootable. Ubuntu 14.04 can be downloaded from here. You might want to have a look here for instructions to unbrick your phone (LG G2) using Ubuntu.


1

Definitely a more verbose option (python) that looks for mimetype(s) using the file command. It is an edited/rewritten version of this one, made fit for your purpose. What it does When files are found it returns a message (in the terminal): checking for filetypes: image, video, audio... 4 media files found. See for details: ...


1

To find files of a certain type, I wouldn't search for the file extension. I'd rather scan files for their MIME type using a combination of find and file. This output can then be greped for the desired mimetypesm e.g. audio/* and video/*. I've created a small script to do so: #!/usr/bin/env bash #Don't know whether you want to do so, but this deletes a ...


0

Checking whether Internet is working is not so trivial. ping is ICMP, so it might work even if the web proxy is down. Something similar occurs with DNS if you test with an IP. Since my Internet connection is unstable I created this script (based on this one) that makes a gentle chord sound to call me, and also uses Ubuntu notify when the Internet connection ...


32

You could try adding the line: trap 'cowsay "Have a nice day!"; sleep 1' EXIT to your .bashrc file.


4

You are getting this error message because you have changed the PATH environment variable to a command line argument (${2}) which dose not hold the actual binary.


8

The variable PATH is a special shell variable. It defines the list of directories in which executables/commands can be found. In the line PATH="${2}", you wipe out the default value of PATH and now the shell doesn't know where to find the ls command. For example, ls can be found in the directory /bin, but you modified PATH to have the value midhand.mp4 (the ...


4

Open Rhythmbox Music Player and import all your Music files. From the Rhythmbox menu select File -> Add Music -> Select a location containing music to add to your library (This should be set to your Music folder.) -> click the Import listed tracks button. Wait for a few minutes for Rhythmbox to import all the songs in your Music folder. How long it takes ...


0

You forgot to enter the vendor name, the correct command should be build/tools/device/mkvendor.sh samsung aegis2vzw /your/path/to/the/boot.img the script takes three arguments: vendor name path. Regards


1

You can first cd in the script to the script location with cd "$(dirname $0)" or use sudo dpkg -i --someflags=abcd "$(dirname $0)"/blah.deb This works also with /bin/sh being dash instead of bash.


3

As per the question: (a) the script is in the same directory as blah.deb, and (2) the user will run the script from some unknown other directory. In that case: #!/bin/bash sudo dpkg -i --someflags=abcd "${BASH_SOURCE[0]%/*}/blah.deb" The shebang line is upgraded to bash so that we can use the BASH_SOURCE array which tells us the location of the script ...


2

I don't really understand your issue (find should return the full path), however I suggest a different approach, perhaps something like find -name '*.report' -execdir bash -c 'echo mv "$0" "${0/LP_/LPP_}"' {} \; By passing the find result {} as a shell positional parameter $0 to a subordinate bash -c command, we can work around the fact that we can't do ...


2

You will probably have your script named similarly (starting) like an existing application or executable in $PATH (or, as Oli mentions, you forgot to make it executable). Another thing is that it is bad practice to use language extensions in executables in $PATH, see this link


3

Even scripts need the executable bit set.


1

It's basically futile. It might help for a short while, but if your disk has bad sectors, then it's only going to get more bad sectors with time. It's best to buy a new disk, and/or get that one replaced if it is under warranty. If it's not under warranty, then back up the good data to a good disk, write 0s to the bad disk at least 10 times, and take it to a ...


0

Why not just tmux or screen and be done with it? For example: $ tmux new -s SessionNameHere $ nohup /path/to/your/script.sh This is practical if it's something that will continuously loop or take a while to finish. You can disconnect from the session and it will remain active.


1

If you child.sh print on standard output $create_sql value, you could get it in parent script: create_sql=`./child.sh "$dictionary"` After this line, you should test child.sh exit value with $? and if it returns 0 you could use $create_sql variable. This approach is useful when script is like a function, otherwise is better follow muru suggested ...


2

Try using an overlay, with a chroot. First, decide the path you want to chroot to, and make sure it exists, and similarly for the path you will overlay on / (which is where modifications will go): mkdir -p /chroot mkdir -p /tmp/tmproot I chose a directory in /tmp/ as it's a tmpfs on my system (possibly unadvisable, but OK for me), so no changes should ...


0

I used the FSlint project and find to get the thing done. My process to get all of this sorted out on multiple disks with the requirement to run everything via CLI & screen sudo apt-get install fslint find path1/2/3 -type f -empty -delete & find path1/2/3 -type d -empty -delete (to get rid of alle empty or not completly copied stuff) ...


1

Here's an impossibility result: The behavior of a script may depend on information that it wrote to a file earlier. If you don't actually allow it to write to the file (but make the script believe it did write to the file), then you may influence the script's behavior in a way that wouldn't happen if you ran it "for real". For instance: #!/bin/bash ...


0

I had similar unhappy incidents trying this operation on the vanilla LTS. ~$ cat /etc/os-release NAME="Ubuntu" VERSION="14.04.1 LTS, Trusty Tahr" On this version, the key file /etc/init.d/vboxautostart-service was not installed. As far as I know all the VitualBox and requirements were put in by apt-get, so I cannot say why the 'vboxautostart-service' ...


2

bash: ./test.sh: bin/bash: bad interpreter: No such file or directory Replace: #!bin/bash With: #!/bin/bash bin/bash is a path relative to the current directory. /bin/bash is an absolute path that works whatever the current directory is. Also, have a look at your PATH: echo $PATH If you place test.sh in any directory listed there and you will ...


1

To be able to run your bash script, change first line to #!/bin/bash That is the binary that will interpret and run your script. To run a bash script, do the following ./scriptname.sh In your example: ./test.sh in the directory where you have the script.


0

If you'd like to use a very capable GUI, try FSlint from the Software Center. (I see that @lemonsqueeze suggested this in the comments above). Here is an answer that outlines FSlint usage: http://askubuntu.com/a/472244/100356


2

A command can be formulated like this: netstat -lpn | grep ":1234\b" | awk '{sub(/\/.*/, "", $NF); print $NF}' | xargs -i kill -kill {} Explanation: netstat -ltpn This lists the listening ports (l) on TCP (t) and their programs (p) without resolving port numbers to names (n). grep ":1234\b" This searches for :1234 followed by a boundary (\b), ...


3

I solve this problem. It was very simple. I need to change ends of strings to Unix/Linux format in my .sh file instead of Windows ends.


1

The script below looks for duplicate files in up to 10 directories at once, looking for duplicates in the combined directories. It should be dramatically faster than both fdupes (running fdupes -r) and fslint; on a relatively small directory of 40GB, locally stored, it took the script 5 seconds to create a dupe list, while it took fdupes and fslint much ...


2

When invoking xinput from udev, you have to set the XAUTHORITY variable: #!/bin/sh export DISPLAY=":0" export XAUTHORITY="/home/<user>/.Xauthority" /usr/bin/xinput set-prop "DLL063E:00 06CB:2934" "Device Enabled" $1 this variable is already set when you run the script directly from the console, but scripts invoked by udev (and other ...


0

VLC. It has a "console" mode that runs without a gui: start=20 # 20 seconds in stop=$(( start + 10 )) # play for 10 seconds cvlc --play-and-exit --start-time $start --stop-time $stop $file 2>/dev/null


2

Can you create a queue in the terminal so that after one installation finishes it will continue to the next? Yes. You can add packages like this: sudo apt-get install sm-player vlc chromium Can you write a script to do this? How would it look like? Yes. Just put above mentioned one-liner into a text file and make it executable with ...


1

Wrong approach. While creating the script, set the x flag as well! Or, when executing the created script, prepend sh or bash to it: Instead of: /tmp/myscript.sh use: bash /tmp/myscript.sh Like that you don't have to make the script executable.


1

Since the script works for you when you login as root, something must be set in the user's rc files. The .profile and .bashrc look innocent, but it could be somewhere else, in .bash_profile, or /etc/profile, or in some script in /etc/profile.d. So we can try telling sudo to run the command in a login shell using -i (or --login): sudo -i /path/to/perl/script ...


0

If you have a look at folder /etc/pm/sleep.d/ - all scripts within this folder are automatically run as root-user before/after suspend or hibernate. When the computer wakes up from hibernate or suspend all scripts are called in reversed order with the argument "thaw" or "resume". A script needs to look like this example: #!/bin/bash case "$1" in ...


6

Another good option is Incron. It works on inotify with specifiable conditions for a given location. So I can say watch this folder, when you see a file created, run a command. Just as a sample incrontab... /path/to/scripts IN_CREATE chmod +x $@$# # <--- this arcane bit is path ($@) + file ($#) One could similarly use the path/file as arguments to a ...


1

When initiated, the script below automatically changes the permissions of all files of a given type (extension) in a directory (one time). After that, the script checks the directory every 5 seconds for newly added files, and changes the permissions if the file is of the given type (in this case a .py file) It has a few options: in this case, it makes the ...


1

As a first step, you could try this in your ~/.vimrc: autocmd BufWritePost *.py silent execute "! chmod +x %" This runs chmod +x on the filename for all .py files when you write to them. Looking at the list of events (:h events), I can't find an event where a new file is created, so I had to settle for running each time it is written to. The first time ...


1

The version of Upstart in Ubuntu 10.10 has no support for the setuid stanza. When Upstart encounters a stanza it does not recognize, it refuses to acknowledge the validity of the job configuration. One solution is to upgrade to an Ubuntu version with Upstart >= 1.4. Ubuntu 12.04 has version 1.5 of Upstart, so that may be a good fit (although Trusty would ...


2

cd /path/to/python/scripts/dir chmod 755 *.py Will make executable all current .py files in whatever directory you cd to. I'm not aware of an auto-tool as you describe. It might be possible to have a macro in your editor that could do this, but not with the editor I use. ;-)


0

You have to make a desktop file, eg. name.desktop which contains the following structure: [Desktop Entry] Type=Application Name=your script name Exec=/path/to/your/script.sh Terminal=true <-if you need sudo (to type your password) Make both this file and your script executable (e.g. chmod 700 script.sh). Now you can double click your desktop ...


0

To open an URL you should use xdg-open, which will use your preferred browser to visit the URL. $ xdg-open http://www.example.com/ In order to Open It after startup, you should do what Geppettvs D'Constanzo suggests: A Cron Job Startup Applications


1

I wanted the same thing and ended up solving it without using guestcontrol. On my MacOS X host I have a folder (named Windows) that my vbox client running a Win7 has mapped as Z:. I use dummy-files to communicate between host and my clients like this: On the Mac host: - created one shell-script complete with an icon for each windows application I wanted to ...


0

From your original question, it looks like the right thing to do would be to move the script to ~/bin/, which should be in your $PATH by default. If you do this, you'll be able to run your script using AltF2 again. You will also be able to pass arguments to it like you do in a shell. You can also add any other folder where you keep your scripts to your ...



Top 50 recent answers are included