Tag Info

Hot answers tagged

8

Assuming your files stored in source dir and your target folders are in dest like following tree: $ tree source source ├── dir1 │ ├── ABA.xy │ ├── ACA.xy │ └── BEB.xy └── dir2 ├── ABA.rr ├── ACA.rr └── BEB.rr 2 directories, 6 files $ tree dest dest ├── ABA ├── ACA └── BEB 3 directories, 0 files The command would be: find source -type f ...


8

If the scripts directory isn't in your PATH, and . (the current directory) is not in the PATH either, you can run the script using ./ as shown below ./script_name.sh Use the script file name to run it either by using it’s relative path or absolute path as shown below: cd /home/user ./script_name.sh OR /home/user/script_name.sh


6

As other people said before me: Don't parse the output of ls! (see http://www.smallo.ruhr.de/award.html#ls) Why not simply: stat --printf='%y\t%n\n' -- * If you want to do something with each file name and time stamp, read the output of stat like this: stat --printf='%y\t%n\0' -- * | \ while IFS=$'\t' read -rd '' timestamp i; do echo "filename: ...


5

Since you have sudo access, create a sudoers file for yourself, then delete it when the script is done: # grant this user access to the sudo commands without passwords # add all required cmds to the CMDS alias sudo tee /etc/sudoers.d/$USER <<END $USER $(hostname) = NOPASSWD: /usr/bin/apt-get, /usr/sbin/adduser, /bin/rm, ... END # your script goes ...


5

You could use gnome-terminal to open up new terminal or new tabs #!/bin/bash # # The following command open new windows # gnome-terminal -e "ssh test@192.168.2.1" gnome-terminal -e "ssh test@192.168.2.3" gnome-terminal -e "ssh test@192.168.2.5" # # The following command open new tabs # gnome-terminal --tab -e "ssh test@192.168.2.1" --tab -e "ssh ...


5

The difference is that your current working directory would have to contain the script that you'd like to execute. In this case, the dot stands for current directory, the slash does it's normal delimiter job, then the name of the script follows. If a script was in the directory above your current working directory you could execute it using ../ It's ...


4

This is fairly straightforward with recent versions of bash by using globbing and arrays, which is what I assume you mean by tables. First create some test files: path=/some/where touch $path/{a,b,c}_suffix.txt Here is an example that puts all files ending in _suffix.txt into the files array: files=("$path"/*_suffix.txt) To iterate over them you can ...


4

Go to a terminal by pressing Ctrl+Alt+T and type md bin Go to the dash type gedit and press Enter Copy paste the following text into it: #!/bin/bash # # This script deletes video files of 8000 bps if and only if the 3800 bps file exists # as set in http://askubuntu.com/questions/581400/how-to-delete-files-selected-by-rules # # ...


4

Consider this error message: install.sh: 4: install.sh: source: not found That means that the script is not being executed by bash. This error likely comes from dash which is the default shell under Ubuntu. Try running your script as: bash /path/to/install.sh More Observe the line: sh kvminstall.sh This starts kvminstall.sh using the default ...


4

I assume you need to know the (clock-) time the folder is opened in e.g. nautilus, not the time it takes to access the folder. Using the window list You can get the window list from the command wmctrl -l, and see if the folder's name occurs in the list. The loop to check would however take at least a split second to notice the folder is opened. You'd have ...


4

Do not parse the output of ls, use a glob: for i in * ; do Also, quote the variables that might contain spaces: timestamp=$(stat -c %y "$i")


3

Zenity can be used to make a GUI file picker, using the --file-selection option. For a single file, this is sufficient: #! /bin/bash file="$(zenity --title "Pick a file" --file-selection)" do something with "$file" Where it gets tricky is handling multiple files. There are only two characters not allowed in filenames: the ASCII NULL and /. /, of ...


3

Your script lacks read and execute permissions for user B. Do: chmod og+rx b.sh


3

You can use on_ac_power to run a script when the power supply is turned on or off. Try the following in a terminal. $ on_ac_power $ echo $? 0 ## Laptop on ac power $ on_ac_power $ echo $? 1 ## Laptop on battery (not on ac power) Based on this you can make your script as, #!/bin/bash while true do if on_ac_power; then ...


2

The tutorial step 2 asked to create a new user: hduser. So if you decided to adopt this username for the Hadoop user, the path of start-all.sh should be: cd /home/hduser/hadoop/bin/ start-all.sh Or if installed system-wide: /usr/lib/hadoop/bin/


2

As the permission of the file is b.sh is -rw------- b.sh, there is no execute bit set for user, group or others. If you want to execute the file as 'userB' then running the following will do: sudo chmod 605 /home/userA/Documents/b.sh


2

You missed a space between [[ and $REPLY: while [[$REPLY != 0 ]]; do should be while [[ $REPLY != 0 ]]; do


2

What you call a table is usually called an array or a map. In bash, to create such an array: path="/home/user/Documents" suffix="_suffix.txt" files=( "$path"/*"$suffix" ) The * is a wildcard, which is expanded by the shell to all matching filenames (that have $path before it and $suffix after). The brackets (()) convert the expanded filenames into an ...


2

See the manual for sudo: -k [command] When used alone, the -k (kill) option to sudo invalidates the user's cached credentials. The next time sudo is run a password will be required. So put a sudo -k before every sudo command you want to re-ask for a password. Or behind every command where you want the next commands not to be sudo. By the ...


2

A slightly different approach using rename: rename 's#.*/(.+)(\.\w+)#mkdir "dest/$1"; "dest/$1/$1$2"#e' source/{a,b}/* This is essentially just using a regular expression to translate the paths. We use a little bit of Perl (which rename supports) to create the new directories and rename moves the file at the end. It isn't too clever. It won't search for ...


2

Create a script with following containt #!/bin/bash first_u=$(awk '{printf "%.0f" , $0/60;}' /proc/uptime) while true do uptime_m=$(awk '{printf "%.0f" , $0/60;}' /proc/uptime) (( time_dif=$uptime_m - $first_u )) if [ $time_dif -eq 30 ]; then notify-send "You have on laptop since 30 minutes" sleep 1800 notify-send "You have on laptop ...


2

Try this: gawk -F, ' # spawns nslookup as a coprocess, passes the IP into its stdin # then reads the output of the coprocess to find the hostname function get_name(ip, line, name) { name = "UNRESOLVED" print ip |& "nslookup" close("nslookup", "to") while (("nslookup" |& getline line) > 0) { ...


1

You can use Arronax to create a starter for your script and save it into $HOME/.config/autostart/ (that's "User Autostart Folder" in the "Standard Folders" list in the lower left of the "Save File" dialog)


1

If you want to use Bash instead Python: #!/bin/bash folder=$1 while true; do command=$(wmctrl -l | grep -o "$folder") if [[ "$folder" == "$command" ]]; then ./myscript.sh break; fi done Edit: I changed a script so you can run it with the following command: bash folderwatch.sh BackupSSD Also, you can make a script ...


1

it's not part of network manager - but network manager uses 'ifupdown' to connect the internet, and ifupdown let you run scripts on connecting (turning interface up) or disconnecting (turning the interface down) all you should do is to put your script in one of the following directories under /etc/network/: if-pre-up.d/ - to be run before connecting ...


1

1 Try alarm-clock-applet sudo apt-get install alarm-clock-applet 2 Also Gnome Clock has a countdown feature. But it has to be set manually every time. sudo apt-get install gnome-clocks


1

In a single (flat) directory If all files are in one and the same directory, the script below should do the job. #!/usr/bin/env python3 import os import sys dr = sys.argv[1]; ids = ("_3800.mp4", "_8000.mp4") checklist = [f[:-9] for f in os.listdir(dr) if f[-9:] in (ids)] for f in [f for f in set(checklist) if checklist.count(f) != 1]: ...


1

Script to reorganize photos into /year/month directories The script below does the following: It determines the month the picture was taken Inside your targeted directory, it creates (if necessary) sub directories per year (if photos were found) Inside these year directories, it creates sub directories per month If the script is unable to find an ...


1

First, glen jackman was close: your script is using CR-LF (\r\n) line endings. For example, I recreated your script with CRLF line endings manually: $ cat foo.sh #!/bin/bash echo "Deleting: " $1 grep -lr $1 foo.txt | xargs echo echo "Done" $ file foo.sh foo.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators $ sh foo.sh ...


1

You can use wget as shown here: Downloading an Entire Web Site with wget Sep 05, 2008 By Dashamir Hoxha in HOW-TOs If you ever need to download an entire Web site, perhaps for off-line viewing, wget can do the job—for example: $ wget \ --recursive \ --no-clobber \ --page-requisites \ --html-extension \ ...



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